Skip to main content

adk_surface/camera/
view.rs

1//! What the live camera surface shows (spec 3.7 §8.2), in the words of the signed-off boards
2//! (`camera-*`, board choices C1–C15): the wire types of its routes, in the OpenAPI document of
3//! every `web` build.
4
5use chrono::{DateTime, Utc};
6use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8
9use crate::engine::CommandOutcome;
10use crate::model::{AgentRef, DecisionCard};
11
12/// A camera's state, as its pill and its picture show it.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
14#[serde(rename_all = "camelCase")]
15pub enum CameraState {
16    /// "Live".
17    Live,
18    /// "Saving frames": the governor looks less often or stopped escalating (board choice C4).
19    SavingFrames,
20    /// "Paused until midnight": the day's frames are used (board choice C5).
21    Paused,
22    /// "Can't reach the camera" (board choice C6).
23    Lost,
24    /// "Camera off": a person switched it off; nothing is captured or sent (board choice C7).
25    Off,
26    /// "Stream stopped": a person ended the stream (board choice C2).
27    Stopped,
28    /// "Paused by Stop all": every camera is paused until Resume all (spec 3.7 V-I17); nothing
29    /// is looked at.
30    Frozen,
31}
32
33/// The colour a line of words takes.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
35#[serde(rename_all = "camelCase")]
36pub enum Tone {
37    /// Green: live, watching, within budget.
38    Ok,
39    /// Amber: saving frames, near the limit.
40    Warn,
41    /// Red: paused, lost, at the limit.
42    Fail,
43    /// Grey: off, nothing to say.
44    Muted,
45    /// The text's own colour.
46    Plain,
47}
48
49/// How the picture is drawn.
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
51#[serde(rename_all = "camelCase")]
52pub enum StageLook {
53    /// The live frame.
54    Live,
55    /// The last frame, frozen and dimmed under the words (board choice C5).
56    Dimmed,
57    /// The last frame in grey under the words (board choice C6).
58    Grey,
59    /// A black panel: nothing is shown because nothing is captured (board choice C7).
60    Dark,
61}
62
63/// Where a region's tag sits: above its box, below it, or inside it at the frame's edge.
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
65#[serde(rename_all = "camelCase")]
66pub enum TagAt {
67    /// Above the box.
68    Above,
69    /// Below the box: a finding, so it does not cover the part's tag.
70    Below,
71    /// Inside the box, at its top.
72    In,
73}
74
75/// `GET /surface/cameras/{camera}` answer: one camera, watched large (board choice C1).
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
77#[serde(rename_all = "camelCase")]
78pub struct CameraView {
79    /// The camera's id.
80    pub id: String,
81    /// "Line 2 camera".
82    pub name: String,
83    /// "RTSP · 1920 × 1080 · on the line 2 server".
84    pub ingest: String,
85    /// The state.
86    pub state: CameraState,
87    /// "Live", "Saving frames", "Paused until midnight", "Can't reach the camera", "Camera off".
88    pub state_text: String,
89    /// The pill's colour.
90    pub tone: Tone,
91    /// The switch: on, or off (board choice C2).
92    pub on: bool,
93    /// The agent that watches it.
94    pub agent: CameraAgent,
95    /// The picture.
96    pub stage: StageView,
97    /// The banner over the picture, when there is something to warn about.
98    #[serde(default, skip_serializing_if = "Option::is_none")]
99    pub notice: Option<NoticeView>,
100    /// What the person may do here now.
101    pub actions: CameraActions,
102    /// The agent's open decisions on this session, such as the held line stop (board choice C13).
103    pub decisions: Vec<DecisionCard>,
104    /// "Nothing is waiting for you."
105    pub nothing_waiting: String,
106    /// "Watching for".
107    pub watches: Vec<WatchView>,
108    /// "Frame budget".
109    pub budget: BudgetView,
110    /// "Tracks now".
111    pub tracks: Vec<TrackRow>,
112    /// The words under the tracks: "Tracks are anonymous and start again when the camera does."
113    pub tracks_note: String,
114    /// The phone's words under the budget while the camera is off: "Tracks start again when the
115    /// camera is back on."
116    #[serde(default, skip_serializing_if = "Option::is_none")]
117    pub tracks_short_note: Option<String>,
118    /// The zones a person may edit, in the camera's pixels.
119    pub zones: Vec<ZoneView>,
120    /// "Sources": every camera, this one's tile following its state (board choice C15).
121    pub sources: Vec<SourceTile>,
122}
123
124/// The agent that watches a camera.
125#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
126#[serde(rename_all = "camelCase")]
127pub struct CameraAgent {
128    /// The agent.
129    pub agent: AgentRef,
130    /// "Asleep until a defect", "Paused by the frame budget", "Not watching: no frames".
131    pub line: String,
132    /// The line's colour.
133    pub tone: Tone,
134    /// The session its thread follows: "Open the thread".
135    pub session_id: String,
136}
137
138/// What a person may do with a camera now.
139#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)]
140#[serde(rename_all = "camelCase")]
141pub struct CameraActions {
142    /// "Camera on / Off".
143    pub switch: bool,
144    /// "Stop the stream".
145    pub stop: bool,
146    /// "Try again now".
147    pub retry: bool,
148    /// "Draw a zone", "Edit the zone".
149    pub zone: bool,
150    /// "Raise a card from this frame".
151    pub raise_card: bool,
152    /// "Use this browser's camera": the camera takes the frames this screen captures
153    /// (`POST /surface/cameras/{camera}/frames`), as the web home's own camera does.
154    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
155    pub send_frames: bool,
156}
157
158/// The picture and what is drawn over it.
159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
160#[serde(rename_all = "camelCase")]
161pub struct StageView {
162    /// The camera's width in pixels; every region is in these pixels.
163    pub width: u32,
164    /// The camera's height in pixels.
165    pub height: u32,
166    /// How the picture is drawn.
167    pub look: StageLook,
168    /// The frame shown, when one is held.
169    #[serde(default, skip_serializing_if = "Option::is_none")]
170    pub frame: Option<FrameView>,
171    /// "Live · 10:41:09", "Last frame · 15:12:03".
172    #[serde(default, skip_serializing_if = "Option::is_none")]
173    pub badge: Option<BadgeView>,
174    /// "Looking 5 a second · overlays 0.1 s behind" (board choice C10).
175    #[serde(default, skip_serializing_if = "Option::is_none")]
176    pub rate: Option<String>,
177    /// The words over the picture when it is not live.
178    #[serde(default, skip_serializing_if = "Option::is_none")]
179    pub cover: Option<CoverView>,
180    /// What was found on the frame.
181    pub regions: Vec<CameraRegion>,
182    /// The zones.
183    pub zones: Vec<ZoneView>,
184    /// Where each track was over the frames held.
185    pub trails: Vec<TrailView>,
186}
187
188/// A frame the hub holds, served by its digest.
189#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
190#[serde(rename_all = "camelCase")]
191pub struct FrameView {
192    /// `sha256:` of its bytes.
193    pub digest: String,
194    /// `/api/surface/cameras/{camera}/frames/{digest}`: the bytes, while the hub holds them.
195    pub href: String,
196    /// When it was captured.
197    pub at: DateTime<Utc>,
198    /// "10:41:09".
199    pub at_text: String,
200}
201
202/// A badge on the picture.
203#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
204#[serde(rename_all = "camelCase")]
205pub struct BadgeView {
206    /// "Live · 10:41:09".
207    pub text: String,
208    /// The dot's colour.
209    pub tone: Tone,
210}
211
212/// The words over a picture that is not live.
213#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
214#[serde(rename_all = "camelCase")]
215pub struct CoverView {
216    /// "Paused until midnight", "Can't reach the line 2 camera", "Camera off".
217    pub title: String,
218    /// "Nothing is captured or sent. You switched line 2 off at 11:05."
219    pub text: String,
220    /// A spinner: the source is being tried again.
221    pub retrying: bool,
222    /// The camera-off icon.
223    pub off: bool,
224}
225
226/// Something found on the frame, in the camera's pixels.
227#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
228#[serde(rename_all = "camelCase")]
229pub struct CameraRegion {
230    /// "part", "seal tear", "fiducial", "person": the overlay's colour (board choice S1).
231    pub label: String,
232    /// `[x0, y0, x1, y1]`; absent for a mask drawn alone.
233    #[serde(default, skip_serializing_if = "Option::is_none")]
234    pub bbox: Option<[f64; 4]>,
235    /// "part · T45", "seal tear · 0.91 · 5 frames · 14.3 mm", "person · blurred".
236    pub tag: String,
237    /// The phone's and a tile's tag: "T45", "14.3 mm".
238    pub short_tag: String,
239    /// Where the tag sits.
240    pub tag_at: TagAt,
241    /// The anonymous track.
242    #[serde(default, skip_serializing_if = "Option::is_none")]
243    pub track: Option<u64>,
244    /// A mask's outline (the Masks layer).
245    #[serde(default, skip_serializing_if = "Vec::is_empty")]
246    pub outline: Vec<[f64; 2]>,
247    /// A measured length.
248    #[serde(default, skip_serializing_if = "Option::is_none")]
249    pub measurement: Option<MeasurementView>,
250    /// What a watch looks for: drawn selected.
251    pub finding: bool,
252}
253
254/// A measured length, drawn as a line with its ends.
255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
256#[serde(rename_all = "camelCase")]
257pub struct MeasurementView {
258    /// One end, in the camera's pixels.
259    pub from: [f64; 2],
260    /// The other end.
261    pub to: [f64; 2],
262    /// "14.3 mm".
263    pub text: String,
264}
265
266/// A zone, in the camera's pixels (board choice C12).
267#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
268#[serde(rename_all = "camelCase")]
269pub struct ZoneView {
270    /// Its id.
271    pub id: String,
272    /// "Inspection window".
273    pub name: String,
274    /// `[x0, y0, x1, y1]` in the camera's pixels.
275    pub corners: [f64; 4],
276    /// "700, 200 → 1600, 880".
277    pub corners_text: String,
278    /// The watches that use it: "Seal tear watch".
279    pub used_by: Vec<String>,
280}
281
282/// Where a track was over the frames held: its trail.
283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
284#[serde(rename_all = "camelCase")]
285pub struct TrailView {
286    /// The track.
287    pub track: u64,
288    /// Its centres, newest first, in the camera's pixels.
289    pub points: Vec<[f64; 2]>,
290}
291
292/// The banner over the picture.
293#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
294#[serde(rename_all = "camelCase")]
295pub struct NoticeView {
296    /// Its colour.
297    pub tone: Tone,
298    /// "Saving frames.", "Parts on line 2 are passing without inspection."
299    pub title: String,
300    /// What follows the title.
301    pub text: String,
302    /// The error, credentials hidden: "connection refused · rtsp://[credentials hidden]@…".
303    #[serde(default, skip_serializing_if = "Option::is_none")]
304    pub detail: Option<String>,
305    /// The phone's shorter title.
306    pub short_title: String,
307    /// The phone's shorter text.
308    pub short_text: String,
309    /// What the banner offers.
310    #[serde(default, skip_serializing_if = "Option::is_none")]
311    pub action: Option<NoticeAction>,
312}
313
314/// What a banner offers.
315#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
316#[serde(rename_all = "camelCase", rename_all_fields = "camelCase", tag = "kind")]
317pub enum NoticeAction {
318    /// "Try again now".
319    Retry {
320        /// The words.
321        text: String,
322        /// The phone's words.
323        short_text: String,
324    },
325    /// "Change the daily frame limit", in Memory & rules.
326    Limit {
327        /// The words.
328        text: String,
329        /// The phone's words.
330        short_text: String,
331        /// Where it opens.
332        href: String,
333    },
334}
335
336/// One watch condition (board choice C1 "Watching for").
337#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
338#[serde(rename_all = "camelCase")]
339pub struct WatchView {
340    /// Its id.
341    pub id: String,
342    /// "Seal tear".
343    pub name: String,
344    /// The label it looks for: its colour.
345    pub label: String,
346    /// "Watching", "Paused", "No frames", "Camera off".
347    pub pill: String,
348    /// It looks at frames now.
349    pub active: bool,
350    /// "Score 0.80 or more, 3 frames in a row, inside".
351    pub before: String,
352    /// The zone it looks inside: "Inspection window".
353    #[serde(default, skip_serializing_if = "Option::is_none")]
354    pub zone: Option<String>,
355    /// ". Then wait 30 s before waking again for the same track."
356    pub after: String,
357    /// The phone's line: "Seal tear, 0.80+, 3 frames in".
358    pub short_before: String,
359    /// What follows the zone on the phone: " · not watching" when it does not look.
360    pub short_after: String,
361    /// "Woke the Inspector 3 times today".
362    pub woke: String,
363}
364
365/// "Frame budget" (board choice C3).
366#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
367#[serde(rename_all = "camelCase")]
368pub struct BudgetView {
369    /// "for line 2".
370    pub scope: String,
371    /// Looking, Asking, Frames today.
372    pub meters: Vec<MeterView>,
373    /// "Steps down in this order: …", while nothing has stepped down.
374    #[serde(default, skip_serializing_if = "Option::is_none")]
375    pub order: Option<String>,
376    /// "What the budget did": each step with its time, then the next.
377    pub steps: Vec<StepView>,
378    /// "Change the daily frame limit", once the camera paused.
379    #[serde(default, skip_serializing_if = "Option::is_none")]
380    pub limit: Option<String>,
381    /// The phone's rows.
382    pub rows: Vec<BudgetRow>,
383}
384
385/// One meter.
386#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
387#[serde(rename_all = "camelCase")]
388pub struct MeterView {
389    /// "Looking", "Asking sam-3.1 about unclear tracks", "Frames today".
390    pub label: String,
391    /// "5 a second", "2 in the last minute", "61,240 of 300,000".
392    pub value: String,
393    /// How full the bar is, in hundredths.
394    pub percent: u8,
395    /// The bar's colour.
396    pub tone: Tone,
397    /// "As set", "At most 6 a minute · 14 today · $0.14", "Renews at midnight".
398    #[serde(default, skip_serializing_if = "Option::is_none")]
399    pub note: Option<String>,
400}
401
402/// One step the governor took, or the next.
403#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
404#[serde(rename_all = "camelCase")]
405pub struct StepView {
406    /// "14:02", or "next".
407    pub at: String,
408    /// "Looked less often: 5 → 2 a second (90% used)".
409    pub text: String,
410    /// The next step, not taken yet.
411    pub next: bool,
412}
413
414/// One of the phone's budget rows.
415#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
416#[serde(rename_all = "camelCase")]
417pub struct BudgetRow {
418    /// "Looking".
419    pub label: String,
420    /// "2 a second (was 5)".
421    pub value: String,
422    /// Its colour; `muted` for plain words.
423    pub tone: Tone,
424}
425
426/// One track now.
427#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
428#[serde(rename_all = "camelCase")]
429pub struct TrackRow {
430    /// "T43".
431    pub id: String,
432    /// "part".
433    pub label: String,
434    /// "seal tear 0.91 · in the zone · 5 frames".
435    pub note: String,
436    /// The phone's note: "seal tear 0.91 · in the zone".
437    pub short_note: String,
438    /// The swatch: the finding's label, else the track's.
439    pub swatch: String,
440    /// A watch looks for what was found on it: the row is marked.
441    pub finding: bool,
442}
443
444/// One camera in "Sources", the strip under a single camera (board choice C15).
445#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
446#[serde(rename_all = "camelCase")]
447pub struct SourceTile {
448    /// The camera's id.
449    pub id: String,
450    /// "Line 3 camera".
451    pub name: String,
452    /// The state.
453    pub state: CameraState,
454    /// "Live", "Saving frames", "Paused", "Lost", "Off".
455    pub state_text: String,
456    /// Its colour.
457    pub tone: Tone,
458    /// The camera shown large.
459    pub selected: bool,
460    /// The small picture.
461    pub stage: StageView,
462}
463
464/// `GET /surface/cameras` answer: every camera, a grid of them (board choice C8).
465#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
466#[serde(rename_all = "camelCase")]
467pub struct CamerasView {
468    /// "Cameras".
469    pub title: String,
470    /// "4 sources · 3 on".
471    pub count_text: String,
472    /// The phone's: "4 · 3 on".
473    pub count_short: String,
474    /// The agent that watches them.
475    #[serde(default, skip_serializing_if = "Option::is_none")]
476    pub agent: Option<CameraAgent>,
477    /// The camera shown first, by its id.
478    #[serde(default, skip_serializing_if = "Option::is_none")]
479    pub selected: Option<String>,
480    /// The phone's line under the large picture: "Line 2 camera · Live · 5 a second".
481    #[serde(default, skip_serializing_if = "Option::is_none")]
482    pub selected_line: Option<String>,
483    /// Every camera.
484    pub tiles: Vec<CameraTile>,
485    /// "Each source has its own frame budget. Stop all pauses every one of them."
486    pub note: String,
487    /// "Each camera has its own frame budget. People are blurred before any frame is shown or kept."
488    pub short_note: String,
489    /// "Select a camera to watch it large. People are blurred before any frame is shown or kept."
490    pub footer: String,
491    /// The agents' open decisions on these cameras' sessions.
492    pub decisions: Vec<DecisionCard>,
493    /// "Nothing is waiting for you."
494    pub nothing_waiting: String,
495    /// Each camera's frames today.
496    pub budget: Vec<MeterView>,
497}
498
499/// One camera of the grid.
500#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
501#[serde(rename_all = "camelCase")]
502pub struct CameraTile {
503    /// The camera's id.
504    pub id: String,
505    /// "Line 2 camera".
506    pub name: String,
507    /// The state.
508    pub state: CameraState,
509    /// "Live", "Saving frames", "Off".
510    pub state_text: String,
511    /// Its colour.
512    pub tone: Tone,
513    /// The switch.
514    pub on: bool,
515    /// The switch may be changed here.
516    pub can_switch: bool,
517    /// The picture, with its overlays.
518    pub stage: StageView,
519    /// "watching for seal tears", "shown only, nothing watched", "from the voice screen".
520    pub caption: String,
521    /// The switch list's line: "5 a second · 20% of today's frames".
522    pub line: String,
523    /// The phone's line: "watching", "2 a second", "shown only".
524    pub short_line: String,
525}
526
527/// `PUT /surface/cameras/{camera}/zones/{zone}` body: the zone's new name and corners, and the
528/// corners the person saw before changing them.
529#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
530#[serde(rename_all = "camelCase")]
531pub struct ZoneChange {
532    /// The zone's name.
533    pub name: String,
534    /// `[x0, y0, x1, y1]` in the camera's pixels.
535    pub corners: [f64; 4],
536    /// The corners the person started from: a zone changed since is refused, not overwritten.
537    pub was: [f64; 4],
538}
539
540/// `PUT /surface/cameras/{camera}/zones/{zone}` answer.
541#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
542#[serde(rename_all = "camelCase")]
543pub struct ZoneSaved {
544    /// The zone now.
545    pub zone: ZoneView,
546    /// "Saved. The seal tear watch uses it from the next frame."
547    pub text: String,
548}
549
550/// `POST /surface/cameras/{camera}/freeze` body: the frame on screen, by its digest.
551#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
552#[serde(rename_all = "camelCase")]
553pub struct FreezeFrame {
554    /// The frame's `sha256:` digest; the hub must still hold it.
555    pub frame: String,
556}
557
558/// `POST /surface/cameras/{camera}/cards` body: a card from a frozen frame (board choice C11).
559#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
560#[serde(rename_all = "camelCase")]
561pub struct RaiseCard {
562    /// The frozen frame, by its digest; the hub must still hold it.
563    pub frame: String,
564    /// "What should it look at?"
565    pub note: String,
566}
567
568/// `POST /surface/cameras/{camera}/frames` answer: what became of one frame this screen
569/// captured.
570#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
571#[serde(rename_all = "camelCase")]
572pub struct FrameTaken {
573    /// The frame went on to the camera's pipeline.
574    pub taken: bool,
575    /// Why it did not. While the camera is off, stopped or paused by Stop all, the screen stops
576    /// capturing: a camera switched off sends nothing.
577    #[serde(default, skip_serializing_if = "Option::is_none")]
578    pub dropped: Option<FrameDropped>,
579}
580
581/// Why the server dropped a frame a screen sent.
582#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
583#[serde(rename_all = "camelCase")]
584pub enum FrameDropped {
585    /// The camera is switched off.
586    Off,
587    /// The camera's stream was stopped.
588    Stopped,
589    /// Stop all paused every camera.
590    Frozen,
591    /// The pipeline was not reading the camera when the frame came.
592    NotReading,
593}
594
595/// `POST /surface/cameras/{camera}/cards` answer.
596#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
597#[serde(rename_all = "camelCase")]
598pub struct CardRaised {
599    /// The kept frame's digest, after blurring: the evidence the card and a held call carry.
600    pub digest: String,
601    /// The short form: `sha256:c52ca5…ce7550`.
602    pub short_digest: String,
603    /// The regions that went with it.
604    pub regions: usize,
605    /// "Kept as evidence until 18 Dec".
606    pub kept_until: String,
607    /// The kept frame in the annotated viewer.
608    pub href: String,
609    /// What sending it to the agent did: sent, or queued behind a decision or a turn.
610    pub outcome: CommandOutcome,
611    /// "Raised to the Inspector. This one frame is kept as evidence until 18 Dec."
612    pub text: String,
613}