1

Execute report, error

(30/11/2016 02:20:33 отредактировано Denisse)

Тема: Execute report, error

My question is about the handling of dates and time in the execution of a report through JavaScript, because when running a report the data throws me correctly except the date and time.

They could help with this error or to what is due. Use the PLAYGROUND sample code of execute report.

This image is execute report from JavaScript.

Execute report, error

This image is execute report from wialon platform.

Execute report, error

2

Execute report, error

Re: Execute report, error

Denisse, Wialon sends date and time in UTC (seconds since 1970) without any timezone. When You format this time in JS Your computer's timezone is used by default. But Wialon has it's own setting for timezone and it can differ with computer's setting.
It is explained here: https://forum.gurtam.com/viewtopic.php?id=10651

Head of Wialon Local Department
Gurtam
3

Execute report, error

Re: Execute report, error

A little example about use timezone, please

4

Execute report, error

Re: Execute report, error

Denisse, what timezone and daylight saving time is set in Your user settings in Wialon? And what timezone is set on Your PC?

Head of Wialon Local Department
Gurtam
5

Execute report, error

Re: Execute report, error

The settings timezone that has Wialon is:

Timezone: Central Time (US & Canada), Guadalajara, Mexico city     -06:00
Daylight: Mexico(PSST), Turks & Caicos Islands: from first Sunday in April to last Sunday in October

and the timezone in PC is:

(UTC - 06:00) Guadalajara, Mexico City, Monterrey

6

Execute report, error

Re: Execute report, error

Denisse, dates and times in report result of Wialon interface are correct?
And times in Your js app are wrong?

Head of Wialon Local Department
Gurtam
7

Execute report, error

Re: Execute report, error

Yes in the report result of Wialon interface is correct.

And the time in my app js is wrong with see to images in the top part.

8

Execute report, error

Re: Execute report, error

Show please Your code of formatting date and time.

Head of Wialon Local Department
Gurtam
9

Execute report, error

Re: Execute report, error

Yes, its the seem of playground javascript API of execute report, but its the next code:

function executeReport(){ // execute selected report
    // get data from corresponding fields
    var id_res=$("#res").val(), id_templ=$("#templ").val(), id_unit=$("#units").val(), time=$("#interval").val();
    if(!id_res){ 
            msg("Select resource"); 
            return;
        } // exit if no resource selected
    
        if(!id_templ){ 
            msg("Select report template"); 
            return;
        } // exit if no report template selected
    
        if(!id_unit){ 
            msg("Select unit"); 
            return;
        } // exit if no unit selected

    var sess = wialon.core.Session.getInstance(); // get instance of current Session
    var res = sess.getItem(id_res); // get resource by id
    var to, from;
        if(validaInter == 1){
            /*Primer dato separa hora y fecha*/
            var auxArray = $("#Desde1").val().split(" ");
            var cadFechaI = auxArray[0].toString().split("/");
            var cadHoraI = auxArray[1].toString().split(":");
            var fechaI = new Date();
            fechaI.setDate(cadFechaI[2]);
            fechaI.setMonth(parseInt(cadFechaI[1])-1);
            fechaI.setFullYear(cadFechaI[0]);
            fechaI.setHours(cadHoraI[0]);
            fechaI.setMinutes(cadHoraI[1]);
            from = (fechaI.getTime()/1000).toFixed(0);
            
            /*Segundo dato separa hora y fecha*/
            var auxArrayF = $("#Hasta1").val().split(" ");
            var cadFechaF = auxArrayF[0].toString().split("/");
            var cadHoraF = auxArrayF[1].toString().split(":");
            var fechaF = new Date();
            fechaF.setDate(cadFechaF[2]);
            fechaF.setMonth(parseInt(cadFechaF[1])-1);
            fechaF.setFullYear(cadFechaF[0]);
            fechaF.setHours(cadHoraF[0]);
            fechaF.setMinutes(cadHoraF[1]);
            to = (fechaF.getTime()/1000).toFixed(0);
             
        }else{
            if(validaInter == 2){
                var d = new Date();
        d.setHours(0);
        d.setMinutes(0);
        d.setSeconds(0);
        from = parseFloat( ((d.getTime() / 1000) - (2592000)).toFixed(0));
        to = from + parseFloat(2592000);
            }
            else{
                to = sess.getServerTime(); // get current server time (end time of report time interval)
                console.log("Valor to: " + to);
                from = to - parseInt( $("#interval").val(), 10); // calculate start time of report
                console.log("Valor from: " + from);
            }
        }
    // specify time interval object
    var interval = { 
                    "from": from, 
                "to": to, 
                "flags": wialon.item.MReport.intervalFlag.absolute 
                    };
    
        var template = res.getReport(id_templ); // get report template by id
    $("#exec_btn").prop("disabled", true); // disable button (to prevent multiclick while execute)

    res.execReport(template, id_unit, 0, interval, // execute selected report
        function(code, data) { // execReport template
            $("#exec_btn").prop("disabled", false); // enable button
            if(code){ 
                            msg(wialon.core.Errors.getErrorText(code)); 
                            return; 
                        } // exit if error code
            if(!data.getTables().length){ // exit if no tables obtained
                            msg("<b>There is no data generated</b>"); 
                            return; 
                        }
            else 
                            showReportResult(data); // show report result
    });
}
10

