From 84423e63959e31a8eb55efbf7194798bee3811dd Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 5 Apr 2024 18:51:41 +0200 Subject: Dumped recent refueling history into a repository Yes, currently it only dumps into the standard output. There's too little data especially on LPG to make any good estimates at this point. Later on, this format will allow the data to be dumped anywhere for any kind of analysis or calculations to be done within this codebase. Or something like that. --- dump.lua | 7 +++++++ fuel.lua | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 dump.lua create mode 100644 fuel.lua diff --git a/dump.lua b/dump.lua new file mode 100755 index 0000000..4fb3d77 --- /dev/null +++ b/dump.lua @@ -0,0 +1,7 @@ +#!/usr/bin/env -S lua -l fuel +local f = fuel.fill +local r = fuel.relative +f("O", "2023-12-28", "17:55", 202230.0, "95", 100.21, 15.37) +f("O", "2024-02-23", "12:05", r(119.2), "lpg", 74.14, 23.61) +f("O", "2024-02-23", "12:18", 202350.9, "95", 100.02, 14.95) +f("O", "2024-04-05", "12:27", r(279.2), "95", 100.16, 14.86) diff --git a/fuel.lua b/fuel.lua new file mode 100644 index 0000000..c10b205 --- /dev/null +++ b/fuel.lua @@ -0,0 +1,30 @@ +local fmts = { + ["zł"] = "%.2f %s", + l = "%.2f %s", + km = "%.1f %s", +} + + +local function fmt (value, unit) + return (fmts[unit] or "%.1f"):format(value, unit) +end + + +local last_milage = 0 + + +local function relative (kilometres) + return last_milage + kilometres +end + + +local function fill (id, date, time, milage, fuel, cost, volume) + if last_milage > milage then + error "new milage may not be less than the previous" + end + last_milage = milage + print(id, date, time, fmt(last_milage, "km"), fuel, fmt(cost, "zł"), fmt(volume, "l")) +end + + +return {fill=fill, relative=relative} -- cgit v1.1