Langkau ke kandungan utama

Accurately querying MyGeotab Trips with Python SDK

ERoss-1985
Poster asal

I am attempting to use the Python SDK to retrieve/query Trips for a particular device from one date/time to another that I can see from a report that I pulled from our environment.

 

My understanding is that the database date/time's are in UTC, so I am converting from out local time to UTC for simplicity sake. I know that I am pulling the correct device information as well. "trips.json" is what I receive back from this particular call, and it returns trips that started nowhere near the date entered. Can I get some help to get particular trips where the start (or end) date/times are within a certain bounds similar to what I have in the attached example report?

import mygeotab.dates import datetime, mygeotab, pytz   cst_tz = pytz.timezone('US/Central'); startDateTime_cst = cst_tz.localize(datetime.datetime(2024, 9, 3, 10, 34, 1)); startDateTime_utc = startDateTime_cst.astimezone(datetime.UTC);   endDateTime_cst = cst_tz.localize(datetime.datetime(2024, 9, 3, 11, 0, 0)); endDateTime_utc = startDateTime_cst.astimezone(datetime.UTC);     client = mygeotab.API(username='{username}', password='{password}', database='{db}'); client.authenticate();   device = client.get('Device', name='-')[0];   trips = client.get('Trip', FromDate=mygeotab.dates.format_iso_datetime(startDateTime_utc), ToDate=mygeotab.dates.format_iso_datetime(endDateTime_utc), IncludeOverlappedTrips=True, device=device);   print(trips);

 

 

069Pd00000DWcp9IAD.xlsx

Sertai perbualan

Anda perlu log masuk untuk membalas catatan ini dan mengambil bahagian dalam perbincangan Komuniti Geotab.

5 Balasan

EishiFUN
Pentadbir Komuniti

Hello @ERoss-1985​ ,

 

Thank you for asking your question in our community. I wanted to let you know I have contacted our SDK team to get their help here. I will let you know what I hear from them as soon as I do or have one of them jump in here.

 

Thank you for your patience while I look into this. Feel free to reach out with any other questions you may have in the meantime. We are here to help.

 

Have a good one!

Eishi FUN

Any news from the SDK team about this one? :)

 

Best,

Joy B

Hi @ERoss-1985​ ,

 

The dates need to be passed to a search object like shown below.

 

import mygeotab.dates import datetime, mygeotab, pytz   cst_tz = pytz.timezone('US/Central')   startDateTime_cst = cst_tz.localize(datetime.datetime(2024, 9, 3, 10, 34, 1)) startDateTime_utc = startDateTime_cst.astimezone(datetime.timezone.utc)   endDateTime_cst = cst_tz.localize(datetime.datetime(2024, 9, 19, 11, 0, 0)) endDateTime_utc = endDateTime_cst.astimezone(datetime.timezone.utc)     client = mygeotab.API(username='username_here', password='pwd_here', database='smarterai_internal_alpha') client.authenticate()     device = client.get('Device', name='MyTruck')[0] fD=mygeotab.dates.format_iso_datetime(startDateTime_utc) tD=mygeotab.dates.format_iso_datetime(endDateTime_utc) print(fD) print(tD) print(f"Name:{device['name']} ID:{device['id']} ")   trips = client.get('Trip',deviceSearch={'id':'b14'},fromDate=fD,toDate=tD, includeOverlappedTrips=True)   print(trips)

I hope this helps.

Let me know if you have any questions.

 

Regards,

Ajay Srinivasan

Solutions Engineering Lead

Geotab

ERoss-1985
Poster asal

Thank you for your response @AjaySrinivasan-1240​ , after applying the changes you recommended it looks like I continue to receive Trip objects with start times from completely different years.

Hi @ERoss-1985​ ,

 

I ran the script and verified that it is producing the results correctly.

I will reach out to you privately for further clarification.

 

Thanks

Masih ada soalan?