Fix show-impact.sh cost formatting to use python3 instead of bc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
claude 2026-03-17 13:16:51 +00:00
parent 1c35751095
commit d5c8ca937d
2 changed files with 10 additions and 8 deletions

View file

@ -48,7 +48,8 @@ while IFS= read -r line; do
if [ "$cache_create" != "0" ] || [ "$cache_read" != "0" ]; then if [ "$cache_create" != "0" ] || [ "$cache_read" != "0" ]; then
printf " Cache: %s created, %s read\n" "$cache_create" "$cache_read" printf " Cache: %s created, %s read\n" "$cache_create" "$cache_read"
fi fi
LC_NUMERIC=C printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%.2f\n" "$energy" "$co2" "$(echo "$cost / 100" | bc -l 2>/dev/null || echo "$cost cents")" cost_dollars=$(python3 -c "print(f'{int(\"${cost}\") / 100:.2f}')" 2>/dev/null || echo "?")
printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%s\n" "$energy" "$co2" "$cost_dollars"
# Social cost proxies (if present in log entry) # Social cost proxies (if present in log entry)
model=$(echo "$line" | jq -r '.model_id // empty') model=$(echo "$line" | jq -r '.model_id // empty')
@ -88,9 +89,9 @@ TOTAL_COST=$(jq -s '[.[].cost_cents] | add' "$LOG_FILE")
TOTAL_ENTRIES=$(wc -l < "$LOG_FILE") TOTAL_ENTRIES=$(wc -l < "$LOG_FILE")
echo "=== Totals ($TOTAL_ENTRIES snapshots) ===" echo "=== Totals ($TOTAL_ENTRIES snapshots) ==="
LC_NUMERIC=C printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%.2f\n" \ TOTAL_COST_DOLLARS=$(python3 -c "print(f'{int(\"${TOTAL_COST}\") / 100:.2f}')" 2>/dev/null || echo "?")
"$TOTAL_ENERGY" "$TOTAL_CO2" \ printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%s\n" \
"$(echo "$TOTAL_COST / 100" | bc -l 2>/dev/null || echo "$TOTAL_COST cents")" "$TOTAL_ENERGY" "$TOTAL_CO2" "$TOTAL_COST_DOLLARS"
# Show annotations if they exist # Show annotations if they exist
ANNOT_FILE="$PROJECT_DIR/.claude/impact/annotations.jsonl" ANNOT_FILE="$PROJECT_DIR/.claude/impact/annotations.jsonl"

View file

@ -48,7 +48,8 @@ while IFS= read -r line; do
if [ "$cache_create" != "0" ] || [ "$cache_read" != "0" ]; then if [ "$cache_create" != "0" ] || [ "$cache_read" != "0" ]; then
printf " Cache: %s created, %s read\n" "$cache_create" "$cache_read" printf " Cache: %s created, %s read\n" "$cache_create" "$cache_read"
fi fi
LC_NUMERIC=C printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%.2f\n" "$energy" "$co2" "$(echo "$cost / 100" | bc -l 2>/dev/null || echo "$cost cents")" cost_dollars=$(python3 -c "print(f'{int(\"${cost}\") / 100:.2f}')" 2>/dev/null || echo "?")
printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%s\n" "$energy" "$co2" "$cost_dollars"
# Social cost proxies (if present in log entry) # Social cost proxies (if present in log entry)
model=$(echo "$line" | jq -r '.model_id // empty') model=$(echo "$line" | jq -r '.model_id // empty')
@ -88,9 +89,9 @@ TOTAL_COST=$(jq -s '[.[].cost_cents] | add' "$LOG_FILE")
TOTAL_ENTRIES=$(wc -l < "$LOG_FILE") TOTAL_ENTRIES=$(wc -l < "$LOG_FILE")
echo "=== Totals ($TOTAL_ENTRIES snapshots) ===" echo "=== Totals ($TOTAL_ENTRIES snapshots) ==="
LC_NUMERIC=C printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%.2f\n" \ TOTAL_COST_DOLLARS=$(python3 -c "print(f'{int(\"${TOTAL_COST}\") / 100:.2f}')" 2>/dev/null || echo "?")
"$TOTAL_ENERGY" "$TOTAL_CO2" \ printf " Energy: ~%s Wh CO2: ~%sg Cost: ~\$%s\n" \
"$(echo "$TOTAL_COST / 100" | bc -l 2>/dev/null || echo "$TOTAL_COST cents")" "$TOTAL_ENERGY" "$TOTAL_CO2" "$TOTAL_COST_DOLLARS"
# Show annotations if they exist # Show annotations if they exist
ANNOT_FILE="$PROJECT_DIR/.claude/impact/annotations.jsonl" ANNOT_FILE="$PROJECT_DIR/.claude/impact/annotations.jsonl"