Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong calculation of fuel economy if missing odometer on fuel records #796

Closed
3 of 4 tasks
pecataToshev opened this issue Jan 10, 2025 · 8 comments
Closed
3 of 4 tasks
Assignees
Labels
pending release fix in place, pending release

Comments

@pecataToshev
Copy link

Checklist
Please make sure you have performed the following steps before opening a new bug ticket, change [ ] to [x] to mark it as done

  • I have read and tried the steps outlined in the Troubleshooting Guide
  • I have searched through existing issues.

Platform

  • Docker Image
  • Windows Standalone Executable

Description
When calculating the fuel economy, the data is incorrect if there are missing odometer records attached to it.

e.g. on dates 2024-12-01 and 2024-09-28

image

I think it'd be correct if it's using the following formulas:
Δ(km) = ${currentOdometerForTheRecord} - ${previousOdometerInFuel}
Fuel Economy(l/100km) = sum(ConsumptionExcludingPreviousRecordWithOdometer) / Δ(km)

So the result will become something like this:
image

To calculate it I created a simple JS algorithm:

const nil = "---";
let res = []
for (let i = 0; i < data.length - 1; i++) {
    let fuelEconomy = nil;
    let delta = nil;
    let consumption = data[i]["Consumption(l)"];
    if (data[i]["Odometer(km)"] !== nil) {
        for (let ii = i + 1; ii < data.length; ii++) {
            if (data[ii]["Odometer(km)"] !== nil) {
                delta = data[i]["Odometer(km)"] - data[ii]["Odometer(km)"];
                break;
            }
            consumption += data[ii]["Consumption(l)"];
        }
    }
    if (delta !== nil) {
        fuelEconomy = (100 * consumption) / delta;
    }
    res.push({
        ...data[i],
        "Δ(km)": delta,
        "Fuel Economy(l/100km)": fuelEconomy,
    })
}
@hargata hargata self-assigned this Jan 10, 2025
@hargata
Copy link
Owner

hargata commented Jan 10, 2025

yeah...we're not sure if this is something that really needs fixing. The context behind making the odometer field optional is because of #619 where a user might not fill out the odometer at the point of fueling up but they are expected to fill out the odometer field eventually.

Your use-case doesn't seem right. What is the use case for only recording the odometer every 10-20 fuel ups?

@pecataToshev
Copy link
Author

I often find myself in situations where accurately tracking my fuel usage is a challenge. For example:

  1. Traveling in areas with limited or no internet access: I just save my fuel recipes and add them later, but often forget to note down the odometer reading at the time of fueling.
  2. Adding historical fuel data: If I'm adding past fueling records that I didn't initially record in the app, it's difficult to accurately track my fuel efficiency because I might not have the original odometer readings for each of them.

I don't see why missing a single odometer reading on a fuel record should mess up all of the data with making the "delta" equal the odometer reading and basically making the fuel efficiency close to zero.

In the end this is a manual process and people might forget to do a step or two out of it

@hargata
Copy link
Owner

hargata commented Jan 10, 2025

That makes sense, let me look into this

@pecataToshev
Copy link
Author

Thanks, mate! Appreciate it! Let me know if I can help further.

@hargata hargata mentioned this issue Jan 10, 2025
@hargata hargata added the pending release fix in place, pending release label Jan 10, 2025
@hargata
Copy link
Owner

hargata commented Jan 10, 2025

kk, put in a fix for this, can you pull down the :edge tag docker image and try it?

image

@pecataToshev
Copy link
Author

Works fine in the fuel:
image

However I think it might be slightly wrong in the Dashboard -> Vehicle Maintenance Report. Not sure if related to th current fix though.
image

@hargata
Copy link
Owner

hargata commented Jan 10, 2025

that should be fixed now

@hargata
Copy link
Owner

hargata commented Jan 10, 2025

Fix released.

@hargata hargata closed this as completed Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending release fix in place, pending release
Projects
None yet
Development

No branches or pull requests

2 participants