Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statistical driver information of today cannot be requested when specifying specific date #144

Closed
joro75 opened this issue Feb 13, 2022 · 10 comments

Comments

@joro75
Copy link
Collaborator

joro75 commented Feb 13, 2022

Describe the bug
In the get_driving_statistics function it is possible to retrieve the specify a 'day'-interval with the 'from_date' of today. In that case no statistics are returned but error_code 2 is being returned.

if however the same function is called with the same 'day'-interval, but with the default 'from_date' (None), the day statistics of today are being returned.

This seems to be related to the line 391 of client.py, where a check is done if the requested date is today, and then the actual retrieval is skipped.

To Reproduce

>>> print(asyncio.run(client.get_driving_statistics(car['vin'], 'day', from_date="2022-02-13")))
[{'error_mesg': 'No data available for this period. (day)', 'error_code': 2}]
>>> print(asyncio.run(cl.get_driving_statistics(car['vin'], 'day')))
[{'bucket': {'year': 2022, 'dayOfYear': 44, 'unit': 'metric', 'date': '2022-02-13'}, 'data': {'tripCount': 1, 'totalDistanceInKm': 14.937, 'totalDurationInSec': 1313, 'idleDurationInSec': 98, 'highwayDistanceInKm': 0.0, 'nightTripsCount': 0, 'hardAccelerationCount': 4, 'hardBrakingCount': 3, 'averageSpeedInKmph': 40.95448, 'totalFuelConsumedInL': 8.703220191470844, 'maxSpeedInKmph': 93.0, 'highwayDistancePercentage': 0.0}}]

Expected behavior
I would expect that even if a specific date for today is passed, the statistical information of that day is being returned.

Additional context
A very related problem is present when no specific date is specified for the 'week'-interval, and it is requested on a Sunday. In that case no data is being returned, even though statistical information is present on the Toyota servers. This problem is also causing problems with some unittests if they are being performed on a Sunday :-(

@joro75 joro75 added the bug label Feb 13, 2022
@joro75
Copy link
Collaborator Author

joro75 commented Feb 13, 2022

I would like to suggest that the if from_date == today: is removed, because why wouldn't it be possible to retrieve the statistics of today? The MyT application can also show the information of today.

I'm however unaware of the reason why this check was added. It could be that there was a valid reason for it.

Could this also partially fix the 'known issue' that is included in the README.md? It would be nice if we could resolve that 'known issue'. :-)

@DurgNomis-drol Do you know why the today-check is present in the get_driving_statistics function?

@DurgNomis-drol
Copy link
Owner

MyT returns nothing if you set the from_date to a date that is stating a week, month or year last I check. I don't know if this have changed, but you are more then welcome to check 😃

@joro75
Copy link
Collaborator Author

joro75 commented Feb 15, 2022

I still have to further investigate and test this by implementing the proposed change and testing it with the actual MyT servers. There is however a strong suspicion that this problem is also breaking the latest unittests if they are performed on a Sunday (because the first day of an 'isoweek') or on a Monday (because the first day of a 'week').

Need a few days to test this correctly and implement the correct fix (if any).

@joro75
Copy link
Collaborator Author

joro75 commented Mar 27, 2022

I tried to retrieve the statistical information from the current date, which is also the first day of the week.
The toyota API replied with the error:

mytoyota.exceptions.ToyotaApiError: HTTP: 400 - {"timestamp":1648411795908,"status":400,"error":"Bad Request","message":"from '2022-03-27' parameter needs to be before to '2022-03-27' parameter ","errorCode":"CMA400"}

It seems to indicate that there is also a 'to' parameter, that can be specified in the get_driving_statistics_endpoint. Further investigation is needed.

@DurgNomis-drol
Copy link
Owner

I have never been able to make this work, i have also tried many different combinations and it will always return that error when requesting data on the the first date of an given periode.

@martarho
Copy link

martarho commented Nov 21, 2022

@joro75 @DurgNomis-drol Hi there, I have a similar error coming from a different problem: While trying to retrieve data from a specific day (16th June 2022) with the interval = "day" I get the error ToyotaApiError: HTTP: 400 - {"timestamp":1669044183252,"status":400,"error":"Bad Request","message":"maximum difference between from & to can be 60 days for Day Interval and 120 days for Week Interval","errorCode":"CMA400"}

Which also suggests there's a parameter to non set on the get_driving_statistics_endpoint

Would you like me to open a separate bug report or is this the right place for it?

EDIT: I can confirm there's indeed a "to" parameter, as I made it work. Let me know if you consider this part of this issue or a separate one so I can commit my edits here or somewhere else :)

@DurgNomis-drol
Copy link
Owner

DurgNomis-drol commented Nov 22, 2022

@martarho Yes it indeed seems that there must be a to parameter, but I have never found out how to use it. Please post all the info you have about the to parameter and what is needed to make it work so we can look into it, it may be very simple to implement it

@martarho
Copy link

I'll open a PR then!

@CM000n
Copy link
Collaborator

CM000n commented Dec 22, 2023

We have recently released a beta version for the new API endpoints and will be focussing our work on this in the future.
Please check if your issue still applies to the new version.

@CM000n
Copy link
Collaborator

CM000n commented Jan 9, 2024

This behaviour should be fixed with mytoyota >= 1.0.

Ex:

pp.pprint(f"Summary for specific day: {await car.get_summary(from_date=date(2023, 8, 5), to_date=date(2023, 8, 5), summary_type=SummaryType.DAILY,)}")

should now give you a

("Summary for specific day: [average_speed=18.231 countries=['DE'] "
 'duration=0:11:39 distance=3.54 ev_duration=0:04:38 ev_distance=1.041 '
 'from_date=2023-08-05 to_date=2023-08-05 fuel_consumed=0.098]')

that also works if you use e.g Arrow.now().date() instead of a specific date.

@CM000n CM000n closed this as completed Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants