alpaDrive / server

The central messaging server for the app & vehicle
https://alpadrive.com
5 stars 0 forks source link

No way to store vehicle data in cloud #4

Closed Muhammedijas981 closed 1 year ago

Muhammedijas981 commented 1 year ago

In order to make API compatible with the latest UI design, vehicles have to report and store extra details about themselves.

vishalkrishnads commented 1 year ago

Could you elaborate the issue better?

Muhammedijas981 commented 1 year ago

As per the requirements, a vehicle has to store daily driving data as well as an overall health report. It isn't advisable to store the data on vehicle to then dynamically compute & deliver upon user request. So, we need the server to use a separate storage mechanism (a mongo collection maybe) to store a copy of all telemetry data on a daily basis, as well as a health report computed from it, if possible.

vishalkrishnads commented 1 year ago

So you're proposing a separate endpoint for storing data? I don't see a nice way for the server to distinguish between telemetry data & collateral data by monitoring the messages..

Muhammedijas981 commented 1 year ago

Hmm how about we monitor just the broadcast messages alone? I mean sure there'll be other messages as well, but wouldn't it be easier to distinguish?

Or we could change the API spec to only send telemetry data via broadcast? Like you could monitor those messages alone and save telemetry to DB?

vishalkrishnads commented 1 year ago

Yeah I think that can be done... We'll have to create a Mongo collection for each vehicle on registration. We'd also have to think about how to structure the data as well.

Anyway, we'll need a separate logger module within the server for this. I'm on it...

vishalkrishnads commented 1 year ago

The new Logger being written uses a formula to calculate the average speed and stress on the vehicle. I'll leave them here for reference in the future when we might have to document them

Average Speed

The average speed is calculated using a weighted average formula, where the weights are the number of messages logged so far. The formula is:

average_speed = ((average_speed * message_count) + speed) / (message_count + 1)

where average_speed is the current average speed, message_count is the number of messages logged so far for the vehicle, and speed is the speed value from the current message being logged.

Essentially, the formula calculates the new average speed by taking the previous average speed and multiplying it by the number of messages already logged, adding the speed from the current message, and then dividing the result by the total number of messages logged so far (plus one, since we are logging a new message).

Stress

The stress is calculated using a simple moving average formula. The formula is:

stress = ((stress * (message_count - 1)) + stress_indicator) / message_count

where stress is the current stress value, message_count is the number of messages logged so far for the vehicle, and stress_indicator is a binary value indicating whether the vehicle is stressed or not (0 = not stressed, 1 = stressed).

The formula essentially calculates the new stress value by taking the previous stress value and multiplying it by the number of messages already logged, adding the stress indicator from the current message, and then dividing the result by the total number of messages logged so far. Since the formula is a simple moving average, it gives equal weight to all the values in the moving window (in this case, all the messages logged so far).