51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""Serve Thor's UI with data from the replays, for screenshots and design review.
|
||
|
|
|
||
|
|
Usage: .venv/bin/python scripts/ui_demo.py [port] (default 8811, binds 127.0.0.1)
|
||
|
|
|
||
|
|
The store holds T1 stopped mid-incident (05:40, an open P1), the T2 maintenance timeline,
|
||
|
|
the DIMM known-condition note, and the T4 partition, all from tests/fixtures. The clock is
|
||
|
|
frozen at T1 05:40 so "ago" texts read as they would have that night.
|
||
|
|
"""
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
ROOT = Path(__file__).resolve().parent.parent
|
||
|
|
sys.path.insert(0, str(ROOT))
|
||
|
|
|
||
|
|
from tests.fakes import FakeStore # noqa: E402
|
||
|
|
from tests.replay import Replay # noqa: E402
|
||
|
|
from thor.config import Settings # noqa: E402
|
||
|
|
from thor.web.app import create_app # noqa: E402
|
||
|
|
|
||
|
|
T1_0540 = 1795412400.0
|
||
|
|
|
||
|
|
|
||
|
|
def demo_store() -> FakeStore:
|
||
|
|
merged = FakeStore()
|
||
|
|
runs = [Replay('t4').run(), Replay('dimm').run(), Replay('t2').run(), Replay('t1').run(until=T1_0540)]
|
||
|
|
for r in runs:
|
||
|
|
merged.incidents.update(r.store.incidents)
|
||
|
|
offset = len(merged.actions)
|
||
|
|
for a in r.store.actions:
|
||
|
|
merged.actions.append(dict(a, id=a['id'] + offset))
|
||
|
|
merged.observations.update(r.store.observations)
|
||
|
|
t1 = runs[-1].store
|
||
|
|
merged.state.update(t1.state)
|
||
|
|
merged.sources = t1.sources
|
||
|
|
merged.blind = t1.blind
|
||
|
|
# Show T2's maintenance as still active, as it was mid-window.
|
||
|
|
m = merged.incidents['maintenance:gandalf:2']
|
||
|
|
m.update(state='open', cleared_at=None, last_seen=T1_0540 - 600)
|
||
|
|
return merged
|
||
|
|
|
||
|
|
|
||
|
|
def build():
|
||
|
|
settings = Settings()
|
||
|
|
settings.public_url = ''
|
||
|
|
return create_app(settings, demo_store(), 'demo0000', clock=lambda: T1_0540)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8811
|
||
|
|
build().run(host='127.0.0.1', port=port)
|