summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-04-05 18:51:41 +0200
committerAki <please@ignore.pl>2024-04-05 18:57:53 +0200
commit84423e63959e31a8eb55efbf7194798bee3811dd (patch)
tree0bb4902f170e5fd0c3611019dc3674409d060301
downloadfuel-84423e63959e31a8eb55efbf7194798bee3811dd.zip
fuel-84423e63959e31a8eb55efbf7194798bee3811dd.tar.gz
fuel-84423e63959e31a8eb55efbf7194798bee3811dd.tar.bz2
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.
-rwxr-xr-xdump.lua7
-rw-r--r--fuel.lua30
2 files changed, 37 insertions, 0 deletions
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}