Traccar 3.7 Trips Report - Distance showing negative - distance

RichardG8 years ago

Emailed you the logs.

jmdiazlr8 years ago

I found the same problem, I read the code and review the DB, for my case the cause was loading positions in batch from the sd card on my device, the device stores this positions when it does not have gprs signal, but the loading is done with a manual request, so there can be positions timely reported before the batch data is loaded, so the "lastPosition" is more current that all batch data, this disturb the DistanceHandler's algorithm... maybe a opportunity to improve the algorithm.

As I understand, the algorithm try to calculate the distance between consecutive positions, defining the previous position as the last position ever saw (based on date and time), this does not work with batch data, I do not see how to resolve this, but somebody.

Anton Tananaev8 years ago

DistanceHandler will ignore a position if its time is older than the last one.

jmdiazlr8 years ago

I do not see that in DistanceHander, and my batched positions have distance and totaldistance attributes... from where can them get this attributes ?

If DistanceHandler discard this positions, it is neglecting all porpoise of loading batched data that is a needed use case.

Anton Tananaev8 years ago

Just double-checked and you are right, it doesn't handle this situation properly. The problem is that to handle it properly, we need to recalculate old data in the database. Traccar doesn't do it at the moment.

jmdiazlr8 years ago

I reviewed my db and realized that in some situations some real time positions are received in inverse order (maybe because network latency), this breaks DistanceHandler too... but this only occurs if the reporting interval is small, with greater interval network latency can not reverse the order of position arrival.

For attribute totalDistace, I think maybe it could be dropped as it is calculable, so less need to recalculate old data on db.

For distance, I think the DataManager can maintain a few last received positions and use them to find the previous position by time of the new position in process... maybe 2 or 3 positions could be enough ... just a general idea.

Anton Tananaev8 years ago

Total distance is required for some other features, so we can't drop it. Also, it's too expensive to calculate distance for long period of time.

Last few won't help. You never know the logic of uploading data. It can be in reverse order.

danbyrne7 years ago

Hi Anton,

I have had a similar situation with having zero and negative distances per trip, and looking into it, I can see that there is an Odometer field in the GPS (although this GPS is not connected to the car odometer), and the odometer value is sometimes not zero.

I downloaded the jar that you suggested to try, however I got an error when the server tried to start... any thoughts? (I am on traccar 3.10 - I'm not sure if that is why this build may not work)

INFO|28619/0|Service traccar|17-06-03 05:30:32|[INFO] StandardFileSystemManager - Using "/tmp/vfs_cache" as temporary files store.
INFO|28619/0|Service traccar|17-06-03 05:30:33|SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
INFO|28619/0|Service traccar|17-06-03 05:30:33|SLF4J: Defaulting to no-operation (NOP) logger implementation
INFO|28619/0|Service traccar|17-06-03 05:30:33|SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
INFO|28619/0|Service traccar|17-06-03 05:30:33|java.lang.reflect.InvocationTargetException
INFO|28619/0|Service traccar|17-06-03 05:30:33| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at java.lang.reflect.Method.invoke(Method.java:498)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at org.rzo.yajsw.app.WrapperJVMMain.executeMain(WrapperJVMMain.java:60)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at org.rzo.yajsw.app.WrapperJVMMain.main(WrapperJVMMain.java:43)
INFO|28619/0|Service traccar|17-06-03 05:30:33|Caused by: java.lang.ClassNotFoundException: org.h2.Driver
INFO|28619/0|Service traccar|17-06-03 05:30:33| at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at java.lang.Class.forName0(Native Method)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at java.lang.Class.forName(Class.java:264)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at org.traccar.database.DataManager.initDatabase(DataManager.java:103)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at org.traccar.database.DataManager.<init>(DataManager.java:75)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at org.traccar.Context.init(Context.java:221)
INFO|28619/0|Service traccar|17-06-03 05:30:33| at org.traccar.Main.main(Main.java:35)
INFO|28619/0|Service traccar|17-06-03 05:30:33| ... 6 more
INFO|wrapper|Service traccar|17-06-03 05:30:34|waitpid 28619 59136
INFO|wrapper|Service traccar|17-06-03 05:30:34|exit code posix process: 59136 application: 0
Anton Tananaev7 years ago

I update the file very often. That link points to 3.11 build.

danbyrne7 years ago

Hi Anton,
FYI I updated to 3.11, set the ignoreOdometer config setting, and my reports are now working correctly... thanks

John Decore6 years ago

Thanks All,

ignoreOdometer saved my life :)

Karsten Meyer5 years ago

Hi, I have some problems with distance too, at some devices it uses the distance like total distance and sums up the distance in database. And then there are smaller total distances too. The device - server and fix date show that the values are newer but how can they be smaller? Positions show the right path and direction on the street. There is a bug in distance-calculation cause how could it be that the distance is sum up?
(hidden-app 5.19)
regards

Karsten Meyer5 years ago

.. devices with android 4.4 - newer devices have no problem since Android 5.1 ?