Execute report, error

Re: Execute report, error

Denisse, also show showReportResult function.

Head of Wialon Local Department
Gurtam
11

Execute report, error

Re: Execute report, error

ok, this is the code:

function showReportResult(result){ // show result after report execute       
    var tables = result.getTables(); // get report tables
        var contador=0;
            
    if (!tables){ 
            return; // exit if no tables
        }
    for(var i=0; i < tables.length; i++){ // cycle on tables
        // html contains information about one table
            if(tables[i].label == "Cargas de combustible"){
                AuxVal = 2;
        var html = "<div ><table align='center' class='mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp mdl-color-text--black'>";
        
        var headers = tables[i].header; // get table headers
        html += "<tr>"; // open header row
        for (var j=0; j<headers.length; j++) // add header
            html += "<th style='text-align:left'>" + headers[j] + "</th>";
        html += "</tr>"; // close header row
        result.getTableRows(i, 0, tables[i].rows, // get Table rows
            qx.lang.Function.bind( function(html, code, rows) { // getTableRows callback
                if (code) {
                                    msg(wialon.core.Errors.getErrorText(code)); 
                                    return;
                                } // exit if error code
                for(var j in rows) { // cycle on table rows
                    if (typeof rows[j].c == "undefined") 
                                            continue; // skip empty rows
                    html += "<tr"+(j%2==1?" class='odd' ":"")+">"; // open table row
                    for (var k = 0; k < rows[j].c.length; k++){ // add ceils to table
                                                guardafechascargas[j] = getTableValue(rows[j].c[1]);
                                                guardalitroscargados[j] = getTableValue(rows[j].c[3]).replace("lt",'');
                        html += "<td style='text-align:left'>" + getTableValue(rows[j].c[k]) + "</td>";
                                            }
                                            
                    html += "</tr>";// close table row
                }
                                tratalitros(guardafechascargas);
                html += "</table>";
                msg(html +"</div>");
            }, this, html)
        );
                
            }
            else
            {
                AuxVal = 1;
            }
            if(tables[i].label == "Robos de combustible"){
                    AuxVal = 2;
                    var html = "<div ><table align='center' class='mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp mdl-color-text--black'>";
        
                    var headers = tables[i].header; // get table headers
                    html += "<tr>"; // open header row
                    for (var j=0; j<headers.length; j++) // add header
            html += "<th style='text-align:left'>" + headers[j] + "</th>";
                    html += "</tr>"; // close header row
                    result.getTableRows(i, 0, tables[i].rows, // get Table rows
            qx.lang.Function.bind( function(html, code, rows) { // getTableRows callback
                if (code) {
                                    msg(wialon.core.Errors.getErrorText(code)); 
                                    return;
                                } // exit if error code
                for(var j in rows) { // cycle on table rows
                    if (typeof rows[j].c == "undefined") 
                                            continue; // skip empty rows
                    html += "<tr"+(j%2==1?" class='odd' ":"")+">"; // open table row
                    for (var k = 0; k < rows[j].c.length; k++) // add ceils to table
                        html += "<td style='text-align:left'>" + getTableValue(rows[j].c[k]) + "</td>";
                    html += "</tr>";// close table row
                }
                html += "</table>";
                msg1(html +"</div>");
            }, this, html)
                    );
                }
                else{
                    AuxVal = 3;
                }
    }
        if(AuxVal == 1){
            msg("No hay datos");
        }
        else{
            if(AuxVal == 3){
                msg1("No hay datos");
            }
        }
        
}
12

Execute report, error

Re: Execute report, error

Denisse, now getTableValue function is missing.
Show function where You format table cell with date.

Head of Wialon Local Department
Gurtam
13

Execute report, error

Re: Execute report, error

ok this this is next code:

function getTableValue(data) {
    if (typeof data == "object")
        if (typeof data.t == "string") return data.t; else return "";
    else return data;
}
14

Execute report, error

Re: Execute report, error

Thanks! this helped me too.

15

Execute report, error

Re: Execute report, error

But not its possible format the date in my app whith this code.

Can I help you, please?

16

Execute report, error

Re: Execute report, error

Denisse, do You execute wialon.core.Session.getInstance().getRenderer().setLocale(...) request?
https://sdk.wialon.com/wiki/ru/sidebar/ … set_locale

You can pass your user's timezone, language, date and time format, metrics into this request after login and this will affect report results.
For example:

var sess = wialon.core.Session.getInstance();
var user = sess.getCurrUser();
var locale = {};
locale.formatDate = "%Y-%m-%E %H:%M:%S";
locale.flags = 0;
sess.getRenderer().setLocale(user.getCustomProperty("tz"), "en", locale, null);
Head of Wialon Local Department
Gurtam
17

Execute report, error

Re: Execute report, error

Not, the setLocale I am not execute,

But the change the code for this information and execute the report well in the plataform and app...

Thank you for this information.

18

Execute report, error

Re: Execute report, error

help please, I have the following javascript to generate a unit report. The bad thing is that I get the following error, I do not know how to solve it:
Uncaught TypeError:

Can not read property 'getTables' of null

19

Execute report, error

Re: Execute report, error

help please, I have the following javascript to generate a unit report. The bad thing is that I get the following error, I do not know how to solve it:
Uncaught TypeError: Can not read property 'getTables' of null






