I'm building an application on mage.ai to manage telemetry data. For that, I manipulate a csv file containing a timestamp and lap columns. It's inherent that the lap takes a few seconds, and when the car crosses the initial line, it adds a lap and so on. For example: Lap 1 took 10 seconds and started at 12:00:00 (so it finished at 12:00:10), by consequence, lap 2 started at 12:00:11 and let's suppose that took the same time, so finished at 12:00:21. From then on I interpolate those values based on the rows quantity to get the miliseconds. What I want to do is that every lap gets the same initial time as the first one, so I can overlap them on the same time axis, so lap 1 starts at 12:00:00 and lap 2 also starts at that point and so on (but still considering miliseconds). How can I do it?
Also, here's my interpolation method:
diff_values = data['time'].diff()
mask = (diff_values == 0)
data.loc[mask, 'time'] = None
data['time'] = data['time'].interpolate(method='linear')
It works but doesn't interpolate the last second, any ideia on how to fix it?
Thanks in advance
I tried a loop similar to the interpolate method, (didn't add the first value there), but I'm actually quite lost on how to manipulate it:
def lap_time_equality(dataframe):
dataframe['lap'] = dataframe['lap'].astype(int)
max_lap = dataframe['lap'].max()
first_time = dataframe['time'].iloc[0]
for lap in range(1, max_lap + 1):
diff_laps = dataframe['lap'].diff()
mask_laps = (diff_laps != 0)
dataframe.loc[mask_laps, 'time'] = None
dataframe['time'] = dataframe['time'].interpolate(method='linear')
return dataframe['time']