Spaces:
Sleeping
Sleeping
| """ | |
| Run this script after any change to inputs_aggregated.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"), | |
| ("Input template (inputs_template.xlsx)", "data/generate_input_template.py"), | |
| ("Resource template (resource_template.xlsx)", "data/generate_resource_template.py"), | |
| ] | |
| print("=" * 60) | |
| print("CRRA Optimization 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_aggregated.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()) | |