<script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="//hst-api.wialon.com/wsdk/script/wialon.js"></script>
<style>
    td, th{ border: 1px solid #c6c6c6; }
    .wrap{ max-height:150px; overflow-y: auto; }
    .odd, th{ background:#EEE; border: 1px solid #c6c6c6; }
</style>
<div id="log"></div>
<script type="text/javascript">
function msg(text){ $("#log").prepend(text + "<br/>"); }
function init(){
    var res_flags = wialon.item.Item.dataFlag.base | wialon.item.Resource.dataFlag.reports;
    var unit_flags = wialon.item.Item.dataFlag.base;
    var sess = wialon.core.Session.getInstance();
    sess.loadLibrary("resourceReports");
    sess.updateDataFlags( 
        [{type: "type", data: "avl_resource", flags:res_flags , mode: 0}, 
         {type: "type", data: "avl_unit", flags: unit_flags, mode: 0}], 
        function (code) { 
            if (code) { msg(wialon.core.Errors.getErrorText(code)); return; }
            var res = sess.getItems("avl_resource");
            for (var i = 0; i< res.length; i++){
                $("#res").append("<option value='" + res[i].getId() + "'>" + res[i].getName() + "</option>");
            }
            var units = sess.getItems("avl_unit");
            for (var i = 0; i< units.length; i++){
                $("#units").append("<option value='"+ units[i].getId() +"'>"+ units[i].getName()+ "</option>");
                console.log(units[i].getId() +' - ' + units[i].getName());
                executeReport(units[i].getId(), units[i].getName());
            }
        }
    );
}
function executeReport(vehiculoid, nombre){ 
    var id_res=15136513, id_templ=8, id_unit=vehiculoid, time=86400;
    var sess = wialon.core.Session.getInstance();
    var sess = wialon.core.Session.getInstance();
    var res = sess.getItem(id_res);
    var to = sess.getServerTime();
    var from = to - parseInt(86400, 10);
    
    var interval = { "from": from, "to": to, "flags": wialon.item.MReport.intervalFlag.absolute };
    var template = res.getReport(id_templ); 
    $("#exec_btn").prop("disabled", true); 

    res.execReport(template, id_unit, 0, interval, 
        function(code, data){
            if(data.getTables() !== undefined ){
                if(!data.getTables().length){ 
                    msg("<table><tr><td><b>Hay datos para mostrar vehículo " + vehiculoid + "Nombre Vehículo: " + nombre + "</b></td></tr></table>"); 
                    return;
                }
                else{
                    var tables = data.getTables();
                    for(var i in tables){ 
                        var html = "<div class='wrap'><table style='width:100%'>";
                        
                        var headers = tables[i].header; 
                        data.getTableRows(i, 0, tables[i].rows, 
                            qx.lang.Function.bind(function(html, code, rows){ 
                                for(var j in rows){
                                    html += "<tr"+(j%2==1?" class='odd' ":"")+">"; 
                                    html += "<td>ID: " + id_unit;
                                    html += "<td>Unidad: " + nombre + "</td>";
                                    for(var k in rows[j].c){
                                        html += "<td>" + getTableValue(rows[j].c[k]) + "</td>";
                                    }
                                    html += "</tr>";
                                }
                                html += "</table>";
                                msg(html +"</div>");
                            }, this, html)
                        );
                    }
                }
            }
    });
} 
function getTableValue(data) {
    if (typeof data == "object")
        if (typeof data.t == "string") return data.t; else return "";
    else return data;
}
$(document).ready(function (){
    $("#exec_btn").click( executeReport );
    wialon.core.Session.getInstance().initSession("https://hst-api.wialon.com");
    wialon.core.Session.getInstance().loginToken("TOKEN", "", // try to login
        function (code) { 
            if (code){ msg(wialon.core.Errors.getErrorText(code)); return; }
            init();
    });
});
</script>
20

Execute report, error

Re: Execute report, error

Hello!
you should use method getTables for result (response) which you get after execute report.
Please look example here: there are two separate functions - one to execute report, other to get report results (tables).

Diana Cheley
Wialon Hosting Expert
Gurtam
21

Execute report, error

(23/05/2024 01:34:14 отредактировано froilan.reyes)

Re: Execute report, error

Buen dia a mi me pasa algo distinto...

Informe por GRUPOS

estoy haciendo un informe de cargas por: dia, semanas, al mes y año.

todo bien , pero cuando descargo la informacion del SDK los valores de las cargas son totalmente distintos

por ejemplo: en Gurtam dice:

01-05-2024      44 Cargas


y en mi aplicacion dice:  41 Cargas, es decir 3 menos..

he visto aqui algo de informacion, pero la verdad no se donde aplicar lo de la zona horaria

este es mi codigo:


espero me puedan ayudar, estoy vuelto loco

Saludos
__________________________________

Good morning, something different is happening to me...


I am making a load report by: day, week, month and year.

Everything is fine, but when I download the information from the SDK the load values are totally different

for example: in Gurtam it says:

05-01-2024 44 Loads


and in my application it says: 41 Loads, that is, 3 less...

I have seen some information here, but I really don't know where to apply the time zone thing.

this is my code:


I hope you can help me, I'm going crazy

Greetings

22

Execute report, error

Re: Execute report, error

Good morning, something different is happening to me...


I am making a load report by: day, week, month and year.

Everything is fine, but when I download the information from the SDK the load values are totally different

for example: in Gurtam it says:

05-01-2024 44 Loads


and in my application it says: 41 Loads, that is, 3 less...

I have seen some information here, but I really don't know where to apply the time zone thing.

this is my code:


I hope you can help me, I'm going crazy

Greetings

23

Execute report, error

Re: Execute report, error

Denisse


Good morning, something different is happening to me...


I am making a load report by: day, week, month and year.

Everything is fine, but when I download the information from the SDK the load values are totally different

for example: in Gurtam it says:

05-01-2024 44 Loads


and in my application it says: 41 Loads, that is, 3 less...

I have seen some information here, but I really don't know where to apply the time zone thing.

this is my code:


I hope you can help me, I'm going crazy

Greetings

24

Execute report, error

Re: Execute report, error

Diana

Me urge hablar con Usted

25

Execute report, error

Re: Execute report, error

froilan.reyes hello, presumably, the issue related to the incorrect locale values (timezone). Please, send a request to support@wialon.com and specify full request text and username that executes the request. Thank you!

Anton Zinovyev
Technical Care Engineer (L2)
Wialon