1

Drivers, Trailers, Bound Drivers and Bond Trailers Count

Тема: Drivers, Trailers, Bound Drivers and Bond Trailers Count

Hello,

I was trying JS API to get Drivers, Trailers, Drivers Bound to Unit, and  Trailers Bound to Unit count. Could you please advise on the method that I should use?

Thanks in advance !

2

Drivers, Trailers, Bound Drivers and Bond Trailers Count

Re: Drivers, Trailers, Bound Drivers and Bond Trailers Count

Hello, nasnew ,

You may use the example provided here
You need to add your token in code.
It was made for the drivers, but you can change for trailers and passengers.
All required libraries and dataflags were added:

sess.loadLibrary("resourceDrivers");
 sess.loadLibrary("resourceTags");
 sess.loadLibrary("resourceTrailers");
res_flags =  wialon.util.Number.or(wialon.item.Item.dataFlag.base, wialon.item.Resource.dataFlag.drivers, wialon.item.Resource.dataFlag.tags, wialon.item.Resource.dataFlag.trailers);

In order to get trailers you need to use getTrailers() method and getTags() for passengers.

Please, let me know if you have any additional questions.

Anton Zinovyev
Technical Care Engineer (L2)
Wialon
3

Drivers, Trailers, Bound Drivers and Bond Trailers Count

Re: Drivers, Trailers, Bound Drivers and Bond Trailers Count

Dear Zant, thanks for your reply.

Below is a sample implementation for the resource count. we managed to get drivers count well but trailers and tags are returning null. please let me know if there is something that we overlooked.

function countResources() {

    this.sess = wialon.core.Session.getInstance();
    this.sess.loadLibrary("resourceDrivers");
    this.sess.loadLibrary("resourceTags");
    this.sess.loadLibrary("resourceTrailers");

     // Define the search specification for unit groups
     var spec_group = {
        itemsType: "avl_resource", 
        propName: "sys_name",     
        propValueMask: "*",         
        sortType: "sys_name"   
     
    };
    var flags_group = wialon.util.Number.or(wialon.item.Item.dataFlag.base, wialon.item.Resource.dataFlag.drivers, wialon.item.Resource.dataFlag.tags, wialon.item.Resource.dataFlag.trailers);


    sess.searchItems(spec_group, true, flags_group, 0, 0, function (code, data) {
        if (code) {
            console.error("Error searching resources:", code);
            return;
          }
          let totalDriversCount = 0;
          let totalTrailerCount = 0;
          let totalPassengersCount = 0;   
          for (let i = 0; i < data.items.length; i++) {
          resID = data.items[ i ].getId(); 
         
           if(!sess.getItem(resID)) 
            {
                console.log("Error: sess.getItem(resID)");
                return;
            }   
           
            let drivers = sess.getItem(resID).getDrivers();           
            if (drivers) {
             
              totalDriversCount += Object.keys(drivers).length;  // Count drivers
            }
            let trailers = sess.getItem(resID).getTrailers();                 
            if (trailers) {
             
                totalTrailerCount += Object.keys(trailers).length;  // Count trailers
            }
            let passengers = sess.getItem(resID).getTags();               
            if (passengers) {
             
                totalPassengersCount += Object.keys(passengers).length;  // Count Passengers
            }
          }
         // $("h4#resources-drivers-count").text(totalDriversCount);
          console.log("Total drivers count:", totalDriversCount);
          console.log("Total trailers count:", totalTrailerCount);
          console.log("Total passengers count:", totalPassengersCount);
    });

}