eckhchri / pcars-ds-liveview

Provides a html page for project cars dedicated server and display a map of the current race.
14 stars 1 forks source link

Sum up of rounded values can lead to wrong calculated race gaps #137

Closed viper4gh closed 4 years ago

viper4gh commented 4 years ago

In CREST2 mode was a rounding of the lap and sector times needed, because the values are provided in seconds with 4 places after the decimal point and after conversion to min:seconds:milliseconds there was still 1 place after decimal point which was cut off (for example 0.7 milliseconds result to 0 milliseconds).

But now for race gap calculation we sum up lap and sector times. With every finished lap we add a new lap time to the sum and the chance of a wrong sum increases. For example: 0.4 ms + 0.4 ms = 0.8 ms, and rounded: 0 ms+ 0 ms = 0 ms / In this worst case the sum of to times result in a diff of 0.8 ms

viper4gh commented 4 years ago

A possible solution is to move the rounding to the function ConvertLaptimeInReadbaleFormat in the index.html. Then the sum up of laptimes uses to complete values with all places after the decimal point and the rounding happens later before the times are shown in the driver table. But on the other hand is the question if the rounding happens more often then and generates a performance impact. I compared the number of calls of the Math.round for both cases in CREST2 mode and there was no big difference. Only disadvantage: Math.round is then also called in DS modes, where it is not needed, because the provided values in DS modes are in milliseconds without places after decimal point.