Reports

There are some peculiarities in working with reports. All commands from the chapter Reports except report/update_report can be performed only if the session contains some results of report execution. A session can contain only one report at the same time. That's why before executing a new report, you need to clear results of the previous one by the command report/cleanup_result.

:!: Attention! To launch this example at Wialon Kit, change https://hst-api.wialon.com for https://kit-api.wialon.com in all requests and use user name and password of your account to login to the system or name and password of demo user kitdemo kitdemo.

Report execution

As an example let's execute a report based on the template “_Trips,fuel (1)”. We'll choose “Bavarian Tractor” as a unit and set time interval from 01.01.2013 00:00 to 20.01.2013 23:59. To do this, use the request exec_report:

https://hst-api.wialon.com/wialon/ajax.html?svc=report/exec_report&
	params={
		"reportResourceId":163266,
		"reportTemplateId":10,
		"reportObjectId":34868,
		"reportObjectSecId":0,
		"interval":{
			"from":1357938000,
			"to":1358715599,
			"flags":0
		}
	}&sid=<your_sid>

Response:

{
    "reportResult": {
        "msgsRendered": 1,
        "stats": [
            ["Move time", "7:09:23"],
            ["Trips count", "120"],
            ["Stops count", "0"],
            ["Parking time", "19 days 16:34:20"],
            ["Parkings count", "121"]
        ],
        "tables": [{
            "name": "unit_trips",
            "label": "Trips without stops",
            "flags": 4497,
            "rows": 16,
            "level": 2,
            "columns": 16,
            "header": ["№", "Date", "Beginning", "Initial location", "End", "Final location", "Driver", "Duration", "Engine hours", "Mileage", "Mileage (adjusted)", "Avg speed", "Max speed", "Trips count", "Initial fuel level", "Final fuel level"],
            "total": ["", "", "2013-01-01 17:36:58", "", "2013-01-20 18:26:50", "", "", "7:09:23", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", "118 km\/h", "120", "0 lt", "0 lt"]
        }, {
            "name": "unit_stays",
            "label": "Parkings",
            "flags": 272,
            "rows": 74,
            "level": 0,
            "columns": 5,
            "header": ["Beginning", "End", "Duration", "Location", "Count"],
            "total": ["2013-01-01 00:07:56", "2013-01-20 23:51:39", "19 days 13:50:40", "", "74"]
        }],
        "attachments": [{
            "name": "Speed and mileage chart",
            "type": "chart",
            "datasets": ["Speed, km\/h", "Absolute mileage", "Mileage in trips"]
        }]
    },
    "reportLayer": {
        "name": "report unit_msgs",
        "bounds": [53.8326976, 27.2796096, 53.9644416, 27.6123168],
        "units": [{
            "id": 34868,
            "msgs": {
                "count": 6585,
                "first": {
                    "time": 1356984476,
                    "lat": 53.9077377319,
                    "lon": 27.5011463165
                },
                "last": {
                    "time": 1358711499,
                    "lat": 53.839679718,
                    "lon": 27.5609111786
                }
            },
            "mileage": 770003.067396,
            "max_speed": 118
        }]
    },
    "layerCount": 2
}

Conclusions that can be drawn out of the response:

  • report contains a table with statistics (“stats” section);
  • report contains 2 tables - “unit_trips” (Trips) and “unit_stays” (Parkings);
  • table with trips is two-level (see “level” field), has 16 columns (see “columns” and “header” fields) and the Total row (see “total”);
  • report contains a chart (see “attachments” section);
  • report contains a layer with messages (because “msgsRendered” is 1);
  • 6585 messages were used to build this layer.

Get tables data

There are two ways to get values from report tables:

  1. Using the request report/get_result_rows. It is suitable for most reports. However, it returns only rows of the top level. If you have a multilevel report, you need to make an additional request to get the rows of lower levels – report/get_result_subrows.
  2. Using the request report/select_result_rows. It returns JSON that contains rows of all levels.

Method 1:

Let's get the first row of the table “Trips without stops”, which has index 0 in “tables” array.

https://hst-api.wialon.com/wialon/ajax.html?svc=report/get_result_rows&
	params={
		"tableIndex":0,
		"indexFrom":0,
		"indexTo":0
	}&sid=<your_sid>

Response:

[{
    "n": 0,
    "i1": 108,
    "i2": 214,
    "t1": 1357047418,
    "t2": 1357056357,
    "d": 3,
    "c": ["1", "2013-01-01", {
        "t": "17:36:58",
        "y": 53.9097984,
        "x": 27.4998528
    }, {
        "t": "Beruta st., Minsk",
        "y": 53.9097984,
        "x": 27.4998528
    }, {
        "t": "20:05:57",
        "y": 53.8847872,
        "x": 27.5675072
    }, {
        "t": "Mayakovskogo st., Minsk",
        "y": 53.8847872,
        "x": 27.5675072
    }, "", "0:11:15", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", {
        "t": "72 km\/h",
        "y": 53.9070656,
        "x": 27.5216608
    }, "3", "0 lt", "0 lt"]
}]

