flobz / psa_car_controller

Control psa car with connected_car v4 API.
GNU General Public License v3.0
403 stars 210 forks source link

Trips not shown in "Trips" page of dashboard #325

Closed Pgr73 closed 2 years ago

Pgr73 commented 2 years ago

Describe the bug

Trips not shown in "Trips" page of dashboard, even after a few trips.

To Reproduce Steps to reproduce the behavior:

  1. what command did you use : As per latest Docker image
  2. when the bug append ? Since the dashboard was installed
  3. Does it persist after restarting the program? Yes
  4. Does it persist after recreate config by going to http://server_address:port/config? Yes

Config file Give the anonymize content of the config file

{ "abrp": { "abrp_enable_vin": [ "VR3UHZKXZxxxxxxx" ], "token": "xxxxx-xxxx-xxxx-xxxx-xxxx" }, "client_id": "xxxxx-xxxx-xxxxx-xxxx-xxxxx", "client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxx", "co2_signal_api": null, "country_code": "FR", "customer_id": "AP-ACNTxxxxxxxx", "proxies": { "http": "", "https": "" }, "realm": "clientsB2CPeugeot", "refresh_token": "xxxx-xxxx-xxxx-xxxx-xxxxx", "remote_refresh_token": "xxxxx-xxx-xxx-xxx-xxxxx", "weather_api": "xxxxxxx" } Environment (please complete the following information):

Additional context

Dear @flobz, I'm not sure this is strictly speaking a bug in your code.

Since I have installed the latest PSA server version, I have done a couple of trips and the car has been charged a couple of times.

In the web dashboard, I see the charging records and it looks fine. I also use the get_vehicleinfo route from Node-Red and I'm getting the info back, as I was expecting.

image

Abrp also receives the battery SOC.

However, I see nothing in the "Trips" tab and most statistics are not calculated:

image

image

I've done a bit of digging and I see that I have only one record in the "Position" table of the "info.db" database :

sqlite> .open info.db sqlite> select * from position; 2021-03-27 12:42:04+00:00|VR3UHZKXZLxxxxxxx|5.5865|45.36565|25360.8|76||0||304

Before I go any further, I need to point out that I've been using your PSA sever for a long time in an early version (I was one of your early adopters ;) in Dec 2020) and I'm "suffering" from the "Last position not updated" problem ( #50 ) that I understand is a result of having activated the "Telemaintenance" option (what a mistake I did, as it has not shown any value !).

From what I could pick up from your code (sorry, I'm not a Phyton expert at all !), the date you are using to populate this "Position" table is the last GPS position date, which, in my case, is always the same (March 27, 2021), due to the issue mentioned above, and I'm assuming that the database record is being overwritten at each insert in the table as the timestamp is the primary key of the table :

sqlite> .schema position CREATE TABLE position (Timestamp DATETIME PRIMARY KEY, VIN TEXT, longitude REAL, latitude REAL, mileage REAL, level INTEGER, level_fuel INTEGER, moving BOOLEAN, temperature INTEGER, altitude INTEGER);

Could you please confirm that is the reason why my dashboard does not display any trip ?

Now, assuming that you confirm my understanding, may I suggest that instead of using the last position date my_psacc.py, line 185: date = car.status.last_position.properties.updated_at , you could use another date. For example, when looking at the data available in the get_vehicleinfo route, you could use the "service" or the "energy" updated_at date/time. This would enable to have trips in the dashboard, even if the GPS position remains always the same. Unfortunately, my Python and Github skills are too low to do and propose the change though a pull request, sorry !

If my understanding is not correct, then could you please provide some assistance to understand why my trips are empty in the dashboard ?

Thanks in advance !

PS: What a great piece of work you have done with this server !!! 👍 🥇

flobz commented 2 years ago

Hello, I'm glad that you appreciate my work. I don't see how we can guess that a trip was made with only a date ?

Pgr73 commented 2 years ago

Hello, Thanks for comming back to me. To be honest, I'm not sure I can answer directly your question as I did not look into the logic that determines when a trip starts and ends.

Nevertheless, since opening the issue, I tried the change proposed (as follows in my_psacc.py, line 185):

image

... and the results are as good as I was hoping to get : trips are now displayed on the trips tab and the statistics seem to be correct :

image

image

As my car is constantly reporting the same "frozen" position, obviously, functions related to the car's GPS position (Map, elevation profile, precise temperature at car location) do not work, but that is another story (#50 ) :smiley:.

For those that (still) have the GPS location update (lucky them), such change may be a slight regression (if the date/time I'm using is slightly different than the one reported along with the GPS position), but for those who don't, its a great improvement.

Hope this helps !

flobz commented 2 years ago

Well thank you very much for the tips, It's seem promising ! I will try that and if it work well it will be added to next version.

flobz commented 2 years ago

It's added to last version