pliceclogs-og/rfid-daemon/diagnostics/compare.sh
type-two e5b8504bc6 Import pliceclogs as-is — the original Discogs seller extension
Snapshot of the working tree exactly as it stood, no edits. This is the predecessor
PRICEGOD was rewritten from ("kept intact, untouched" per pricegod/README.md), and it
is still the only place the DYMO scale is actually implemented —
rfid-daemon/index.js:1068-1265: HID discovery, parseScaleReport, one-shot read, and a
streaming /weight + /scale/start|stop session whose JSON shape PRICEGOD's daemon.js
already speaks.

Preserved verbatim on purpose (hence -og), including the known bug: DYMO_PIDS at
index.js:1082 is [0x8003, 0x8004], so it cannot see the bench M25 (0x8009). Fix that
in whatever daemon inherits the scale, not here.

node_modules stays ignored (22M of the 24M tree). No credentials in the import: the
two PEM markers in utils.js/sheets.js only strip headers off a key read from settings,
and mrpadmin / johnking are an SSH and a Postgres username, both key/trust auth.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 13:47:09 +10:00

92 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
# Aggregates session logs across all variants and prints a comparison table.
# Reads everything in this directory matching run-*.log (JSON Lines from
# variants/log.js) and reports per-variant metrics.
#
# Usage: ./compare.sh # summarise all sessions found
# ./compare.sh keepalive # only show keepalive sessions
# ./compare.sh --since=7d # only sessions in the last 7 days
set -euo pipefail
cd "$(dirname "$0")"
FILTER="${1:-}"
shopt -s nullglob
LOGS=(run-*.log)
if [ ${#LOGS[@]} -eq 0 ]; then
echo "No session logs found in $(pwd)."
echo "Run a variant (e.g. node ../variants/keepalive.js) and price some tags first."
exit 0
fi
printf '%-12s %-22s %8s %8s %7s %8s %9s %12s %s\n' \
"VARIANT" "SESSION_START" "WRITES" "READS" "TIMEOUTS" "LOCKUPS" "RUNTIME_M" "WRITES/MIN" "FILE"
printf '%-12s %-22s %8s %8s %7s %8s %9s %12s %s\n' \
"-------" "----------------------" "------" "-----" "--------" "-------" "---------" "-----------" "----"
for log in "${LOGS[@]}"; do
fname="$log"
# extract "<variant>" from "run-<variant>-<stamp>.log"
base="${fname#run-}"
base="${base%.log}"
variant="${base%-*-*}"
stamp="${base#${variant}-}"
if [ -n "$FILTER" ] && [ "$variant" != "$FILTER" ]; then
continue
fi
awk -v variant="$variant" -v fname="$fname" -v stamp="$stamp" '
/"ev":"start"/ { sessionStartTs = ts() }
/"ev":"write_ok"/ { writes++ }
/"ev":"read_ok"/ { reads++ }
/"ev":"timeout"/ { timeouts++ }
/"ev":"lockup_detected"/ { lockups++ }
/"ev":"end"/ { hasEnd = 1; runtime = extractMs() }
function ts() {
match($0, /"ts":"[^"]+"/);
return substr($0, RSTART+6, RLENGTH-7);
}
function extractMs( m) {
if (match($0, /"runtimeMs":[0-9]+/)) {
return substr($0, RSTART+12, RLENGTH-12) + 0
}
return 0
}
END {
if (!hasEnd) {
# Active or crashed session: estimate runtime from first→last line
runtime = -1
}
runtimeMin = (runtime > 0) ? runtime / 60000.0 : 0
writesPerMin = (runtimeMin > 0) ? writes / runtimeMin : 0
label = sessionStartTs
if (length(label) > 22) label = substr(label, 1, 22)
printf "%-12s %-22s %8d %8d %7d %8d %9.1f %12.2f %s\n",
variant, label, writes+0, reads+0, timeouts+0, lockups+0,
runtimeMin, writesPerMin, fname
}
' "$log"
done
echo
echo "Per-variant aggregate:"
printf '%-12s %8s %8s %8s %12s %s\n' "VARIANT" "WRITES" "TIMEOUT" "LOCKUPS" "WRITES/LOCK" "SESSIONS"
printf '%-12s %8s %8s %8s %12s %s\n' "-------" "------" "-------" "-------" "-----------" "--------"
for variant in control keepalive preflight slowpace broadcast; do
files=(run-${variant}-*.log)
[ ${#files[@]} -eq 0 ] && continue
awk -v variant="$variant" -v sessions="${#files[@]}" '
/"ev":"write_ok"/ { writes++ }
/"ev":"timeout"/ { timeouts++ }
/"ev":"lockup_detected"/ { lockups++ }
END {
ratio = (lockups > 0) ? writes / lockups : writes
printf "%-12s %8d %8d %8d %12.1f %s\n", variant, writes+0, timeouts+0, lockups+0, ratio, sessions
}
' "${files[@]}"
done