Number 3 in the parameter d tells us that the current row contains 3 subrows. To get them, make the request:

https://hst-api.wialon.com/wialon/ajax.html?svc=report/get_result_subrows&
	params={
		"tableIndex":0,
		"rowIndex":0
	}&sid=<your_sid>

Response:

[{
    "n": 0,
    "i1": 108,
    "i2": 118,
    "t1": 1357047418,
    "t2": 1357047581,
    "d": 0,
    "c": ["1.1", "", {
        "t": "17:36:58",
        "y": 53.9097984,
        "x": 27.4998528
    }, {
        "t": "Beruta st., Minsk",
        "y": 53.9097984,
        "x": 27.4998528
    }, {
        "t": "17:39:41",
        "y": 53.9152448,
        "x": 27.4865568
    }, {
        "t": "Matusevicha st., Minsk",
        "y": 53.9152448,
        "x": 27.4865568
    }, "", "0:02:43", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", {
        "t": "34 km\/h",
        "y": 53.910112,
        "x": 27.495648
    }, "1", "0 lt", "0 lt"]
}, {
    "n": 1,
    "i1": 151,
    "i2": 169,
    "t1": 1357053985,
    "t2": 1357054222,
    "d": 0,
    "c": ["1.2", "", {
        "t": "19:26:25",
        "y": 53.9205888,
        "x": 27.492064
    }, {
        "t": "Danily Serdicha st., 68, Minsk",
        "y": 53.9205888,
        "x": 27.492064
    }, {
        "t": "19:30:22",
        "y": 53.9094592,
        "x": 27.4950912
    }, {
        "t": "Pritytskogo st., Ratomka",
        "y": 53.9094592,
        "x": 27.4950912
    }, "", "0:03:57", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", {
        "t": "41 km\/h",
        "y": 53.9177472,
        "x": 27.4873152
    }, "1", "0 lt", "0 lt"]
}, {
    "n": 2,
    "i1": 200,
    "i2": 214,
    "t1": 1357056082,
    "t2": 1357056357,
    "d": 0,
    "c": ["1.3", "", {
        "t": "20:01:22",
        "y": 53.8974912,
        "x": 27.5369984
    }, {
        "t": "Klary Tsetkin st., Minsk",
        "y": 53.8974912,
        "x": 27.5369984
    }, {
        "t": "20:05:57",
        "y": 53.8847872,
        "x": 27.5675072
    }, {
        "t": "Mayakovskogo st., Minsk",
        "y": 53.8847872,
        "x": 27.5675072
    }, "", "0:04:35", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", {
        "t": "62 km\/h",
        "y": 53.8868928,
        "x": 27.5656
    }, "1", "0 lt", "0 lt"]
}]

Method 2:

After report execution, we know that maximal nesting level of the table “Trips without stops” is 2. Now we will make a request which will return the first row with its subrows which nesting level is 2 or less:

https://hst-api.wialon.com/wialon/ajax.html?svc=report/select_result_rows&
	params={
		"tableIndex":0,
		"config":{
			"type":"range",
			"data":{
				"from":0,
				"to":0,
				"level":2
			}
		}
	}&sid=<your_sid>

Response:

