#!/usr/bin/env bash
# Byte-count experiments for the columnar-compression article (no timing).
#   B=$(mktemp -d); BUILD_DIR=$B bash run.sh
# PY: interpreter with requirements.txt installed; PLOT_PY: one with matplotlib.
set -euo pipefail
cd "$(dirname "$0")"
: "${BUILD_DIR:?set BUILD_DIR to a scratch directory}"
PY=${PY:-python3}
PLOT_PY=${PLOT_PY:-$PY}
OUT=${OUT:-results}
mkdir -p "$BUILD_DIR" "$OUT"

$PY conformance.py "$BUILD_DIR"
$PY sizes.py "$BUILD_DIR"
cp "$BUILD_DIR"/conformance.txt "$BUILD_DIR"/summary.txt \
   "$BUILD_DIR"/columns_original.tsv "$BUILD_DIR"/columns_sorted.tsv "$OUT"/
{
  lscpu | grep -E 'Model name|^CPU\(s\)'
  uname -r
  $PY --version
  $PY -c 'import pyarrow, duckdb, numpy; print("pyarrow", pyarrow.__version__, "duckdb", duckdb.__version__, "numpy", numpy.__version__)'
} > "$OUT/env.txt"
if $PLOT_PY -c 'import matplotlib' 2>/dev/null; then
  $PLOT_PY plot.py "$OUT" ../column-bytes.svg
fi
