Spaces:
Sleeping
Sleeping
File size: 1,297 Bytes
fa58ff0 60dd41c fa58ff0 7a80c0b fa58ff0 60dd41c fa58ff0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """
Run this script after any change to inputs.csv to update all
generated data files and Excel templates.
Usage:
python data/update.py
"""
import hashlib
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).parent.parent
PYTHON = sys.executable
scripts = [
("Coefficients + method groups + secondary resources", "data/generate_model_data.py"),
("Resource template (resource_template.xlsx)", "data/generate_resource_template.py"),
]
print("=" * 60)
print("CRRA Optimisation Tool — data update")
print("=" * 60)
for label, script in scripts:
print(f"\n▶ {label}")
result = subprocess.run(
[PYTHON, str(ROOT / script)],
cwd=str(ROOT),
capture_output=True,
text=True,
)
for line in result.stdout.splitlines():
print(f" {line}")
if result.returncode != 0:
print(f" ERROR:\n{result.stderr}")
sys.exit(result.returncode)
print("\n" + "=" * 60)
print("All files updated successfully.")
print("=" * 60)
# Update the hash file so the app knows the CSV is in sync
csv_path = ROOT / "data/inputs.csv"
hash_path = ROOT / "data/.csv_hash"
hasher = hashlib.md5()
with open(csv_path, "rb") as f:
hasher.update(f.read())
with open(hash_path, "w") as f:
f.write(hasher.hexdigest())
|