[{
    "n": 0,
    "i1": 108,
    "i2": 214,
    "t1": 1357047418,
    "t2": 1357056357,
    "d": 3,
    "c": ["1", "2013-01-01", {
        "t": "17:36:58",
        "y": 53.9097984,
        "x": 27.4998528
    }, {
        "t": "Beruta st., Minsk",
        "y": 53.9097984,
        "x": 27.4998528
    }, {
        "t": "20:05:57",
        "y": 53.8847872,
        "x": 27.5675072
    }, {
        "t": "Mayakovskogo st., Minsk",
        "y": 53.8847872,
        "x": 27.5675072
    }, "", "0:11:15", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", {
        "t": "72 km\/h",
        "y": 53.9070656,
        "x": 27.5216608
    }, "3", "0 lt", "0 lt"],
    "r": [{
        "n": 0,
        "i1": 108,
        "i2": 118,
        "t1": 1357047418,
        "t2": 1357047581,
        "d": 0,
        "c": ["1.1", "", {
            "t": "17:36:58",
            "y": 53.9097984,
            "x": 27.4998528
        }, {
            "t": "Beruta st., Minsk",
            "y": 53.9097984,
            "x": 27.4998528
        }, {
            "t": "17:39:41",
            "y": 53.9152448,
            "x": 27.4865568
        }, {
            "t": "Matusevicha st., Minsk",
            "y": 53.9152448,
            "x": 27.4865568
        }, "", "0:02:43", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", {
            "t": "34 km\/h",
            "y": 53.910112,
            "x": 27.495648
        }, "1", "0 lt", "0 lt"]
    }, {
        "n": 1,
        "i1": 151,
        "i2": 169,
        "t1": 1357053985,
        "t2": 1357054222,
        "d": 0,
        "c": ["1.2", "", {
            "t": "19:26:25",
            "y": 53.9205888,
            "x": 27.492064
        }, {
            "t": "Danily Serdicha st., 68, Minsk",
            "y": 53.9205888,
            "x": 27.492064
        }, {
            "t": "19:30:22",
            "y": 53.9094592,
            "x": 27.4950912
        }, {
            "t": "Pritytskogo st., Ratomka",
            "y": 53.9094592,
            "x": 27.4950912
        }, "", "0:03:57", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", {
            "t": "41 km\/h",
            "y": 53.9177472,
            "x": 27.4873152
        }, "1", "0 lt", "0 lt"]
    }, {
        "n": 2,
        "i1": 200,
        "i2": 214,
        "t1": 1357056082,
        "t2": 1357056357,
        "d": 0,
        "c": ["1.3", "", {
            "t": "20:01:22",
            "y": 53.8974912,
            "x": 27.5369984
        }, {
            "t": "Klary Tsetkin st., Minsk",
            "y": 53.8974912,
            "x": 27.5369984
        }, {
            "t": "20:05:57",
            "y": 53.8847872,
            "x": 27.5675072
        }, {
            "t": "Mayakovskogo st., Minsk",
            "y": 53.8847872,
            "x": 27.5675072
        }, "", "0:04:35", "0:00:00", "0.00 km", "0.00 km", "0 km\/h", {
            "t": "62 km\/h",
            "y": 53.8868928,
            "x": 27.5656
        }, "1", "0 lt", "0 lt"]
    }]
}]

Getting graphic data

As was told before, a layer with trips and parkings was generated for the report. We can get the image of this layer (combined with map) using the request get_result_map:

https://hst-api.wialon.com/wialon/ajax.html?svc=report/get_result_map&
	params={
		"width":600,
		"height":600
	}&sid=<your_sid>

Response:

Also there is “Speed and mileage chart” in the report. You can get its image using the request get_result_chart. To place a chart name above the chart, set the flag 0×01, and to place a legend under the chart, set the flag 0x200 (512).

https://hst-api.wialon.com/wialon/ajax.html?svc=report/get_result_chart&
	params={
		"attachmentIndex":0,
		"action":0,
		"width":600,
		"height":300,
		"autoScaleY":0,
		"pixelFrom":0,
		"pixelTo":300,
		"flags":513
	}&sid=<your_sid>

Response:

Follow us on Facebook Gurtam Wialon Twitter Gurtam Wialon info@gurtam.com   |   Copyright © 2002-2024 Gurtam