openc3-cosmos-constellation 0.8.3 → 0.8.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad3cbfc7648b177285a954c17e4c592c254862d2c0e79f128526b4dad52957f9
4
- data.tar.gz: ff7be196ea8274ab1b35dc13194dab2b1d34b80f72bea88b8c3a24208d7c0869
3
+ metadata.gz: 53b51a98ca67f44b6357a6a33df8571bc2f48b032ed3c6133840f9c7b7a534ca
4
+ data.tar.gz: 5a98a9243f1f4379ccc6e998b7d5622fa5efbea3b08a9096cc5e63af86425453
5
5
  SHA512:
6
- metadata.gz: afefedd0cefea489de19b2ee79118567b602cea73dbc52ad47b26934cb9624950af4cc2915015bfb87d8ab1e86d7f5c0d7861f6b768e5693a39e8e13a9968149
7
- data.tar.gz: 6c4e10555ffa3ff8127ccae734e5ca63c10e7a920c5816cf557490c2ae54d2f5576fce8ee5d0143aa3b7dd894198b25253f0c1f595cd3aa159976892bbaef687
6
+ metadata.gz: 3aa955fc123b67ee2bdbe48f734eeab548fc7084079ca3c88dda63ae0fdf9f3b2a6c4960dcf58c3e42514c34d07c801ca203f1070c0de8542573c5cd7ed852ea
7
+ data.tar.gz: 51a24b7d342d1519b342b3cd1b434ddad8e8728e42a920f3ae9e0c130c716c1d9089acb1e5b8a8398360fb3299ec6d790353d68e5117974d45c3d546f6aed990
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- # Builds openc3-cosmos-constellation-<VERSION>.gem: rake build VERSION=0.8.3
2
- # (or ./openc3.sh cli rake build VERSION=0.8.3 inside a COSMOS checkout).
1
+ # Builds openc3-cosmos-constellation-<VERSION>.gem: rake build VERSION=0.8.5
2
+ # (or ./openc3.sh cli rake build VERSION=0.8.5 inside a COSMOS checkout).
3
3
  PLUGIN_NAME = Dir['*.gemspec'][0].split('.')[0..-2].join('.')
4
4
 
5
5
  # The tool draws the shared Constellation Forecast view, copied in from this repo when it is here.
@@ -13,7 +13,7 @@ SHARED_RESULTS = '../../clients/python/src/constellation_space/results.py'
13
13
  SHARED_LICENSE = '../../LICENSE'
14
14
 
15
15
  task :build do
16
- abort('VERSION is required: rake build VERSION=0.8.3') unless ENV['VERSION']
16
+ abort('VERSION is required: rake build VERSION=0.8.5') unless ENV['VERSION']
17
17
  FileUtils.cp(SHARED_VIEW, VIEW) if File.exist?(SHARED_VIEW)
18
18
  abort("#{VIEW} is missing: copy bridges/shared/forecast-view.js there") unless File.exist?(VIEW)
19
19
  if File.exist?(SHARED_RESULTS)
@@ -8,7 +8,8 @@ target's packets (targets/CONSTELLATION/cmd_tlm/tlm.txt):
8
8
 
9
9
  NEXT_PASS the next predicted pass and its expected GB (p10/p50/p90)
10
10
  NEXT_24H passes and expected GB over the next 24 hours
11
- SWAP the soonest rain-fade swap to decide, with minutes left (limits go yellow, then red)
11
+ SWAP the soonest rain-fade swap to decide, as advice (add a backup pass or move to it),
12
+ its backup's AOS, LOS and GB, the gain, and minutes left (limits go yellow, then red)
12
13
  CAPACITY one day's capacity across the antennas, and the tightest
13
14
  MODCOD the next pass's MODCOD plan
14
15
  RUN the latest workflow run received, of any kind
@@ -38,7 +39,7 @@ from typing import Any
38
39
 
39
40
  from constellation_space import results
40
41
 
41
- VERSION = "0.8.3"
42
+ VERSION = "0.8.5"
42
43
  TARGET = "CONSTELLATION"
43
44
  POLL_S = int(os.environ.get("POLL_SECONDS", "15"))
44
45
  # COSMOS shows a packet stale 30 s after its last value: re-inject every poll so a quiet feed
@@ -70,6 +71,8 @@ STRING_BYTES = {
70
71
  "LOS": 32,
71
72
  "BACKUP_ANTENNA": 64,
72
73
  "BACKUP_AOS": 32,
74
+ "BACKUP_LOS": 32,
75
+ "ADVICE": 256,
73
76
  "DEADLINE": 32,
74
77
  "STATUS": 16,
75
78
  "DAY": 16,
@@ -188,6 +191,11 @@ def _minute(iso: str | None) -> str:
188
191
  return f"{iso[:16].replace('T', ' ')}Z" if iso else ""
189
192
 
190
193
 
194
+ def _number(value: Any) -> float:
195
+ """A number for a FLOAT item; 0 for none, as the item cannot be empty."""
196
+ return float(value) if isinstance(value, int | float) and not isinstance(value, bool) else 0.0
197
+
198
+
191
199
 
192
200
 
193
201
 
@@ -223,7 +231,7 @@ def swap_items(items: list[dict[str, Any]]) -> list[dict[str, Any]]:
223
231
 
224
232
 
225
233
  def held_until(item: dict[str, Any]) -> str:
226
- """When a held action can no longer be approved, as the API's expires_at() has it: its cancel
234
+ """When a held action can no longer be approved, as the API's expires_at() has it: its decide-by
227
235
  deadline, else when its pass starts, or a link's span ends. The API sends a held item without
228
236
  its action, so mostly the latter."""
229
237
  end = item["until"] if (item.get("entity") or {}).get("type") == "link" else item["target_at"]
@@ -280,6 +288,10 @@ NO_SWAP: dict[str, Any] = {
280
288
  "STATUS": "NONE",
281
289
  "APPROVED": 0,
282
290
  "PENDING": 0,
291
+ "ADVICE": "NONE",
292
+ "BACKUP_LOS": "",
293
+ "BACKUP_GB": 0.0,
294
+ "GAIN_GB": 0.0,
283
295
  }
284
296
 
285
297
 
@@ -404,6 +416,10 @@ def packets(
404
416
  "STATUS": "APPROVED" if results.action_state(swap) == "approved" else "ADVISED",
405
417
  "APPROVED": sum(results.action_state(s) == "approved" for s in open_swaps),
406
418
  "PENDING": pending,
419
+ "ADVICE": results.advice(swap),
420
+ "BACKUP_LOS": _minute(action.get("to_until")),
421
+ "BACKUP_GB": _number(action.get("to_gb")),
422
+ "GAIN_GB": _number(action.get("gain_gb")),
407
423
  }
408
424
  return out
409
425
 
@@ -507,9 +523,12 @@ def check_in(consumer: str) -> bool:
507
523
  return True
508
524
 
509
525
 
510
- def report(consumer: str, cursor: str, applied: dict[str, int]) -> None:
526
+ def report(
527
+ consumer: str, cursor: str, applied: dict[str, int], outcomes: list[dict[str, str]]
528
+ ) -> None:
511
529
  try:
512
- results.report(call, consumer, cursor, applied, f"OpenC3 COSMOS target {TARGET}")
530
+ target = f"OpenC3 COSMOS target {TARGET}"
531
+ results.report(call, consumer, cursor, applied, target, outcomes, log)
513
532
  except Exception as exc:
514
533
  log(f"could not report ({exc})", warn=True)
515
534
 
@@ -629,6 +648,7 @@ def main() -> None:
629
648
  keep(consumer, cursor, forecast)
630
649
  continue
631
650
  applied = {"parameters": 0, "forecasts": 0}
651
+ outcomes: list[dict[str, str]] = []
632
652
  for resource, items in parts:
633
653
  system = resource.get("constellation.system")
634
654
  if system != "cosmos":
@@ -645,8 +665,11 @@ def main() -> None:
645
665
  applied["malformed"] = applied.get("malformed", 0) + bad
646
666
  items = good
647
667
  applied["forecasts"] += forecast.take(resource, items)
648
- # Approved swaps it shows as instructions: the platform shows them carried out.
649
- if acted := results.first_acted(swap_items(items), forecast.acted):
668
+ # Approved swaps it shows as approved advice: the platform shows them acted on.
669
+ shown = f"shown in the {TARGET} SWAP packet"
670
+ if acted := results.first_acted(
671
+ swap_items(items), forecast.acted, outcomes, shown
672
+ ):
650
673
  applied["acted"] = applied.get("acted", 0) + acted
651
674
  widget = output_of(resource).get("widget") or {}
652
675
  if widget.get("on"):
@@ -656,7 +679,7 @@ def main() -> None:
656
679
  refreshed = time.time()
657
680
  # Only a run applied moves the cursor: one that failed part-way is retried.
658
681
  cursor = entry["cursor"]
659
- report(consumer, cursor, applied)
682
+ report(consumer, cursor, applied, outcomes)
660
683
  keep(consumer, cursor, forecast)
661
684
  log(f"injected {applied['parameters']} packets, {cursor}")
662
685
  if page["entries"]:
@@ -104,7 +104,7 @@ def http(
104
104
 
105
105
  def action_state(item: dict[str, Any]) -> str | None:
106
106
  """What an item's action is to a bridge. "advice": suggested, never an instruction.
107
- "approved": a person approved it in Constellation, an instruction to carry out. "pending":
107
+ "approved": a person approved it in Constellation, advice to carry out. "pending":
108
108
  held for approval; the action itself is not sent, only action_status. "rejected": decided
109
109
  against; the original stands. None: the item has no action. Any status other than approved
110
110
  or rejected counts as held, so an item a bridge cannot read is never taken for a plain
@@ -152,7 +152,7 @@ def parse_time(value: Any) -> datetime | None:
152
152
 
153
153
  def acted_until(item: dict[str, Any]) -> str:
154
154
  """When an acted key may be forgotten: the latest of the item's time, its end (a pass's end),
155
- its action's cancel deadline and now, plus KEEP_ACTED, so a key is never dropped as soon as it
155
+ its action's deadline and now, plus KEEP_ACTED, so a key is never dropped as soon as it
156
156
  is written. "" (kept for good) when none of the item's is a time."""
157
157
  action = item.get("action") or {}
158
158
  times = [
@@ -164,21 +164,110 @@ def acted_until(item: dict[str, Any]) -> str:
164
164
  return (max(*known, now()) + KEEP_ACTED).astimezone(timezone.utc).isoformat(timespec="seconds")
165
165
 
166
166
 
167
- def first_acted(items: list[dict[str, Any]], acted: dict[str, str]) -> int:
168
- """How many of these items are approved actions still open (before their cancel deadline)
169
- carried out for the first time. A bridge that enforces or shows approvals on every run, rather
170
- than acting once, counts each decision (action_key) once: `acted` maps each counted to when
171
- it may be forgotten (acted_until), kept in the bridge's state, and loses keys long over."""
167
+ def first_acted(
168
+ items: list[dict[str, Any]],
169
+ acted: dict[str, str],
170
+ outcomes: list[dict[str, str]] | None = None,
171
+ how: str = "",
172
+ ) -> int:
173
+ """How many of these items are approved actions still open (before their deadline) carried
174
+ out for the first time. A bridge that enforces or shows approvals on every run, rather than
175
+ acting once, counts each decision (action_key) once: `acted` maps each counted to when it may
176
+ be forgotten (acted_until), kept in the bridge's state, and loses keys long over. Each one
177
+ counted goes in `outcomes` as acted (`how` says how), and an approval first seen past its
178
+ deadline as refused, each once (outcome())."""
172
179
  _drop_over(acted)
173
180
  first = 0
174
181
  for item in items:
175
182
  key = action_key(item)
176
- if action_state(item) == "approved" and not past_deadline(item) and key not in acted:
177
- acted[key] = acted_until(item)
183
+ if action_state(item) != "approved" or key in acted:
184
+ continue
185
+ acted[key] = acted_until(item)
186
+ if past_deadline(item):
187
+ said = outcome(item, "refused", too_late(item))
188
+ else:
178
189
  first += 1
190
+ said = outcome(item, "acted", how)
191
+ if outcomes is not None and said:
192
+ outcomes.append(said)
179
193
  return first
180
194
 
181
195
 
196
+ def outcome(item: dict[str, Any], result: str, reason: str = "") -> dict[str, str] | None:
197
+ """What mission control did with an approved action, for the delivery report's `actions`:
198
+ acted or refused, and why. None for an item that does not name its action and decision (an
199
+ API from before outcomes): the API could not match it."""
200
+ if not (item.get("action_id") and item.get("decision_id")):
201
+ return None
202
+ return {
203
+ "action_id": str(item["action_id"]),
204
+ "decision_id": str(item["decision_id"]),
205
+ "outcome": result,
206
+ "reason": reason[:500],
207
+ }
208
+
209
+
210
+ def too_late(item: dict[str, Any]) -> str:
211
+ """Why an approval past its deadline was refused."""
212
+ return f"it arrived after its decide-by time, {minute((item.get('action') or {}).get('deadline'))}"
213
+
214
+
215
+ def minute(value: Any) -> str:
216
+ """An ISO time to the minute, as the texts write it: 2026-11-05 09:45Z."""
217
+ at = parse_time(value) if value else None
218
+ return at.astimezone(timezone.utc).strftime("%Y-%m-%d %H:%MZ") if at else ""
219
+
220
+
221
+ # Why a swap advises its action (the action's `reason`), as a person reads it.
222
+ REASONS = {
223
+ "adds_capacity": "it adds capacity",
224
+ "overlap": "both passes use one radio at once",
225
+ "paid_booking": "releasing the paid booking in time is worth it",
226
+ "original_empty": "this pass delivers about nothing in the rain",
227
+ }
228
+
229
+
230
+ def _gb_text(value: Any) -> str | None:
231
+ return f"{value:.1f} GB" if isinstance(value, int | float) and not isinstance(value, bool) else None
232
+
233
+
234
+ def advice(item: dict[str, Any]) -> str:
235
+ """A swap as the advice it is, never a command: add a backup pass (and keep this one) or move
236
+ to the backup, its time and GB, the gain over doing nothing (gain_gb), why, and when to
237
+ decide by. The customer's contact plan is theirs; Constellation books and cancels nothing."""
238
+ action = item.get("action") or {}
239
+ if not action.get("to_antenna_id"):
240
+ return "No backup pass in the window"
241
+ move = action.get("action") == "move"
242
+ text = f"{'Move to the backup' if move else 'Add a backup pass'} on {action['to_antenna_id']}"
243
+ if at := minute(action.get("to_at")):
244
+ text += f" at {at}"
245
+ if until := minute(action.get("to_until")):
246
+ text += f" to {until[-6:]}"
247
+ if gb := _gb_text(action.get("to_gb")):
248
+ text += f" ({gb})"
249
+ text += " instead of this one" if move else " and keep this one"
250
+ if gain := _gb_text(action.get("gain_gb")):
251
+ text += f", +{gain}"
252
+ if why := REASONS.get(action.get("reason") or ""):
253
+ text += f": {why}"
254
+ if deadline := minute(action.get("deadline")):
255
+ text += f"; decide by {deadline}"
256
+ return text
257
+
258
+
259
+ def loss(item: dict[str, Any]) -> str:
260
+ """What rain costs the pass, as a person reads it: the note's own sentence ("Rain costs 60%
261
+ of its dry 0.6 GB"), which only the API can say as it alone knows the dry yield, else the GB
262
+ the pass is expected to carry in the rain (p50). Never a p10, which equals the p50 in a
263
+ forecast with no spread."""
264
+ note = item.get("note") or ""
265
+ if note.startswith("Rain costs"):
266
+ return note.split(". ", 1)[0]
267
+ gb = expected_gb(item)
268
+ return f"{gb['p50']:.1f} GB expected in the rain" if gb else ""
269
+
270
+
182
271
  def _drop_over(keys: dict[str, str]) -> bool:
183
272
  """Drops the keys whose time to be forgotten has passed; whether any was."""
184
273
  cutoff = now()
@@ -189,7 +278,7 @@ def _drop_over(keys: dict[str, str]) -> bool:
189
278
 
190
279
 
191
280
  def past_deadline(item: dict[str, Any]) -> bool:
192
- """Whether the item's action is past its cancel deadline: closed, never to be carried out."""
281
+ """Whether the item's action is past its deadline (decide-by): closed, never to be carried out."""
193
282
  deadline = parse_time((item.get("action") or {}).get("deadline"))
194
283
  return deadline is not None and deadline <= now()
195
284
 
@@ -449,22 +538,44 @@ def start_cursor(call: Callable[..., Any], consumer: str) -> str:
449
538
  return page["next"]
450
539
 
451
540
 
541
+ # The most action outcomes the API takes in one delivery report.
542
+ MAX_OUTCOMES = 200
543
+
544
+
452
545
  def report(
453
- call: Callable[..., Any], consumer: str, cursor: str, applied: dict[str, int], target: str
546
+ call: Callable[..., Any],
547
+ consumer: str,
548
+ cursor: str,
549
+ applied: dict[str, int],
550
+ target: str,
551
+ actions: list[dict[str, str]] | None = None,
552
+ log: Callable[[str], None] = print,
454
553
  ) -> None:
455
- """Tells Constellation what the run at `cursor` became in the system, shown in Constellation;
456
- raises when Constellation does not take it."""
457
- call(
458
- "POST",
459
- "/predictions/feed/deliveries",
460
- {
461
- "consumer": consumer,
462
- "run_id": cursor.split("#", 1)[1],
463
- "cursor": cursor,
464
- "applied": applied,
465
- "target": target,
466
- },
467
- )
554
+ """Tells Constellation what the run at `cursor` became in the system, shown in Constellation,
555
+ and what became of each approved action in it (`actions`, outcome()); raises when
556
+ Constellation does not take it. An API from before outcomes refuses `actions` (422), and one
557
+ whose decision has moved on refuses the whole report (409 unknown_decision): either way the
558
+ report is sent again without them, so the delivery is still recorded."""
559
+ body = {
560
+ "consumer": consumer,
561
+ "run_id": cursor.split("#", 1)[1],
562
+ "cursor": cursor,
563
+ "applied": applied,
564
+ "target": target,
565
+ }
566
+ if not actions:
567
+ call("POST", "/predictions/feed/deliveries", body)
568
+ return
569
+ try:
570
+ call("POST", "/predictions/feed/deliveries", {**body, "actions": actions[:MAX_OUTCOMES]})
571
+ except Exception as exc:
572
+ if getattr(exc, "code", None) not in (409, 422):
573
+ raise
574
+ log(
575
+ f"Constellation did not take the outcomes of {len(actions)} approved action(s) of"
576
+ f" {cursor} (HTTP {exc.code}); reported the delivery without them"
577
+ )
578
+ call("POST", "/predictions/feed/deliveries", body)
468
579
 
469
580
 
470
581
  def kind(items: list[dict[str, Any]]) -> str:
@@ -34,22 +34,30 @@ TELEMETRY CONSTELLATION SWAP BIG_ENDIAN "Forecast: the soonest open rain-fade sw
34
34
  APPEND_ITEM SATELLITE 512 STRING "Satellite id"
35
35
  APPEND_ITEM ANTENNA 512 STRING "Antenna at risk"
36
36
  APPEND_ITEM AOS 256 STRING "Predicted AOS of the pass at risk, UTC"
37
- APPEND_ITEM KEEPS_GB_P10 32 FLOAT "GB the pass keeps if it rains (p10)"
37
+ APPEND_ITEM KEEPS_GB_P10 32 FLOAT "Deprecated: the p10, equal to EXPECTED_GB_P50 in a forecast with no spread. Read EXPECTED_GB_P50"
38
38
  UNITS Gigabytes GB
39
39
  FORMAT_STRING "%.3f"
40
- APPEND_ITEM EXPECTED_GB_P50 32 FLOAT "GB the pass delivers dry (p50)"
40
+ APPEND_ITEM EXPECTED_GB_P50 32 FLOAT "GB the pass is expected to carry in the rain (p50)"
41
41
  UNITS Gigabytes GB
42
42
  FORMAT_STRING "%.3f"
43
- APPEND_ITEM BACKUP_ANTENNA 512 STRING "Antenna to book instead, or NONE"
43
+ APPEND_ITEM BACKUP_ANTENNA 512 STRING "Antenna of the backup pass advised, or NONE"
44
44
  APPEND_ITEM BACKUP_AOS 256 STRING "Backup pass AOS, UTC"
45
- APPEND_ITEM DEADLINE 256 STRING "Cancel the original by, UTC"
45
+ APPEND_ITEM DEADLINE 256 STRING "Decide by, UTC"
46
46
  APPEND_ITEM MINUTES_TO_DEADLINE 32 FLOAT "Minutes left to decide: yellow at 30 or less, red at 15 or less (99999 when no swap is open)"
47
47
  UNITS Minutes min
48
48
  FORMAT_STRING "%.1f"
49
49
  LIMITS DEFAULT 1 ENABLED 15 30 100000 100000
50
- APPEND_ITEM STATUS 128 STRING "The swap shown: ADVISED, APPROVED (approved in Constellation: carry it out) or NONE"
50
+ APPEND_ITEM STATUS 128 STRING "The swap shown: ADVISED, APPROVED (advice approved in Constellation) or NONE"
51
51
  APPEND_ITEM APPROVED 32 UINT "Open swaps approved in Constellation"
52
52
  APPEND_ITEM PENDING 32 UINT "Swaps held for approval in Constellation, deadline ahead"
53
+ APPEND_ITEM ADVICE 2048 STRING "The advice in words: add a backup pass (keep this one) or move to the backup, its gain and why"
54
+ APPEND_ITEM BACKUP_LOS 256 STRING "Backup pass LOS, UTC"
55
+ APPEND_ITEM BACKUP_GB 32 FLOAT "GB the backup pass is expected to carry (p50)"
56
+ UNITS Gigabytes GB
57
+ FORMAT_STRING "%.3f"
58
+ APPEND_ITEM GAIN_GB 32 FLOAT "GB the advice adds over doing nothing (p50)"
59
+ UNITS Gigabytes GB
60
+ FORMAT_STRING "%.3f"
53
61
 
54
62
  TELEMETRY CONSTELLATION CAPACITY BIG_ENDIAN "Forecast: one day's capacity across the antennas, and the tightest"
55
63
  ALLOW_SHORT
@@ -34,11 +34,14 @@ HORIZONTAL
34
34
  LABELVALUEDESC CONSTELLATION SWAP SATELLITE "Satellite" CONVERTED 16
35
35
  LABELVALUEDESC CONSTELLATION SWAP ANTENNA "Antenna" CONVERTED 16
36
36
  LABELVALUEDESC CONSTELLATION SWAP AOS "AOS" CONVERTED 16
37
- LABELVALUEDESC CONSTELLATION SWAP DEADLINE "Cancel by" CONVERTED 16
37
+ LABELVALUEDESC CONSTELLATION SWAP DEADLINE "Decide by" CONVERTED 16
38
+ LABELVALUEDESC CONSTELLATION SWAP EXPECTED_GB_P50 "GB expected" WITH_UNITS 16
39
+ LABELVALUEDESC CONSTELLATION SWAP ADVICE "Advice" CONVERTED 16
38
40
  LABELVALUEDESC CONSTELLATION SWAP BACKUP_ANTENNA "Backup" CONVERTED 16
39
41
  LABELVALUEDESC CONSTELLATION SWAP BACKUP_AOS "Backup AOS" CONVERTED 16
40
- LABELVALUEDESC CONSTELLATION SWAP KEEPS_GB_P10 "If rain" WITH_UNITS 16
41
- LABELVALUEDESC CONSTELLATION SWAP EXPECTED_GB_P50 "GB if dry" WITH_UNITS 16
42
+ LABELVALUEDESC CONSTELLATION SWAP BACKUP_LOS "Backup LOS" CONVERTED 16
43
+ LABELVALUEDESC CONSTELLATION SWAP BACKUP_GB "Backup GB" WITH_UNITS 16
44
+ LABELVALUEDESC CONSTELLATION SWAP GAIN_GB "Gain" WITH_UNITS 16
42
45
  LABELVALUEDESC CONSTELLATION SWAP APPROVED "Approved" CONVERTED 16
43
46
  LABELVALUEDESC CONSTELLATION SWAP PENDING "Pending" CONVERTED 16
44
47
  END
@@ -173,7 +173,7 @@ function dumbbell(rows, { unit = 'GB' } = {}) {
173
173
  const h = pad.t + rows.length * rowH;
174
174
  const max = Math.max(...rows.map((r) => r.b), 0.001);
175
175
  const x = (v) => pad.l + (v / max) * (W - pad.l - pad.r);
176
- return `<svg class="cf-chart" viewBox="0 0 ${W} ${h}" role="img" aria-label="p10 against p50 per pass">${rows
176
+ return `<svg class="cf-chart" viewBox="0 0 ${W} ${h}" role="img" aria-label="GB per pass, without and with the advice">${rows
177
177
  .map((r, i) => {
178
178
  const y = pad.t + i * rowH + rowH / 2;
179
179
  return `<g ${tip(r.tip)}><text class="cf-label" x="${pad.l - 8}" y="${y + 4}" text-anchor="end">${esc(r.label)}</text><line class="cf-whisker" x1="${x(r.a)}" x2="${x(r.b)}" y1="${y}" y2="${y}"/><circle class="cf-dot-warn" cx="${x(r.a)}" cy="${y}" r="5"/><circle class="cf-dot" cx="${x(r.b)}" cy="${y}" r="5"/></g>`;
@@ -254,7 +254,7 @@ const tile = (label, value, hint) => `<div class="cf-tile"><div class="cf-tile-v
254
254
  const section = (title, body, note) => `<section class="cf-section"><h3>${esc(title)}</h3>${note ? `<p class="cf-note">${esc(note)}</p>` : ''}${body}</section>`;
255
255
 
256
256
  /** What an item's action is, as the bridges read it (constellation_space.results.action_state):
257
- * 'advice' (suggested), 'approved' (approved in Constellation: an instruction), 'pending' (held
257
+ * 'advice' (suggested), 'approved' (approved in Constellation: advice to act on), 'pending' (held
258
258
  * for approval; its action is not sent), 'rejected', or null with no action. A status the view
259
259
  * does not know is held, never a plain forecast. */
260
260
  export function actionState(item) {
@@ -267,6 +267,38 @@ export function actionState(item) {
267
267
  /** A swap to show: advice, or approved in Constellation; never one held or rejected. */
268
268
  const actionable = (i) => actionState(i) === 'advice' || actionState(i) === 'approved';
269
269
 
270
+ // Why a swap advises its action (the action's reason), as constellation_space.results.REASONS.
271
+ const REASONS = {
272
+ adds_capacity: 'it adds capacity',
273
+ overlap: 'both passes use one radio at once',
274
+ paid_booking: 'releasing the paid booking in time is worth it',
275
+ original_empty: 'this pass delivers about nothing in the rain',
276
+ };
277
+
278
+ /** A swap as the advice it is, as constellation_space.results.advice words it: add a backup
279
+ * pass (keep this one) or move to the backup, its time and GB, the gain (gain_gb), and why.
280
+ * Never a cancel: Constellation books and cancels nothing. */
281
+ export function advice(item) {
282
+ const a = item.action || {};
283
+ if (!a.to_antenna_id) return 'No backup pass in the window';
284
+ const move = a.action === 'move';
285
+ let text = `${move ? 'Move to the backup' : 'Add a backup pass'} on ${shortAntenna(a.to_antenna_id)}`;
286
+ if (a.to_at) text += ` at ${a.to_at.slice(0, 16).replace('T', ' ')}Z${a.to_until ? ` to ${a.to_until.slice(11, 16)}Z` : ''}`;
287
+ if (typeof a.to_gb === 'number') text += ` (${a.to_gb.toFixed(1)} GB)`;
288
+ text += move ? ' instead of this one' : ' and keep this one';
289
+ if (typeof a.gain_gb === 'number') text += `, +${a.gain_gb.toFixed(1)} GB`;
290
+ if (REASONS[a.reason]) text += `: ${REASONS[a.reason]}`;
291
+ return text;
292
+ }
293
+
294
+ /** What rain costs a pass, as constellation_space.results.loss says it: the note's own sentence,
295
+ * else the GB expected in the rain (p50), never a p10 that equals it. */
296
+ export function loss(item) {
297
+ const note = item.note || '';
298
+ if (note.startsWith('Rain costs')) return note.split('. ')[0];
299
+ return `${num(gbOf(item)?.p50)} GB expected in the rain`;
300
+ }
301
+
270
302
  // A probability or share column reads as a percent, as the lock-loss risk does.
271
303
  const SHARES = ['probability', 'share'];
272
304
  // rfi-watch items are links whose value is RFI in dB (p10/p50/p90) with a lock-loss risk (a
@@ -343,11 +375,11 @@ export const VIEWS = {
343
375
  const swaps = items.filter(actionable).sort((a, b) => a.action.deadline.localeCompare(b.action.deadline));
344
376
  const approved = swaps.filter((i) => actionState(i) === 'approved').length;
345
377
  const held = items.filter((i) => actionState(i) === 'pending').length;
346
- const atRisk = swaps.reduce((s, i) => s + (gbOf(i).p50 - gbOf(i).p10), 0);
378
+ const gain = swaps.reduce((s, i) => s + (typeof i.action.gain_gb === 'number' ? i.action.gain_gb : 0), 0);
347
379
  const soonest = swaps.find((i) => Date.parse(i.action.deadline) > Date.now());
348
380
  const booked = swaps.filter((i) => i.action.to).length;
349
381
  const hint = approved || held ? `${approved} approved · ${held} awaiting approval` : `${booked} with a better backup`;
350
- return `<div class="cf-tiles">${tile('swaps to decide', swaps.length - approved, hint)}${tile('GB at risk if it rains', big(atRisk), 'p50 minus p10, summed')}${tile('soonest decision', soonest ? until(soonest.action.deadline) : '—', soonest ? `cancel by ${minute(soonest.action.deadline)}` : '')}${tile('workflow version', `v${run.workflow_version}`)}</div>`;
382
+ return `<div class="cf-tiles">${tile('swaps to decide', swaps.length - approved, hint)}${tile('GB the advice adds', big(gain), 'over doing nothing (p50), summed')}${tile('soonest decision', soonest ? until(soonest.action.deadline) : '—', soonest ? `decide by ${minute(soonest.action.deadline)}` : '')}${tile('workflow version', `v${run.workflow_version}`)}</div>`;
351
383
  }
352
384
  const day = items.filter((i) => Date.parse(i.target_at) < Date.now() + 86400e3);
353
385
  const p50 = day.reduce((s, i) => s + (gbOf(i)?.p50 ?? 0), 0);
@@ -381,16 +413,19 @@ export const VIEWS = {
381
413
  return section('Passes at weather risk', `<p class="cf-empty">${none}</p>`);
382
414
  }
383
415
  return section(
384
- 'What each at-risk pass keeps if it rains',
416
+ 'What the advice adds to each at-risk pass',
385
417
  dumbbell(
386
- risky.map((i) => ({
387
- label: `${i.entity.satellite_id} @ ${stationTag(i.entity.antenna_id)}`,
388
- a: gbOf(i).p10,
389
- b: gbOf(i).p50,
390
- tip: `${linkLabel(i)} at ${minute(i.target_at)}: ${num(gbOf(i).p10)} GB at p10 against ${num(gbOf(i).p50)} GB at p50`,
391
- })),
418
+ risky.map((i) => {
419
+ const gain = typeof i.action.gain_gb === 'number' ? i.action.gain_gb : 0;
420
+ return {
421
+ label: `${i.entity.satellite_id} @ ${stationTag(i.entity.antenna_id)}`,
422
+ a: gbOf(i).p50,
423
+ b: gbOf(i).p50 + gain,
424
+ tip: `${linkLabel(i)} at ${minute(i.target_at)}: ${num(gbOf(i).p50)} GB expected in the rain, +${num(gain)} GB with the advice`,
425
+ };
426
+ }),
392
427
  ),
393
- 'Amber is the wet tail (p10); dark is the median (p50). The wider the gap, the more rain costs.',
428
+ 'Amber is the GB expected in the rain (p50); dark adds the gain the advice brings over doing nothing.',
394
429
  );
395
430
  }
396
431
  if (run.kind === 'audit-ledger') {
@@ -436,22 +471,20 @@ export const VIEWS = {
436
471
  .slice(0, 6)
437
472
  .map((i) => {
438
473
  const a = i.action;
439
- const g = gbOf(i);
440
474
  const approved = actionState(i) === 'approved';
441
- const backup = a.to ? `Book ${esc(i.entity.satellite_id)} on ${esc(shortAntenna(a.to_antenna_id))} at ${minute(a.to_at)}, +${num(a.gain_gb_p10)} GB at p10` : 'No better pass within 6 h';
442
- const head = approved ? 'Approved: carry out' : 'Rain-fade risk';
443
- const note = approved ? `Approved in Constellation. Cancel the original by ${minute(a.deadline)}` : `Cancel by ${minute(a.deadline)}`;
444
- return `<div class="cf-card" ${tip(`Decide by ${minute(a.deadline)}`)}><div class="cf-card-head"><span class="cf-status-warn" aria-hidden="true">▲</span><b>${head}</b><span class="cf-chip">${until(a.deadline)}</span></div><div>${esc(linkLabel(i))} at ${minute(i.target_at)} keeps ${num(g.p10)} of ${num(g.p50)} GB if it rains.</div><div class="cf-card-action">${backup}</div><div class="cf-note">${note}</div></div>`;
475
+ const head = approved ? 'Approved advice' : 'Rain-fade risk';
476
+ const note = approved ? `Approved in Constellation. Decide by ${minute(a.deadline)}` : `Decide by ${minute(a.deadline)}`;
477
+ return `<div class="cf-card" ${tip(`Decide by ${minute(a.deadline)}`)}><div class="cf-card-head"><span class="cf-status-warn" aria-hidden="true">▲</span><b>${head}</b><span class="cf-chip">${until(a.deadline)}</span></div><div>${esc(linkLabel(i))} at ${minute(i.target_at)}: ${esc(loss(i))}.</div><div class="cf-card-action">${esc(advice(i))}</div><div class="cf-note">${note}</div></div>`;
445
478
  });
446
479
  // A pass at risk with no backup comes as advice alone (a warning and its note): nothing to decide.
447
480
  const advisories = items
448
481
  .filter((i) => actionState(i) === null && i.severity)
449
482
  .slice(0, Math.max(0, 6 - cards.length))
450
- .map((i) => `<div class="cf-card"><div class="cf-card-head"><span class="cf-status-warn" aria-hidden="true">▲</span><b>Rain-fade risk</b></div><div>${esc(linkLabel(i))} at ${minute(i.target_at)} keeps ${num(gbOf(i).p10)} of ${num(gbOf(i).p50)} GB if it rains.</div><div class="cf-card-action">${esc(i.note || 'No backup pass in the window')}</div></div>`);
483
+ .map((i) => `<div class="cf-card"><div class="cf-card-head"><span class="cf-status-warn" aria-hidden="true">▲</span><b>Rain-fade risk</b></div><div>${esc(linkLabel(i))} at ${minute(i.target_at)}: ${esc(loss(i))}.</div><div class="cf-card-action">${esc(i.note || 'No backup pass in the window')}</div></div>`);
451
484
  cards.push(...advisories);
452
485
  const waiting = held ? ` ${held} awaiting approval in Constellation.` : '';
453
486
  const more = (all.length > 6 ? `The ${6} soonest of ${all.length}. Every swap is in Results below.` : 'Approved first, then the soonest decision.') + waiting;
454
- const title = all.some((i) => actionState(i) === 'approved') ? 'Swaps to carry out and to decide' : 'Swaps to decide';
487
+ const title = all.some((i) => actionState(i) === 'approved') ? 'Approved advice and swaps to decide' : 'Swaps to decide';
455
488
  if (!cards.length) return section(title, `<p class="cf-empty">No swaps to decide.${waiting}</p>`);
456
489
  return section(title, `<div class="cf-cards">${cards.join('')}</div>`, more);
457
490
  },
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openc3-cosmos-constellation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Constellation Space Corp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-20 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'A CONSTELLATION target whose packets a bridge microservice fills from
14
14
  the Constellation feed: the next predicted pass, the next 24 hours, the soonest