File indexing completed on 2026-11-09 10:47:24
0001
0002 """Refresh the retained efficiency history; hourly, with monthly --full reconciliation."""
0003 import argparse
0004 from datetime import date
0005 import json
0006 import os
0007 import sys
0008 from pathlib import Path
0009
0010 sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'src'))
0011 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0012 import django
0013 django.setup()
0014 from monitor_app.compute_efficiency import product
0015 from monitor_app.productive_cores import product as productive_cores_product
0016
0017 if __name__ == '__main__':
0018 ap = argparse.ArgumentParser(description=__doc__)
0019 ap.add_argument('--full', action='store_true')
0020 ap.add_argument('--reread-from', type=date.fromisoformat,
0021 help='reread daily production cores from this day (YYYY-MM-DD), not the last seven')
0022 args = ap.parse_args()
0023 result = product(refresh=True, full=args.full)
0024 if not result.get('value'):
0025 raise RuntimeError('Efficiency history did not produce a stored result')
0026 daily_cores = productive_cores_product(refresh=True, reread_from=args.reread_from)
0027 if not daily_cores.get('value'):
0028 raise RuntimeError('Daily production core history did not produce a stored result')
0029 print(json.dumps({'built_at': str(result['built_at']),
0030 'daily_rows': len(result['value']['daily']),
0031 'reread_from': result['value']['reread_from'],
0032 'production_core_days': len(daily_cores['value']['daily'])}))