ekos-notifier 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ekos_notifier/__init__.py +3 -0
- ekos_notifier/__main__.py +5 -0
- ekos_notifier/alerts.py +86 -0
- ekos_notifier/align.py +135 -0
- ekos_notifier/calibration.py +92 -0
- ekos_notifier/capture.py +186 -0
- ekos_notifier/cli.py +463 -0
- ekos_notifier/clouds.py +246 -0
- ekos_notifier/conditions.py +396 -0
- ekos_notifier/config.example.yaml +109 -0
- ekos_notifier/config.py +209 -0
- ekos_notifier/digest.py +371 -0
- ekos_notifier/disk.py +139 -0
- ekos_notifier/ekos/__init__.py +1 -0
- ekos_notifier/ekos/adapter.py +357 -0
- ekos_notifier/ekos/bus.py +82 -0
- ekos_notifier/ekos/decode.py +154 -0
- ekos_notifier/ekos/settings.py +261 -0
- ekos_notifier/ekos/states.py +140 -0
- ekos_notifier/ephemeris.py +127 -0
- ekos_notifier/events.py +22 -0
- ekos_notifier/focus.py +87 -0
- ekos_notifier/guiding.py +516 -0
- ekos_notifier/indi/__init__.py +2 -0
- ekos_notifier/indi/adapter.py +151 -0
- ekos_notifier/indi/decode.py +401 -0
- ekos_notifier/indi/dump.py +119 -0
- ekos_notifier/indi/presets/camera-standard.yaml +8 -0
- ekos_notifier/indi/presets/focuser-standard.yaml +8 -0
- ekos_notifier/indi/presets/power-standard.yaml +13 -0
- ekos_notifier/indi/presets/weather-standard.yaml +12 -0
- ekos_notifier/indi/presets.py +92 -0
- ekos_notifier/legacy.py +65 -0
- ekos_notifier/lock.py +60 -0
- ekos_notifier/messages.py +180 -0
- ekos_notifier/notify.py +236 -0
- ekos_notifier/phd2/__init__.py +1 -0
- ekos_notifier/phd2/adapter.py +163 -0
- ekos_notifier/phd2/decode.py +185 -0
- ekos_notifier/pipeline.py +85 -0
- ekos_notifier/power.py +316 -0
- ekos_notifier/reload.py +85 -0
- ekos_notifier/replay.py +80 -0
- ekos_notifier/rules.py +406 -0
- ekos_notifier/samples/__init__.py +17 -0
- ekos_notifier/samples/sim-m31-scheduler-kstars-3.8.5-flatpak.ndjson.gz +0 -0
- ekos_notifier/service.py +231 -0
- ekos_notifier/session.py +265 -0
- ekos_notifier/simulate.py +187 -0
- ekos_notifier/sky.py +320 -0
- ekos_notifier/stats.py +117 -0
- ekos_notifier/store.py +471 -0
- ekos_notifier/systemd.py +118 -0
- ekos_notifier-0.1.0.dist-info/METADATA +349 -0
- ekos_notifier-0.1.0.dist-info/RECORD +58 -0
- ekos_notifier-0.1.0.dist-info/WHEEL +4 -0
- ekos_notifier-0.1.0.dist-info/entry_points.txt +2 -0
- ekos_notifier-0.1.0.dist-info/licenses/LICENSE +21 -0
ekos_notifier/alerts.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Shared pieces for alert rules: building alert events, wording times, and a base class that
|
|
2
|
+
knows whether a session is active.
|
|
3
|
+
|
|
4
|
+
An alert is an ``Event`` of kind ``alert`` (source ``rules``) with ``rule``, ``priority``
|
|
5
|
+
(emergency | high | normal | quiet), ``title``, ``body`` and ``immediate`` (a Normal alert sent at
|
|
6
|
+
once rather than in the hourly digest). The notifier sends them from the store.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import time
|
|
12
|
+
from collections.abc import Iterable
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from ekos_notifier.events import Event
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def make_alert(
|
|
19
|
+
ts: float,
|
|
20
|
+
session_id: str | None,
|
|
21
|
+
rule: str,
|
|
22
|
+
priority: str,
|
|
23
|
+
title: str,
|
|
24
|
+
body: str,
|
|
25
|
+
*,
|
|
26
|
+
immediate: bool = False,
|
|
27
|
+
**extra: Any,
|
|
28
|
+
) -> Event:
|
|
29
|
+
data: dict[str, Any] = {
|
|
30
|
+
"rule": rule,
|
|
31
|
+
"priority": priority,
|
|
32
|
+
"title": title,
|
|
33
|
+
"body": body,
|
|
34
|
+
"immediate": immediate,
|
|
35
|
+
**extra,
|
|
36
|
+
}
|
|
37
|
+
return Event(ts, "alert", data, "rules", session_id)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def hhmm(ts: float) -> str:
|
|
41
|
+
return time.strftime("%H:%M", time.localtime(ts))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def minutes(seconds: float) -> str:
|
|
45
|
+
return f"{max(1, round(seconds / 60))} min"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class SessionRule:
|
|
49
|
+
"""A rule that only alerts during an active session. Subclasses implement ``on_event`` and
|
|
50
|
+
``on_tick``; ``session`` is the active session's id, or None. ``SETTINGS`` names the
|
|
51
|
+
attributes that come from the config: a config reload copies those from a freshly built rule
|
|
52
|
+
and leaves everything the rule has learned alone."""
|
|
53
|
+
|
|
54
|
+
SETTINGS: tuple[str, ...] = ()
|
|
55
|
+
|
|
56
|
+
def __init__(self) -> None:
|
|
57
|
+
self.session: str | None = None
|
|
58
|
+
|
|
59
|
+
def resume(self, session_id: str | None, alerts: Iterable[Event] = ()) -> None:
|
|
60
|
+
self.session = session_id
|
|
61
|
+
|
|
62
|
+
def handle(self, event: Event) -> list[Event]:
|
|
63
|
+
if event.kind == "session.started":
|
|
64
|
+
self.resume(event.session_id)
|
|
65
|
+
out = self.on_event(event)
|
|
66
|
+
if event.kind == "session.closed":
|
|
67
|
+
self.session = None
|
|
68
|
+
self.on_session_closed()
|
|
69
|
+
return out + self.tick(event.ts)
|
|
70
|
+
|
|
71
|
+
def tick(self, now: float) -> list[Event]:
|
|
72
|
+
return self.on_tick(now) if self.session else []
|
|
73
|
+
|
|
74
|
+
def on_event(self, event: Event) -> list[Event]:
|
|
75
|
+
return []
|
|
76
|
+
|
|
77
|
+
def on_tick(self, now: float) -> list[Event]:
|
|
78
|
+
return []
|
|
79
|
+
|
|
80
|
+
def on_session_closed(self) -> None:
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
def preflight(self, now: float) -> list[tuple[bool, str]]:
|
|
84
|
+
"""Pre-flight checks for "Starting session": (passed, words) for what this rule can see
|
|
85
|
+
of the rig right now. Nothing when it can't tell."""
|
|
86
|
+
return []
|
ekos_notifier/align.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""The "Plate solve failed" alert (High, docs/design.md "Alerts").
|
|
2
|
+
|
|
3
|
+
During a session, an Ekos Align run that fails, with no successful solve within ``RETRY_GRACE``
|
|
4
|
+
seconds (Ekos retries a solve by itself with looser settings, and the Scheduler retries a job's
|
|
5
|
+
alignment stage), sends **Plate solve failed**: what came just before (a meridian flip, or the
|
|
6
|
+
Scheduler moving to a new target), how many runs have failed, and Ekos's last reason ("Solver
|
|
7
|
+
timed out after 60 seconds."). Once per streak; **Plate solve succeeded** (Normal, immediate)
|
|
8
|
+
follows the next successful solve.
|
|
9
|
+
|
|
10
|
+
A run is everything from ``in_progress`` until it ends ``complete``/``successful``, ``failed`` or
|
|
11
|
+
``aborted``. It failed if it ended ``failed``, or ``aborted`` with a solver failure logged during
|
|
12
|
+
it (KStars 3.8.5's autofocus ends a failed run ``aborted``, seen live, so Align is treated the same
|
|
13
|
+
way until a failed solve is recorded). An ``aborted`` with no failure logged is the user's own
|
|
14
|
+
Abort and counts for nothing. Failure lines are Align's own (from KStars 3.8.5's strings): "Solver
|
|
15
|
+
Failed.", "Solver failed after %1 seconds.", "Solver timed out after %1 seconds.", "Maximum number
|
|
16
|
+
of iterations reached. Solver failed.", "Astrometry alignment failed". Its retry lines ("Solver
|
|
17
|
+
failed. Retrying without scale constraint.", "Plate solving failed, extending criteria and
|
|
18
|
+
retrying...") mean the run continues.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import re
|
|
24
|
+
from collections.abc import Iterable
|
|
25
|
+
|
|
26
|
+
from ekos_notifier.alerts import SessionRule, hhmm, make_alert
|
|
27
|
+
from ekos_notifier.events import Event
|
|
28
|
+
|
|
29
|
+
RETRY_GRACE = 180.0
|
|
30
|
+
CONTEXT_WINDOW = 900.0 # a flip or target change this soon before the run explains it
|
|
31
|
+
RUNNING = {"in_progress", "syncing", "slewing", "rotating"}
|
|
32
|
+
SOLVED = {"complete", "successful"}
|
|
33
|
+
FAILURE = re.compile(
|
|
34
|
+
r"solver failed|solver timed out|solver aborted|alignment failed|failed plate solving", re.I
|
|
35
|
+
)
|
|
36
|
+
RETRYING = re.compile(r"retry", re.I)
|
|
37
|
+
JOB = re.compile(r"Job '(.+?)' ")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class PlateSolveRule(SessionRule):
|
|
41
|
+
def __init__(self, retry_grace: float = RETRY_GRACE) -> None:
|
|
42
|
+
super().__init__()
|
|
43
|
+
self.retry_grace = retry_grace
|
|
44
|
+
self._in_run = False
|
|
45
|
+
self._run_failed = False # a final solver failure logged in this run
|
|
46
|
+
self._reason: str | None = None
|
|
47
|
+
self._failed_at: float | None = None # first failed run of the streak, not yet sent
|
|
48
|
+
self._streak = 0
|
|
49
|
+
self._alerted = False
|
|
50
|
+
self._flip_at: float | None = None
|
|
51
|
+
self._target: tuple[float, str] | None = None # when the Scheduler moved on, to what
|
|
52
|
+
|
|
53
|
+
def resume(self, session_id: str | None, alerts: Iterable[Event] = ()) -> None:
|
|
54
|
+
super().resume(session_id, alerts)
|
|
55
|
+
for a in alerts:
|
|
56
|
+
if a.data.get("rule") == "plate_solve_failed":
|
|
57
|
+
self._alerted = True
|
|
58
|
+
elif a.data.get("rule") == "plate_solve_ok":
|
|
59
|
+
self._alerted = False
|
|
60
|
+
|
|
61
|
+
def on_session_closed(self) -> None:
|
|
62
|
+
self._in_run = self._run_failed = self._alerted = False
|
|
63
|
+
self._failed_at, self._streak = None, 0
|
|
64
|
+
|
|
65
|
+
def on_event(self, event: Event) -> list[Event]:
|
|
66
|
+
kind, d, ts = event.kind, event.data, event.ts
|
|
67
|
+
if kind == "capture.state" and d.get("state") == "meridian_flip":
|
|
68
|
+
self._flip_at = ts
|
|
69
|
+
elif kind == "capture.flip_started":
|
|
70
|
+
self._flip_at = ts
|
|
71
|
+
elif kind == "ekos.log":
|
|
72
|
+
text = str(d.get("text", ""))
|
|
73
|
+
if d.get("module") == "Align" and FAILURE.search(text) and not RETRYING.search(text):
|
|
74
|
+
self._run_failed = True
|
|
75
|
+
self._reason = text.strip()
|
|
76
|
+
elif d.get("module") == "Scheduler" and (m := JOB.search(text)):
|
|
77
|
+
if self._target is None or self._target[1] != m.group(1):
|
|
78
|
+
self._target = (ts, m.group(1))
|
|
79
|
+
if kind != "align.state" or d.get("snapshot"):
|
|
80
|
+
return []
|
|
81
|
+
state = d.get("state")
|
|
82
|
+
if state in RUNNING:
|
|
83
|
+
if not self._in_run:
|
|
84
|
+
self._in_run, self._run_failed = True, False
|
|
85
|
+
return []
|
|
86
|
+
if state in SOLVED:
|
|
87
|
+
self._in_run = False
|
|
88
|
+
self._failed_at, self._streak = None, 0
|
|
89
|
+
if self._alerted:
|
|
90
|
+
self._alerted = False
|
|
91
|
+
return [
|
|
92
|
+
make_alert(
|
|
93
|
+
ts,
|
|
94
|
+
self.session,
|
|
95
|
+
"plate_solve_ok",
|
|
96
|
+
"normal",
|
|
97
|
+
"Plate solve succeeded",
|
|
98
|
+
f"Ekos solved the frame at {hhmm(ts)}.",
|
|
99
|
+
immediate=True,
|
|
100
|
+
)
|
|
101
|
+
]
|
|
102
|
+
return []
|
|
103
|
+
if self._in_run and (state == "failed" or (state == "aborted" and self._run_failed)):
|
|
104
|
+
self._in_run = False
|
|
105
|
+
self._streak += 1
|
|
106
|
+
if self._failed_at is None:
|
|
107
|
+
self._failed_at = ts
|
|
108
|
+
elif state in ("failed", "aborted"):
|
|
109
|
+
self._in_run = False
|
|
110
|
+
return []
|
|
111
|
+
|
|
112
|
+
def on_tick(self, now: float) -> list[Event]:
|
|
113
|
+
if self._alerted or self._failed_at is None or now - self._failed_at < self.retry_grace:
|
|
114
|
+
return []
|
|
115
|
+
self._alerted = True
|
|
116
|
+
failed_at, self._failed_at = self._failed_at, None
|
|
117
|
+
return [self._alert(now, failed_at)]
|
|
118
|
+
|
|
119
|
+
def _alert(self, now: float, failed_at: float) -> Event:
|
|
120
|
+
runs = f"{self._streak} runs" if self._streak > 1 else "a run"
|
|
121
|
+
when = ""
|
|
122
|
+
if self._flip_at is not None and 0 <= failed_at - self._flip_at <= CONTEXT_WINDOW:
|
|
123
|
+
when = " after the meridian flip"
|
|
124
|
+
elif self._target is not None and 0 <= failed_at - self._target[0] <= CONTEXT_WINDOW:
|
|
125
|
+
when = f" after slewing to {self._target[1]}"
|
|
126
|
+
lines = [f"Ekos couldn't solve the frame{when} ({runs} failed since {hhmm(failed_at)})."]
|
|
127
|
+
if self._reason:
|
|
128
|
+
lines.append(f"Ekos: “{self._reason}”")
|
|
129
|
+
lines.append(
|
|
130
|
+
"Without a solve the target may be off-centre. Check for clouds, dew or focus, "
|
|
131
|
+
"and the solver settings."
|
|
132
|
+
)
|
|
133
|
+
return make_alert(
|
|
134
|
+
now, self.session, "plate_solve_failed", "high", "Plate solve failed", "\n".join(lines)
|
|
135
|
+
)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Calibration reminders (docs/design.md, "Alerts", Normal — manual steps).
|
|
2
|
+
|
|
3
|
+
- **Flats reminder** (Normal, sent with the session summary): when a session that imaged ends,
|
|
4
|
+
the filters that have lights tonight but no flats tonight. Flats taken by the sequence itself, or
|
|
5
|
+
in an earlier session of the same night, count; each filter is reminded once per night. Not when
|
|
6
|
+
the user stopped Ekos (they're at the rig), the same as the summary.
|
|
7
|
+
- **Darks reminder** (off by default; turn it on in ``messages:``): when a dark job starts (the
|
|
8
|
+
Ekos adapter reads the active job's frame type as Capture starts, ``capture.job``), a reminder
|
|
9
|
+
to cover the telescope. Once per night, session or not: darks don't start a session.
|
|
10
|
+
|
|
11
|
+
Nights are the session manager's (``night_of``: 02:00 belongs to the evening before).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from collections import defaultdict
|
|
17
|
+
from collections.abc import Iterable
|
|
18
|
+
|
|
19
|
+
from ekos_notifier.alerts import SessionRule, make_alert
|
|
20
|
+
from ekos_notifier.events import Event
|
|
21
|
+
from ekos_notifier.session import night_of
|
|
22
|
+
|
|
23
|
+
QUIET_ENDS = {"ekos_stopped"} # as for the summary: you stopped Ekos yourself
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CalibrationRule(SessionRule):
|
|
27
|
+
def __init__(self) -> None:
|
|
28
|
+
super().__init__()
|
|
29
|
+
self._lights: dict[str, set[str]] = defaultdict(set) # night -> filters with lights
|
|
30
|
+
self._flats: dict[str, set[str]] = defaultdict(set) # night -> filters with flats
|
|
31
|
+
self._reminded: dict[str, set[str]] = defaultdict(set) # night -> filters reminded
|
|
32
|
+
self._darks_reminded: set[str] = set() # nights
|
|
33
|
+
|
|
34
|
+
def resume(self, session_id: str | None, alerts: Iterable[Event] = ()) -> None:
|
|
35
|
+
super().resume(session_id, alerts)
|
|
36
|
+
for a in alerts:
|
|
37
|
+
if a.data.get("rule") == "flats_reminder":
|
|
38
|
+
self._reminded[night_of(a.ts)].update(a.data.get("filters", []))
|
|
39
|
+
elif a.data.get("rule") == "darks_reminder":
|
|
40
|
+
self._darks_reminded.add(night_of(a.ts))
|
|
41
|
+
|
|
42
|
+
def tick(self, now: float) -> list[Event]:
|
|
43
|
+
return []
|
|
44
|
+
|
|
45
|
+
def on_event(self, event: Event) -> list[Event]:
|
|
46
|
+
kind, d = event.kind, event.data
|
|
47
|
+
night = night_of(event.ts)
|
|
48
|
+
if kind == "capture.frame" and d.get("type") in ("light", "flat"):
|
|
49
|
+
table = self._lights if d["type"] == "light" else self._flats
|
|
50
|
+
table[night].add(d.get("filter") or "no filter")
|
|
51
|
+
elif kind == "session.closed" and d.get("state") == "closed":
|
|
52
|
+
if d.get("reason") not in QUIET_ENDS:
|
|
53
|
+
night = d.get("night") or night
|
|
54
|
+
missing = self._lights[night] - self._flats[night] - self._reminded[night]
|
|
55
|
+
if missing:
|
|
56
|
+
self._reminded[night] |= missing
|
|
57
|
+
return [self._flats_reminder(event, sorted(missing))]
|
|
58
|
+
elif kind == "capture.job" and d.get("frame_type") == "dark":
|
|
59
|
+
if night not in self._darks_reminded:
|
|
60
|
+
self._darks_reminded.add(night)
|
|
61
|
+
return [
|
|
62
|
+
make_alert(
|
|
63
|
+
event.ts,
|
|
64
|
+
event.session_id,
|
|
65
|
+
"darks_reminder",
|
|
66
|
+
"normal",
|
|
67
|
+
"Darks starting",
|
|
68
|
+
"Ekos is starting dark frames.\nCover the telescope (or close the dust "
|
|
69
|
+
"cap) if it isn't already.",
|
|
70
|
+
immediate=True,
|
|
71
|
+
)
|
|
72
|
+
]
|
|
73
|
+
return []
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def _flats_reminder(event: Event, filters: list[str]) -> Event:
|
|
77
|
+
which = ", ".join(filters)
|
|
78
|
+
body = (
|
|
79
|
+
f"No flats yet tonight for {which}.\n"
|
|
80
|
+
"Take them before the focus, rotation or camera changes, or tonight's lights won't "
|
|
81
|
+
"have matching flats."
|
|
82
|
+
)
|
|
83
|
+
return make_alert(
|
|
84
|
+
event.ts,
|
|
85
|
+
event.session_id,
|
|
86
|
+
"flats_reminder",
|
|
87
|
+
"normal",
|
|
88
|
+
"Flats reminder",
|
|
89
|
+
body,
|
|
90
|
+
immediate=True,
|
|
91
|
+
filters=filters,
|
|
92
|
+
)
|
ekos_notifier/capture.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Capture and Scheduler alerts (docs/design.md, "Alerts", High).
|
|
2
|
+
|
|
3
|
+
- **Capture aborted:** Capture goes ``aborted`` during a session and hasn't resumed within
|
|
4
|
+
``ABORT_GRACE`` seconds (the Scheduler may restart a job). Only when Ekos gave a reason in the
|
|
5
|
+
log just before (e.g. "Autoguiding stopped. Aborting...", "Autofocus failed. Aborting
|
|
6
|
+
exposure"), or guiding, focus or a device had just failed: an abort with no cause is taken as
|
|
7
|
+
the user's own Stop and only recorded.
|
|
8
|
+
- **Scheduler aborted:** the Scheduler goes ``aborted`` after running, with its last log lines.
|
|
9
|
+
(Pressing Stop leaves it ``idle``.)
|
|
10
|
+
- **Capture stalled:** Capture is busy (exposing, downloading, changing filter, starting a job,
|
|
11
|
+
dithering) but nothing has happened for 2 × (exposure + download), and at least
|
|
12
|
+
``STALL_MIN`` seconds. The exposure comes from Ekos's "Capturing 60.000-second …" log line, the
|
|
13
|
+
download time from its "Download Time: 0.10 s" line. States where Capture waits on something
|
|
14
|
+
else on purpose (guiding, focus, flip, temperature) don't count. A Normal "Capture running
|
|
15
|
+
again" follows when a frame arrives.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import re
|
|
21
|
+
from collections import deque
|
|
22
|
+
|
|
23
|
+
from ekos_notifier.alerts import SessionRule, hhmm, make_alert, minutes
|
|
24
|
+
from ekos_notifier.events import Event
|
|
25
|
+
|
|
26
|
+
ABORT_GRACE = 60.0
|
|
27
|
+
STALL_MIN = 120.0
|
|
28
|
+
CAUSE_WINDOW = 5.0 # seconds before an abort in which its cause shows up
|
|
29
|
+
WORKING = {"capturing", "image_received", "in_progress", "changing_filter", "dithering"}
|
|
30
|
+
RESUMED = WORKING | {"meridian_flip", "aligning", "focusing", "filter_focus", "calibrating"}
|
|
31
|
+
BUSY = RESUMED | {"suspended", "guider_drift", "pause_planned", "waiting", "setting_temperature"}
|
|
32
|
+
EXPOSURE = re.compile(r"Capturing ([\d.]+)-second")
|
|
33
|
+
DOWNLOAD = re.compile(r"Download Time: ([\d.]+) s")
|
|
34
|
+
ROUTINE = re.compile(r"Download Time|Received image|Captured |Capturing [\d.]+-second")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class CaptureRule(SessionRule):
|
|
38
|
+
def __init__(self, abort_grace: float = ABORT_GRACE, stall_min: float = STALL_MIN) -> None:
|
|
39
|
+
super().__init__()
|
|
40
|
+
self.abort_grace = abort_grace
|
|
41
|
+
self.stall_min = stall_min
|
|
42
|
+
self._log: deque[tuple[float, str, str]] = deque(maxlen=50) # (ts, module, text)
|
|
43
|
+
self._causes: deque[tuple[float, str]] = deque(maxlen=20) # (ts, cause) not from the log
|
|
44
|
+
self._capture: str | None = None
|
|
45
|
+
self._since: float | None = None # last capture progress (state change or frame)
|
|
46
|
+
self._exposure = 0.0
|
|
47
|
+
self._download = 0.0
|
|
48
|
+
self._abort: tuple[float, str] | None = None # pending (ts, reason)
|
|
49
|
+
self._stalled_at: float | None = None
|
|
50
|
+
self._scheduler_ran = False
|
|
51
|
+
|
|
52
|
+
def on_session_closed(self) -> None:
|
|
53
|
+
self._abort = None
|
|
54
|
+
self._stalled_at = None
|
|
55
|
+
|
|
56
|
+
# -- events ------------------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
def on_event(self, event: Event) -> list[Event]:
|
|
59
|
+
kind, d = event.kind, event.data
|
|
60
|
+
state = d.get("state")
|
|
61
|
+
out: list[Event] = []
|
|
62
|
+
if kind == "ekos.log" and d.get("text"):
|
|
63
|
+
text = str(d["text"])
|
|
64
|
+
self._log.append((event.ts, str(d.get("module", "")), text))
|
|
65
|
+
if m := EXPOSURE.search(text):
|
|
66
|
+
self._exposure = float(m.group(1))
|
|
67
|
+
if m := DOWNLOAD.search(text):
|
|
68
|
+
self._download = float(m.group(1))
|
|
69
|
+
elif kind == "guide.state" and state in ("aborted", "calibration_error", "disconnected"):
|
|
70
|
+
self._causes.append((event.ts, "guiding stopped"))
|
|
71
|
+
elif kind == "focus.state" and state == "failed":
|
|
72
|
+
self._causes.append((event.ts, "autofocus failed"))
|
|
73
|
+
elif kind == "kstars.vanished" or (
|
|
74
|
+
kind in ("ekos.state", "indi.state") and state in ("idle", "error")
|
|
75
|
+
):
|
|
76
|
+
self._capture = None # its last state is stale now; the Emergency rule takes over
|
|
77
|
+
self._abort = None
|
|
78
|
+
elif kind == "device.disconnected":
|
|
79
|
+
self._causes.append((event.ts, "a device disconnected"))
|
|
80
|
+
elif kind == "capture.frame":
|
|
81
|
+
self._since = event.ts
|
|
82
|
+
if d.get("exposure"):
|
|
83
|
+
self._exposure = float(d["exposure"])
|
|
84
|
+
out += self._unstalled(event.ts)
|
|
85
|
+
elif kind == "capture.state" and not d.get("snapshot"):
|
|
86
|
+
was, self._capture, self._since = self._capture, state, event.ts
|
|
87
|
+
# Only an abort of a capture that was running: a failed focus exposure makes Ekos
|
|
88
|
+
# report Capture "aborted" even when it was idle (seen live).
|
|
89
|
+
if state == "aborted" and self.session and was in BUSY:
|
|
90
|
+
self._abort = (event.ts, self._reason(event.ts))
|
|
91
|
+
elif state in RESUMED:
|
|
92
|
+
self._abort = None
|
|
93
|
+
elif kind == "scheduler.state":
|
|
94
|
+
if state == "running":
|
|
95
|
+
self._scheduler_ran = True
|
|
96
|
+
elif state == "aborted" and self._scheduler_ran and not d.get("snapshot"):
|
|
97
|
+
self._scheduler_ran = False
|
|
98
|
+
if self.session:
|
|
99
|
+
out.append(self._scheduler_alert(event.ts))
|
|
100
|
+
elif state == "idle":
|
|
101
|
+
self._scheduler_ran = False
|
|
102
|
+
return out
|
|
103
|
+
|
|
104
|
+
def on_tick(self, now: float) -> list[Event]:
|
|
105
|
+
out: list[Event] = []
|
|
106
|
+
if self._abort is not None and now - self._abort[0] >= self.abort_grace:
|
|
107
|
+
(ts, reason), self._abort = self._abort, None
|
|
108
|
+
if reason:
|
|
109
|
+
out.append(self._abort_alert(now, ts, reason))
|
|
110
|
+
if (
|
|
111
|
+
self._stalled_at is None
|
|
112
|
+
and self._capture in WORKING
|
|
113
|
+
and self._since is not None
|
|
114
|
+
and now - self._since >= self._stall_limit()
|
|
115
|
+
):
|
|
116
|
+
self._stalled_at = self._since
|
|
117
|
+
out.append(self._stall_alert(now))
|
|
118
|
+
return out
|
|
119
|
+
|
|
120
|
+
# -- helpers -------------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
def _stall_limit(self) -> float:
|
|
123
|
+
expected = self._exposure if self._capture == "capturing" else 0.0
|
|
124
|
+
return max(self.stall_min, 2 * (expected + self._download))
|
|
125
|
+
|
|
126
|
+
def _reason(self, ts: float) -> str:
|
|
127
|
+
"""Why Capture aborted, from what happened in the seconds before; "" if nothing."""
|
|
128
|
+
recent = [
|
|
129
|
+
text
|
|
130
|
+
for t, module, text in self._log
|
|
131
|
+
if ts - t <= CAUSE_WINDOW and module == "Capture" and "abort" in text.lower()
|
|
132
|
+
]
|
|
133
|
+
if recent:
|
|
134
|
+
text = re.sub(r"^\[[^\]]*\]\s*", "", recent[-1]) # drop "[CCD Simulator] "
|
|
135
|
+
return re.sub(r"\s*Aborting( exposure)?\.*$", "", text, flags=re.I).strip() or text
|
|
136
|
+
causes = [c for t, c in self._causes if ts - t <= CAUSE_WINDOW]
|
|
137
|
+
return causes[-1] if causes else ""
|
|
138
|
+
|
|
139
|
+
def _abort_alert(self, now: float, ts: float, reason: str) -> Event:
|
|
140
|
+
body = (
|
|
141
|
+
f"Capture aborted at {hhmm(ts)} and hasn't restarted.\n"
|
|
142
|
+
f"Ekos: {reason.rstrip('.')}.\n"
|
|
143
|
+
"The sequence is stopped: nothing is being captured."
|
|
144
|
+
)
|
|
145
|
+
return make_alert(now, self.session, "capture_aborted", "high", "Capture aborted", body)
|
|
146
|
+
|
|
147
|
+
def _scheduler_alert(self, ts: float) -> Event:
|
|
148
|
+
lines = [f"The Scheduler aborted at {hhmm(ts)}."]
|
|
149
|
+
recent = [text for t, module, text in self._log if module == "Scheduler" and ts - t <= 60]
|
|
150
|
+
if recent:
|
|
151
|
+
lines.append("Scheduler: " + recent[-1])
|
|
152
|
+
lines.append("No more jobs will run tonight unless you restart it.")
|
|
153
|
+
return make_alert(
|
|
154
|
+
ts, self.session, "scheduler_aborted", "high", "Scheduler aborted", "\n".join(lines)
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
def _stall_alert(self, now: float) -> Event:
|
|
158
|
+
assert self._since is not None
|
|
159
|
+
what = (self._capture or "busy").replace("_", " ")
|
|
160
|
+
if self._capture == "capturing" and self._exposure:
|
|
161
|
+
what = f"capturing a {self._exposure:g} s exposure"
|
|
162
|
+
body = (
|
|
163
|
+
f"No progress from Capture since {hhmm(self._since)} ({minutes(now - self._since)}): "
|
|
164
|
+
f"it's still {what}.\n"
|
|
165
|
+
"Check the camera, its connection and the filter wheel."
|
|
166
|
+
)
|
|
167
|
+
return make_alert(now, self.session, "capture_stalled", "high", "Capture stalled", body)
|
|
168
|
+
|
|
169
|
+
def _unstalled(self, ts: float) -> list[Event]:
|
|
170
|
+
if self._stalled_at is None:
|
|
171
|
+
return []
|
|
172
|
+
since, self._stalled_at = self._stalled_at, None
|
|
173
|
+
if not self.session:
|
|
174
|
+
return []
|
|
175
|
+
body = f"A new frame arrived at {hhmm(ts)}, {minutes(ts - since)} after Capture stalled."
|
|
176
|
+
return [
|
|
177
|
+
make_alert(
|
|
178
|
+
ts,
|
|
179
|
+
self.session,
|
|
180
|
+
"capture_running",
|
|
181
|
+
"normal",
|
|
182
|
+
"Capture running again",
|
|
183
|
+
body,
|
|
184
|
+
immediate=True,
|
|
185
|
+
)
|
|
186
|
+
]
|