-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendar_gen.py
More file actions
68 lines (45 loc) · 2.08 KB
/
calendar_gen.py
File metadata and controls
68 lines (45 loc) · 2.08 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Synthetic Calendar Generator MVP.
Generates a 7-day schedule for a single character using a simple
configuration file. The generator prioritises sleep, work, meals, and
optional activities before filling the remaining gaps with free time.
Usage:
python calendar_gen.py config.json output.json
"""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from typing import Dict, Optional, Sequence
from engines.base import ScheduleInput
from rigs.simple_rig import SimpleRig
def load_config(path: Path) -> Dict[str, object]:
"""Load the configuration JSON as a raw dictionary."""
return json.loads(path.read_text())
def write_output(events: Sequence[Dict[str, object]], path: Path) -> None:
"""Serialise the generated events to JSON."""
path.write_text(json.dumps(list(events), indent=2))
def format_totals(totals: Dict[str, float]) -> Sequence[str]:
return [f"Total {activity}: {hours:.1f} hours" for activity, hours in sorted(totals.items())]
def main(argv: Optional[Sequence[str]] = None) -> None:
parser = argparse.ArgumentParser(description="Synthetic Calendar Generator")
parser.add_argument("config", type=Path, help="Path to configuration JSON")
parser.add_argument("output", type=Path, help="Path to output JSON file")
args = parser.parse_args(argv)
raw_config = load_config(args.config)
rig = SimpleRig()
schedule_input = ScheduleInput(constraints=raw_config)
result = rig.generate(schedule_input)
write_output(result.events, args.output)
week_start = result.diagnostics.get("week_start")
week_end = result.diagnostics.get("week_end")
character_name = result.diagnostics.get("character_name", raw_config.get("name", ""))
print(f"Generated schedule for {character_name}")
if week_start is not None and week_end is not None:
print(f"Week of {week_start.isoformat()} to {week_end.isoformat()}")
print()
for line in format_totals(dict(result.totals)):
print(line)
print()
print(f"Schedule saved to {args.output}")
if __name__ == "__main__":
main()