Skip to content

Commit 33d5c39

Browse files
Compact output and improve readability
1 parent 1b7f511 commit 33d5c39

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,26 @@ savings_color() {
175175

176176
report() {
177177
local db=$1 grouping=${2:-} filter rule='------------------------------------------------------------------'
178-
local b='' r='' red='' amber='' green='' prefix bar pct c
178+
local b='' r='' red='' amber='' green='' prefix bar pct c spct spi
179179
if [ -t 1 ]; then
180180
b=$'\e[1m'; r=$'\e[0m'
181181
red=$'\e[1;31m'; amber=$'\e[1;33m'; green=$'\e[1;32m'
182182
fi
183183
filter=$(grouping_filter "$grouping")
184184

185185
printf 'period : %s%s%s\n' "$b" "$(stat_period "$db" "$filter")" "$r"
186-
printf 'currency : %s%s%s (detected from invoices)\n' "$b" "$(stat_currency "$db" "$filter")" "$r"
186+
printf 'currency : %s%s%s\n' "$b" "$(stat_currency "$db" "$filter")" "$r"
187187
printf 'servers analysed : %s%s%s\n' "$b" "$(stat_servers "$db" "$filter")" "$r"
188188
printf 'price group : %s%s%s\n' "$b" "$(account_price_group "$db")" "$r"
189189
printf 'total paid : %s€%s%s\n' "$b" "$(stat_total_paid "$db" "$filter")" "$r"
190-
printf 'current run-rate : %s€%s%s/mo (last invoice)\n' "$b" "$(stat_run_rate "$db" "$filter")" "$r"
190+
printf 'current run-rate : %s€%s%s/mo\n' "$b" "$(stat_run_rate "$db" "$filter")" "$r"
191191
printf '%s\n' "$rule"
192-
printf 'picking the cheapest same-spec type each month would save : %s%s%%%s (%s€%s%s)\n' \
193-
"$b" "$(stat_savings_pct "$db" "$filter")" "$r" "$b" "$(stat_savings_amount "$db" "$filter")" "$r"
194-
printf ' recoverable now : %s%s%%%s (%s€%s%s) · already lost : %s%s%%%s (%s€%s%s)\n' \
192+
spct=$(stat_savings_pct "$db" "$filter")
193+
printf -v spi '%.0f' "$spct"
194+
printf 'cheapest same-spec each month would save : %s%s%%%s (%s€%s%s)\n' \
195+
"$(savings_color "$spi" "$red" "$amber" "$green")" "$spct" "$r" \
196+
"$b" "$(stat_savings_amount "$db" "$filter")" "$r"
197+
printf 'avoidable : %s%s%%%s (%s€%s%s) · needed earlier action : %s%s%%%s (%s€%s%s)\n' \
195198
"$b" "$(stat_recoverable_pct "$db" "$filter")" "$r" "$b" "$(stat_recoverable_amount "$db" "$filter")" "$r" \
196199
"$b" "$(stat_lost_pct "$db" "$filter")" "$r" "$b" "$(stat_lost_amount "$db" "$filter")" "$r"
197200
printf '%s\n' "$rule"

tests/integration.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ need_data() { # audit needs only local CSVs — no network, no credentials
8383
[ "$status" -eq 0 ]
8484
[[ "$output" =~ price\ group\ +:\ [a-z]+ ]]
8585
[[ "$output" =~ would\ save\ :\ [0-9]+\.[0-9]+% ]]
86-
[[ "$output" =~ recoverable\ now\ :\ [0-9]+\.[0-9]+%.*already\ lost\ :\ [0-9]+\.[0-9]+% ]]
86+
[[ "$output" =~ avoidable\ :\ [0-9]+\.[0-9]+%.*needed\ earlier\ action\ :\ [0-9]+\.[0-9]+% ]]
8787
}
8888

8989
@test "audit runs the committed synthetic examples with no credentials or network" {
9090
DB="$BATS_TEST_TMPDIR/example.db" run "$ROOT/gelkao" -q audit "$ROOT/examples"
9191
[ "$status" -eq 0 ]
9292
[[ "$output" =~ price\ group\ +:\ eu ]]
9393
[[ "$output" =~ would\ save\ :\ 3[0-9]\.[0-9]+% ]]
94-
[[ "$output" =~ recoverable\ now\ :\ [0-9]+\.[0-9]+%.*already\ lost\ :\ [0-9]+\.[0-9]+% ]]
94+
[[ "$output" =~ avoidable\ :\ [0-9]+\.[0-9]+%.*needed\ earlier\ action\ :\ [0-9]+\.[0-9]+% ]]
9595
}
9696

9797
@test "gelkao <cn> end-to-end downloads then reports a positive line count" {

tests/report.bats

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ locked_pair_db() {
141141
run audit "$a" "$d" "$BATS_TEST_TMPDIR/r3.db"
142142
[ "$status" -eq 0 ]
143143
[ "${lines[0]}" = "period : 2025-11 .. 2025-11 (1 months)" ]
144-
[ "${lines[1]}" = "currency : EUR (detected from invoices)" ]
144+
[ "${lines[1]}" = "currency : EUR" ]
145145
[ "${lines[2]}" = "servers analysed : 1" ]
146146
[ "${lines[3]}" = "price group : eu" ]
147147
[ "${lines[4]}" = "total paid : €4.99" ]
148-
[ "${lines[5]}" = "current run-rate : €4.99/mo (last invoice)" ]
149-
[ "${lines[7]}" = "picking the cheapest same-spec type each month would save : 24.0% (€1)" ]
148+
[ "${lines[5]}" = "current run-rate : €4.99/mo" ]
149+
[ "${lines[7]}" = "cheapest same-spec each month would save : 24.0% (€1)" ]
150150
[[ "${lines[10]}" =~ ^2025-11[[:space:]]+paid[[:space:]]+5[[:space:]]+optimal[[:space:]]+4[[:space:]]+#+[[:space:]]+24%$ ]]
151151
}
152152

@@ -168,11 +168,11 @@ locked_pair_db() {
168168
[[ "${lines[10]}" =~ [[:space:]]39%$ ]]
169169
}
170170

171-
@test "the saving splits into still-recoverable and already-lost lines" {
171+
@test "the saving splits into avoidable and needed-earlier-action lines" {
172172
a="$BATS_TEST_TMPDIR/lps"; jun2026_assets "$a" 2026-06-15
173173
d="$BATS_TEST_TMPDIR/lpsd"; mkdir -p "$d"; jun2026_locked_pair_invoice "$d/i.csv"
174174
run audit "$a" "$d" "$BATS_TEST_TMPDIR/lps.db"
175175
[ "$status" -eq 0 ]
176-
[[ "$output" =~ recoverable.*0\.0%.*\(€0\) ]]
177-
[[ "$output" =~ lost.*13\.4%.*\(€2\) ]]
176+
[[ "$output" =~ avoidable.*0\.0%.*\(€0\) ]]
177+
[[ "$output" =~ earlier\ action.*13\.4%.*\(€2\) ]]
178178
}

0 commit comments

Comments
 (0)