magicciv/tools/ecology-report.sh
2026-04-07 17:52:04 -07:00

68 lines
2 KiB
Bash
Executable file

#!/bin/bash
# ecology-report.sh — Run ecology bench and print summary table.
#
# Usage:
# ./tools/ecology-report.sh [--biome <id>] [--ticks <n>]
#
# Plot maturity curve:
# cargo run --bin ecology_bench -- single-tile --ticks 120000 > /tmp/eco.csv
# gnuplot -e "set datafile separator ','; set key autotitle columnhead; \
# plot '/tmp/eco.csv' using 1:5 with lines title 'maturity', \
# '' using 1:2 with lines title 'canopy', \
# '' using 1:4 with lines title 'fungi'"
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SIM_DIR="$SCRIPT_DIR/../src/simulator"
BIOME="${1:-temperate_forest}"
TICKS="${2:-120000}"
# Parse named args
while [[ $# -gt 0 ]]; do
case "$1" in
--biome) BIOME="$2"; shift 2 ;;
--ticks) TICKS="$2"; shift 2 ;;
*) shift ;;
esac
done
echo "=== Ecology Report ==="
echo ""
echo "--- Single Tile ($BIOME, ${TICKS} ticks) ---"
echo ""
cd "$SIM_DIR"
# Run bench, capture CSV stdout and summary stderr
TMPCSV=$(mktemp /tmp/eco_report_XXXXXX.csv)
TMPSTDERR=$(mktemp /tmp/eco_report_XXXXXX.err)
trap 'rm -f "$TMPCSV" "$TMPSTDERR"' EXIT
cargo run --release --bin ecology_bench -- single-tile --biome "$BIOME" --ticks "$TICKS" \
> "$TMPCSV" 2> "$TMPSTDERR"
# Print sampled milestones from CSV
echo "Sampled data points:"
awk -F, '{
if (NR==1) { print; next }
tick = $1 + 0
if (tick==0 || tick==1000 || tick==5000 || tick==15000 || tick==30000 || tick==50000 || tick==80000 || tick==100000 || tick==119999)
print
}' "$TMPCSV"
echo ""
echo "--- Summary ---"
cat "$TMPSTDERR"
echo ""
echo "--- World Age Sweep (temperate_forest) ---"
echo "ticks,final_canopy,final_fungi,final_maturity,final_soil,final_deadwood,final_habitat"
for age in 5000 15000 30000 50000 80000 120000; do
result=$(cargo run --release --bin ecology_bench -- single-tile --biome "$BIOME" --ticks "$age" 2>/dev/null | tail -1)
echo "ticks=$age: $result"
done
echo ""
echo "=== Report Complete ==="