1use std::collections::BTreeMap;
10
11use printobserver_printer_api::{Adjustable, PrinterState};
12use printobserver_types::contract::Sample;
13use printobserver_types::{EventId, FileName, ImageId, PrintId, Range, Timestamp};
14
15use super::action::{
16 AcknowledgementDisposition, ActionKind, ActionRecord, ActionRequest, Actor, ActorClass,
17 ExecutionOutcome, PrintAction,
18};
19use super::camera_check::CameraCheckObjection;
20use super::charge::{
21 ChargeKey, ChargeMethod, ChargedFilament, FilePosition, PendingCharge, PendingTaken,
22 PrintOutcome, PrintSegmentKey,
23};
24use super::ids::{ActionId, CameraCheckId, InterventionId, SpoolId};
25use super::image::ImageRecord;
26use super::intervention::{Intervention, InterventionOutcome};
27use super::manifest::{JobManifest, SegmentSpool};
28use super::policy::{
29 EffectiveBounds, PolicyDecision, RejectionReason, SafetyEnvelope, SpoolField, SpoolRefusalCause,
30};
31use super::preflight::{
32 DoubtedSpool, MaterialComparison, MaterialName, MaterialObjection, MaterialResult, Preflight,
33 PreflightNeed, PreflightObjection, PreflightSegment, PreflightSpool, PreflightTool,
34 PreflightToolResult, PreflightVerdict, SheetComparison, SheetId, SheetObjection, SheetResult,
35 ShortSpool, UnanalysedSpool, UncomparedMaterial,
36};
37use super::print::{ManifestNarrowing, PrintRecord};
38use super::spool::{
39 ClearedMark, LoadedSpool, SpoolLifecycle, SpoolRecord, SpoolTrust, UnverifiedMark,
40 UnverifiedMarks, UnverifiedReason,
41};
42use super::spool_command::SpoolCommand;
43
44fn later_instant() -> Timestamp {
46 "2026-03-01T12:30:00Z"
47 .parse()
48 .expect("a fixed RFC 3339 instant")
49}
50
51fn action_id() -> ActionId {
53 "0191f0a0-0000-7000-8000-000000000004"
54 .parse()
55 .expect("a fixed version 7 identifier")
56}
57
58fn intervention_id() -> InterventionId {
60 "0191f0a0-0000-7000-8000-000000000005"
61 .parse()
62 .expect("a fixed version 7 identifier")
63}
64
65fn spool_id() -> SpoolId {
67 "0191f0a0-0000-7000-8000-000000000006"
68 .parse()
69 .expect("a fixed version 7 identifier")
70}
71
72fn replaced_spool_id() -> SpoolId {
74 "0191f0a0-0000-7000-8000-000000000007"
75 .parse()
76 .expect("a fixed version 7 identifier")
77}
78
79impl Sample for SpoolId {
80 fn sample_full() -> Self {
81 spool_id()
82 }
83}
84
85impl Sample for ActionId {
86 fn sample_full() -> Self {
87 action_id()
88 }
89}
90
91impl Sample for InterventionId {
92 fn sample_full() -> Self {
93 intervention_id()
94 }
95}
96
97impl Sample for CameraCheckId {
98 fn sample_full() -> Self {
99 "0191f0a0-0000-7000-8000-0000000000c1"
100 .parse()
101 .expect("a fixed version 7 identifier")
102 }
103}
104
105impl Sample for ManifestNarrowing {
106 fn sample_full() -> Self {
107 Self {
108 adjustable: Adjustable::Feedrate,
109 requested: Range::new(0.2, 4.0),
110 applied: Range::new(0.5, 1.5),
111 }
112 }
113}
114
115impl Sample for PrintRecord {
116 fn sample_full() -> Self {
117 Self {
118 id: PrintId::sample_full(),
119 provider_print_id: Some(4211),
120 file_name: Some("benchy.gcode".to_owned()),
121 state: PrinterState::Printing,
122 opened_at: Timestamp::sample_full(),
123 job_started_at: Some(Timestamp::sample_full()),
124 job_print_time_s: Some(3024),
125 ended_at: Some(later_instant()),
126 end_reason: Some("finished".to_owned()),
127 narrowings: vec![ManifestNarrowing::sample_full()],
128 }
129 }
130
131 fn sample_minimal() -> Self {
132 Self {
133 id: PrintId::sample_full(),
134 provider_print_id: None,
135 file_name: None,
136 state: PrinterState::Printing,
137 opened_at: Timestamp::sample_full(),
138 job_started_at: None,
139 job_print_time_s: None,
140 ended_at: None,
141 end_reason: None,
142 narrowings: vec![],
143 }
144 }
145}
146
147impl Sample for ImageRecord {
148 fn sample_full() -> Self {
149 Self {
150 id: ImageId::sample_full(),
151 print_id: Some(PrintId::sample_full()),
152 event_id: EventId::sample_full(),
153 source_url: Some("https://detector.example/snapshots/1.jpg".to_owned()),
154 fetched_at: Timestamp::sample_full(),
155 content_type: "image/jpeg".to_owned(),
156 byte_len: 51_200,
157 sha256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855".to_owned(),
158 relative_path: "images/0191f0a0/1.jpg".to_owned(),
159 }
160 }
161
162 fn sample_minimal() -> Self {
163 Self {
164 print_id: None,
165 source_url: None,
166 ..Self::sample_full()
167 }
168 }
169}
170
171impl Sample for Actor {
172 fn sample_full() -> Self {
173 Self::Agent {
174 session_name: "print-0191f0a0".to_owned(),
175 }
176 }
177}
178
179impl Sample for ActorClass {
180 fn sample_full() -> Self {
181 Self::Agent
182 }
183}
184
185impl Sample for ActionKind {
186 fn sample_full() -> Self {
187 Self::SetFeedrateFactor
188 }
189}
190
191impl Sample for AcknowledgementDisposition {
192 fn sample_full() -> Self {
193 Self::Watch
194 }
195}
196
197impl Sample for ExecutionOutcome {
198 fn sample_full() -> Self {
199 Self::Failed {
200 reason: "the printer refused the command".to_owned(),
201 }
202 }
203}
204
205impl Sample for PrintAction {
206 fn sample_full() -> Self {
207 Self::SetFeedrateFactor {
208 factor: 0.8,
209 duration_s: Some(600),
210 reason: "the first layer is going down fast".to_owned(),
211 actor: Actor::sample_full(),
212 }
213 }
214
215 fn sample_minimal() -> Self {
216 Self::SetFeedrateFactor {
217 factor: 0.8,
218 duration_s: None,
219 reason: "the first layer is going down fast".to_owned(),
220 actor: Actor::sample_full(),
221 }
222 }
223
224 fn sample_alternates() -> Vec<Self> {
225 let reason = || "the print needs it".to_owned();
226 vec![
227 Self::Pause {
228 reason: reason(),
229 actor: Actor::sample_full(),
230 },
231 Self::Resume {
232 reason: reason(),
233 actor: Actor::sample_full(),
234 },
235 Self::Cancel {
236 reason: reason(),
237 actor: Actor::sample_full(),
238 },
239 Self::StartPrint {
240 file_name: FileName::sample_full(),
241 manifest: JobManifest::sample_full(),
242 override_filament_check: true,
243 override_material_check: true,
244 override_sheet_check: true,
245 reason: reason(),
246 actor: Actor::sample_full(),
247 },
248 Self::SetFlowrateFactor {
249 factor: 1.05,
250 duration_s: Some(300),
251 reason: reason(),
252 actor: Actor::sample_full(),
253 },
254 Self::SetToolTargetC {
255 tool: 0,
256 target_c: 215.0,
257 duration_s: Some(300),
258 reason: reason(),
259 actor: Actor::sample_full(),
260 },
261 Self::SetBedTargetC {
262 target_c: 60.0,
263 duration_s: Some(300),
264 reason: reason(),
265 actor: Actor::sample_full(),
266 },
267 Self::SetFanPercent {
268 percent: 80.0,
269 duration_s: Some(300),
270 reason: reason(),
271 actor: Actor::sample_full(),
272 },
273 Self::AcknowledgeFailure {
274 event_id: EventId::sample_full(),
275 disposition: AcknowledgementDisposition::Watch,
276 reason: reason(),
277 actor: Actor::Operator,
278 },
279 Self::ClosePrint {
280 outcome: PrintOutcome::Interrupted,
281 reason: "the printer was switched off mid-print".to_owned(),
282 actor: Actor::Operator,
283 },
284 ]
285 }
286}
287
288impl Sample for ActionRequest {
289 fn sample_full() -> Self {
290 Self {
291 action: PrintAction::sample_full(),
292 actor: Actor::sample_full(),
293 requested_at: Timestamp::sample_full(),
294 }
295 }
296
297 fn sample_minimal() -> Self {
298 Self {
299 action: PrintAction::sample_minimal(),
300 ..Self::sample_full()
301 }
302 }
303}
304
305impl Sample for ActionRecord {
306 fn sample_full() -> Self {
307 Self {
308 id: action_id(),
309 print_id: PrintId::sample_full(),
310 request: ActionRequest::sample_full(),
311 decision: PolicyDecision::Accepted,
312 executed_at: Some(later_instant()),
313 outcome: Some(ExecutionOutcome::Succeeded),
314 }
315 }
316
317 fn sample_minimal() -> Self {
318 Self {
319 request: ActionRequest::sample_minimal(),
320 executed_at: None,
321 outcome: None,
322 ..Self::sample_full()
323 }
324 }
325}
326
327fn allowed_ranges() -> BTreeMap<Adjustable, Range> {
329 BTreeMap::from([
330 (Adjustable::Feedrate, Range::new(0.5, 1.5)),
331 (Adjustable::ToolTarget { tool: 0 }, Range::new(190.0, 230.0)),
332 ])
333}
334
335impl Sample for JobManifest {
336 fn sample_full() -> Self {
337 Self {
338 file_name: "benchy.gcode".to_owned(),
339 material: "PLA".to_owned(),
340 nozzle_diameter_mm: 0.4,
341 slicer_profile: "0.2mm standard".to_owned(),
342 sheet: Some("smooth-pei".to_owned()),
343 allowed: allowed_ranges(),
344 metadata: BTreeMap::from([("layer_height_mm".to_owned(), "0.2".to_owned())]),
345 segment_spools: vec![SegmentSpool::sample_full()],
346 camera_check: Some(CameraCheckId::sample_full()),
347 }
348 }
349
350 fn sample_minimal() -> Self {
351 Self {
352 sheet: None,
353 segment_spools: Vec::new(),
354 camera_check: None,
355 ..Self::sample_full()
356 }
357 }
358}
359
360impl Sample for SegmentSpool {
361 fn sample_full() -> Self {
362 Self {
363 segment: 1,
364 spool_id: spool_id(),
365 }
366 }
367}
368
369impl Sample for SafetyEnvelope {
370 fn sample_full() -> Self {
371 Self {
372 allowed: allowed_ranges(),
373 actions: BTreeMap::from([(
374 ActorClass::Agent,
375 vec![ActionKind::Pause, ActionKind::SetFeedrateFactor],
376 )]),
377 agent_min_interval_s: 60,
378 }
379 }
380}
381
382impl Sample for EffectiveBounds {
383 fn sample_full() -> Self {
384 Self {
385 allowed: allowed_ranges(),
386 }
387 }
388}
389
390impl Sample for RejectionReason {
391 fn sample_full() -> Self {
392 Self::OutOfBounds {
393 adjustable: Adjustable::Feedrate,
394 requested: 4.0,
395 allowed: Range::new(0.5, 1.5),
396 }
397 }
398
399 fn sample_alternates() -> Vec<Self> {
400 vec![
401 Self::InsufficientFilament {
402 tool: 0,
403 spool_id: spool_id(),
404 spool_name: "Galaxy black".to_owned(),
405 required_g: 120.0,
406 buffer_g: 12.0,
407 remaining_g: 80.0,
408 unverified: Some(UnverifiedReason::sample_full()),
409 segment: Some(1),
410 },
411 Self::InsufficientFilament {
412 tool: 0,
413 spool_id: spool_id(),
414 spool_name: "Galaxy black".to_owned(),
415 required_g: 120.0,
416 buffer_g: 12.0,
417 remaining_g: 80.0,
418 unverified: None,
419 segment: None,
420 },
421 Self::UnverifiedSpool {
422 tool: 0,
423 spool_id: spool_id(),
424 spool_name: "Galaxy black".to_owned(),
425 reason: UnverifiedReason::sample_full(),
426 segment: Some(2),
427 },
428 Self::AnalysisUnavailable {
429 file_name: "benchy.gcode".to_owned(),
430 waited_s: 300,
431 },
432 Self::SpoolRefused {
433 cause: SpoolRefusalCause::sample_full(),
434 message: "spool Galaxy black is retired, so it takes no command".to_owned(),
435 },
436 Self::MaterialRefused {
437 objection: MaterialObjection::sample_full(),
438 },
439 Self::SheetRefused {
440 objection: SheetObjection::sample_full(),
441 },
442 Self::SheetNotDeclared,
443 Self::CameraCheckRefused {
444 camera_check: CameraCheckId::sample_full(),
445 objection: CameraCheckObjection::sample_full(),
446 },
447 Self::PrintAlreadyEnded,
448 Self::PrintStillActive {
449 state: PrinterState::Paused,
450 },
451 Self::InterventionStillActive {
452 intervention_id: InterventionId::sample_full(),
453 },
454 Self::PlannedChangeWaiting {
455 change_index: 0,
456 layer: 12,
457 z_mm: 2.4,
458 color: Some("#FF0000".to_owned()),
459 },
460 Self::PlannedChangeWaiting {
461 change_index: 1,
462 layer: 24,
463 z_mm: 4.8,
464 color: None,
465 },
466 ]
467 }
468}
469
470impl Sample for SpoolField {
471 fn sample_full() -> Self {
472 Self::GrossG
473 }
474}
475
476impl Sample for SpoolRefusalCause {
477 fn sample_full() -> Self {
478 Self::RetiredSpool {
479 spool_id: spool_id(),
480 }
481 }
482
483 fn sample_minimal() -> Self {
484 Self::DensityRequired {
485 spool_id: None,
486 material: "PEEK".to_owned(),
487 }
488 }
489
490 fn sample_alternates() -> Vec<Self> {
491 vec![
492 Self::UnknownSpool {
493 spool_id: replaced_spool_id(),
494 },
495 Self::NothingToConfirm { tool: 0 },
496 Self::InvalidAdjustmentFigure {
497 field: SpoolField::GrossG,
498 value: -5.0,
499 },
500 Self::TareRequired {
501 spool_id: spool_id(),
502 },
503 Self::DensityRequired {
504 spool_id: Some(spool_id()),
505 material: "PEEK".to_owned(),
506 },
507 Self::MissingField {
508 field: SpoolField::Name,
509 },
510 Self::ConflictingFields {
511 fields: vec![SpoolField::RemainingG, SpoolField::GrossG],
512 },
513 Self::UnknownTool { tool: -1 },
514 Self::NotLoaded {
515 spool_id: spool_id(),
516 },
517 Self::LedgerRefused,
518 ]
519 }
520}
521
522impl Sample for PolicyDecision {
523 fn sample_full() -> Self {
524 Self::Rejected(RejectionReason::sample_full())
525 }
526}
527
528impl Sample for InterventionOutcome {
529 fn sample_full() -> Self {
530 Self::Superseded {
531 by: intervention_id(),
532 }
533 }
534}
535
536impl Sample for Intervention {
537 fn sample_full() -> Self {
538 Self {
539 id: intervention_id(),
540 print_id: PrintId::sample_full(),
541 action_id: action_id(),
542 adjustable: Adjustable::Feedrate,
543 prior_value: Some(1.0),
544 applied_value: 0.8,
545 applied_at: Timestamp::sample_full(),
546 expires_at: later_instant(),
547 restored_at: Some(later_instant()),
548 outcome: InterventionOutcome::Restored,
549 }
550 }
551
552 fn sample_minimal() -> Self {
553 Self {
554 prior_value: None,
555 restored_at: None,
556 outcome: InterventionOutcome::StillActive,
557 ..Self::sample_full()
558 }
559 }
560}
561
562impl Sample for UnverifiedReason {
563 fn sample_full() -> Self {
564 Self::UnchargedPrint {
565 print_id: PrintId::sample_full(),
566 }
567 }
568
569 fn sample_alternates() -> Vec<Self> {
570 vec![
571 Self::UnaccountedPrint {
572 file_name: "benchy.gcode".to_owned(),
573 printed_at: Timestamp::sample_full(),
574 },
575 Self::FilamentChangeUnconfirmed {
576 print_id: PrintId::sample_full(),
577 },
578 Self::FilamentChangeUnconfirmedPosition {
579 print_id: PrintId::sample_full(),
580 },
581 Self::TallyReset {
582 file_name: "benchy.gcode".to_owned(),
583 origin: "local".to_owned(),
584 },
585 ]
586 }
587}
588
589impl Sample for UnverifiedMark {
590 fn sample_full() -> Self {
591 Self {
592 reason: UnverifiedReason::sample_full(),
593 since: Timestamp::sample_full(),
594 }
595 }
596}
597
598impl Sample for UnverifiedMarks {
599 fn sample_full() -> Self {
600 Self::new(vec![
601 UnverifiedMark::sample_full(),
602 UnverifiedMark {
603 reason: UnverifiedReason::FilamentChangeUnconfirmed {
604 print_id: PrintId::sample_full(),
605 },
606 since: later_instant(),
607 },
608 ])
609 .expect("two marks")
610 }
611}
612
613impl Sample for SpoolTrust {
614 fn sample_full() -> Self {
615 Self::Unverified {
616 marks: UnverifiedMarks::sample_full(),
617 }
618 }
619
620 fn sample_alternates() -> Vec<Self> {
621 vec![Self::Verified]
622 }
623}
624
625impl Sample for SpoolRecord {
626 fn sample_full() -> Self {
627 Self {
628 id: spool_id(),
629 name: "Galaxy black".to_owned(),
630 material: "PLA".to_owned(),
631 color: Some("black".to_owned()),
632 diameter_mm: 1.75,
633 density_g_cm3: 1.24,
634 initial_g: 1_000.0,
635 remaining_g: 742.5,
636 tare_g: Some(250.0),
637 lifecycle: SpoolLifecycle::sample_full(),
638 trust: SpoolTrust::sample_full(),
639 registered_at: Timestamp::sample_full(),
640 updated_at: later_instant(),
641 }
642 }
643
644 fn sample_minimal() -> Self {
645 Self {
646 color: None,
647 tare_g: None,
648 lifecycle: SpoolLifecycle::Shelved,
649 trust: SpoolTrust::Verified,
650 ..Self::sample_full()
651 }
652 }
653
654 fn sample_alternates() -> Vec<Self> {
655 vec![Self {
656 remaining_g: 12.5,
657 lifecycle: SpoolLifecycle::Retired {
658 at: later_instant(),
659 },
660 ..Self::sample_full()
661 }]
662 }
663}
664
665impl Sample for SpoolLifecycle {
666 fn sample_full() -> Self {
667 Self::Loaded { tool: 0 }
668 }
669
670 fn sample_alternates() -> Vec<Self> {
671 vec![
672 Self::Shelved,
673 Self::Retired {
674 at: later_instant(),
675 },
676 ]
677 }
678}
679
680impl Sample for ClearedMark {
681 fn sample_full() -> Self {
682 Self {
683 spool_id: replaced_spool_id(),
684 reason: UnverifiedReason::FilamentChangeUnconfirmed {
685 print_id: PrintId::sample_full(),
686 },
687 }
688 }
689}
690
691impl Sample for LoadedSpool {
692 fn sample_full() -> Self {
693 Self {
694 tool: 0,
695 spool_id: spool_id(),
696 }
697 }
698}
699
700impl Sample for PrintOutcome {
701 fn sample_full() -> Self {
702 Self::Completed
703 }
704
705 fn sample_alternates() -> Vec<Self> {
706 vec![Self::Cancelled, Self::Failed, Self::Interrupted]
707 }
708}
709
710impl Sample for ChargeMethod {
711 fn sample_full() -> Self {
712 Self::GcodeExtrusion
713 }
714}
715
716impl Sample for ChargeKey {
717 fn sample_full() -> Self {
718 Self::Print {
719 print_id: PrintId::sample_full(),
720 tool: 0,
721 segment: 1,
722 }
723 }
724
725 fn sample_alternates() -> Vec<Self> {
726 vec![Self::Unobserved {
727 origin: "local".to_owned(),
728 file_name: "benchy.gcode".to_owned(),
729 generation: 2,
730 print_number: 7,
731 tool: 0,
732 }]
733 }
734}
735
736impl Sample for FilePosition {
737 fn sample_full() -> Self {
738 Self {
739 bytes: 1_761_607,
740 size_bytes: Some(4_194_304),
741 observed_at: Timestamp::sample_full(),
742 }
743 }
744
745 fn sample_minimal() -> Self {
746 Self {
747 size_bytes: None,
748 ..Self::sample_full()
749 }
750 }
751}
752
753impl Sample for PrintSegmentKey {
754 fn sample_full() -> Self {
755 Self {
756 print_id: PrintId::sample_full(),
757 tool: 0,
758 segment: 1,
759 }
760 }
761}
762
763impl Sample for ChargedFilament {
764 fn sample_full() -> Self {
765 Self {
766 spool_id: spool_id(),
767 grams: 2.98,
768 diameter_mm: 1.75,
769 density_g_cm3: 1.24,
770 remaining_before_g: 745.48,
771 remaining_after_g: 742.5,
772 }
773 }
774}
775
776impl Sample for PendingCharge {
777 fn sample_full() -> Self {
778 Self {
779 charge_key: PrintSegmentKey::sample_full(),
780 length_mm: 1_204.5,
781 method: ChargeMethod::GcodeExtrusion,
782 analysed_length_mm: Some(5_120.0),
783 position: Some(FilePosition::sample_full()),
784 note: Some("fed after the filament change at layer 12".to_owned()),
785 pended_at: later_instant(),
786 }
787 }
788
789 fn sample_minimal() -> Self {
790 Self {
791 method: ChargeMethod::FileFraction,
792 analysed_length_mm: None,
793 position: None,
794 note: None,
795 ..Self::sample_full()
796 }
797 }
798}
799
800impl Sample for PendingTaken {
801 fn sample_full() -> Self {
802 Self {
803 charge_key: ChargeKey::sample_full(),
804 print_id: PrintId::sample_full(),
805 }
806 }
807}
808
809impl Sample for PreflightVerdict {
810 fn sample_full() -> Self {
811 Self::Insufficient
812 }
813}
814
815impl Sample for PreflightSpool {
816 fn sample_full() -> Self {
817 Self {
818 id: spool_id(),
819 name: "Galaxy black".to_owned(),
820 }
821 }
822}
823
824impl Sample for PreflightNeed {
825 fn sample_full() -> Self {
826 Self {
827 required_g: 120.0,
828 buffer_g: 12.0,
829 }
830 }
831}
832
833impl Sample for ShortSpool {
834 fn sample_full() -> Self {
835 Self {
836 spool: PreflightSpool::sample_full(),
837 remaining_g: 80.0,
838 need: PreflightNeed::sample_full(),
839 marks: vec![UnverifiedMark::sample_full()],
840 }
841 }
842
843 fn sample_minimal() -> Self {
844 Self {
845 marks: Vec::new(),
846 ..Self::sample_full()
847 }
848 }
849}
850
851impl Sample for DoubtedSpool {
852 fn sample_full() -> Self {
853 Self {
854 spool: PreflightSpool::sample_full(),
855 remaining_g: 742.5,
856 need: Some(PreflightNeed::sample_full()),
857 marks: UnverifiedMarks::sample_full(),
858 }
859 }
860
861 fn sample_minimal() -> Self {
862 Self {
863 need: None,
864 ..Self::sample_full()
865 }
866 }
867}
868
869impl Sample for UnanalysedSpool {
870 fn sample_full() -> Self {
871 Self {
872 spool: PreflightSpool::sample_full(),
873 remaining_g: 742.5,
874 }
875 }
876}
877
878impl Sample for PreflightObjection {
879 fn sample_full() -> Self {
880 Self::Insufficient(ShortSpool::sample_full())
881 }
882
883 fn sample_minimal() -> Self {
884 Self::NoAnalysis(UnanalysedSpool::sample_full())
885 }
886
887 fn sample_alternates() -> Vec<Self> {
888 vec![
889 Self::Insufficient(ShortSpool::sample_minimal()),
890 Self::UnverifiedSpool(DoubtedSpool::sample_full()),
891 ]
892 }
893}
894
895impl Sample for PreflightToolResult {
896 fn sample_full() -> Self {
897 Self::Insufficient(ShortSpool::sample_full())
898 }
899
900 fn sample_minimal() -> Self {
901 Self::Unchecked
902 }
903
904 fn sample_alternates() -> Vec<Self> {
905 vec![
906 Self::Passed {
907 spool: PreflightSpool::sample_full(),
908 remaining_g: 742.5,
909 need: PreflightNeed::sample_full(),
910 },
911 Self::UnverifiedSpool(DoubtedSpool::sample_minimal()),
912 Self::NoAnalysis(UnanalysedSpool::sample_full()),
913 Self::Overridden {
914 objection: PreflightObjection::sample_full(),
915 },
916 Self::Warned {
917 objection: PreflightObjection::NoAnalysis(UnanalysedSpool::sample_full()),
918 },
919 ]
920 }
921}
922
923impl Sample for PreflightTool {
924 fn sample_full() -> Self {
925 Self {
926 tool: 0,
927 result: PreflightToolResult::sample_full(),
928 }
929 }
930
931 fn sample_minimal() -> Self {
932 Self {
933 tool: 1,
934 result: PreflightToolResult::Unchecked,
935 }
936 }
937}
938
939impl Sample for Preflight {
940 fn sample_full() -> Self {
941 Self {
942 file_name: "benchy.gcode".to_owned(),
943 tools: vec![
944 PreflightTool::sample_full(),
945 PreflightTool::sample_minimal(),
946 ],
947 verdict: PreflightVerdict::Insufficient,
948 material: Some(MaterialResult::sample_full()),
949 sheet: Some(SheetResult::sample_full()),
950 segments: vec![
951 PreflightSegment::sample_full(),
952 PreflightSegment {
953 segment: 1,
954 color: None,
955 filament_mm: 812.4,
956 required_g: None,
957 spool_id: None,
958 },
959 ],
960 checked_at: Timestamp::sample_full(),
961 }
962 }
963
964 fn sample_minimal() -> Self {
965 Self {
966 material: None,
967 sheet: None,
968 segments: Vec::new(),
969 ..Self::sample_full()
970 }
971 }
972}
973
974impl Sample for PreflightSegment {
975 fn sample_full() -> Self {
976 Self {
977 segment: 0,
978 color: Some("#FFFFFF".to_owned()),
979 filament_mm: 301.7,
980 required_g: Some(0.9),
981 spool_id: Some(spool_id()),
982 }
983 }
984}
985
986fn material(name: &str) -> MaterialName {
988 MaterialName::try_from(name.to_owned()).expect("a material named by something")
989}
990
991fn sheet(id: &str) -> SheetId {
993 SheetId::try_from(id.to_owned()).expect("a sheet named by something")
994}
995
996impl Sample for MaterialName {
997 fn sample_full() -> Self {
998 material("PLA")
999 }
1000}
1001
1002impl Sample for SheetId {
1003 fn sample_full() -> Self {
1004 sheet("smooth-pei")
1005 }
1006}
1007
1008impl Sample for MaterialComparison {
1009 fn sample_full() -> Self {
1010 Self {
1011 tool: 0,
1012 spool: PreflightSpool::sample_full(),
1013 loaded: material("PETG"),
1014 sliced_for: material("PLA"),
1015 }
1016 }
1017}
1018
1019impl Sample for UncomparedMaterial {
1020 fn sample_full() -> Self {
1021 Self {
1022 tool: 0,
1023 spool: PreflightSpool::sample_full(),
1024 loaded: material("PETG"),
1025 file_name: FileName::sample_full(),
1026 }
1027 }
1028}
1029
1030impl Sample for MaterialObjection {
1031 fn sample_full() -> Self {
1032 Self::Mismatch(MaterialComparison::sample_full())
1033 }
1034
1035 fn sample_alternates() -> Vec<Self> {
1036 vec![
1037 Self::Undeclared(UncomparedMaterial::sample_full()),
1038 Self::Unread {
1039 tool: 0,
1040 spool: PreflightSpool::sample_full(),
1041 loaded: material("PETG"),
1042 file_name: FileName::sample_full(),
1043 detail: "the printer could not be reached".to_owned(),
1044 },
1045 ]
1046 }
1047}
1048
1049impl Sample for MaterialResult {
1050 fn sample_full() -> Self {
1051 Self::Refused {
1052 objection: MaterialObjection::sample_full(),
1053 }
1054 }
1055
1056 fn sample_minimal() -> Self {
1057 Self::Unchecked
1058 }
1059
1060 fn sample_alternates() -> Vec<Self> {
1061 vec![
1062 Self::Passed(MaterialComparison {
1063 loaded: material("PLA"),
1064 ..MaterialComparison::sample_full()
1065 }),
1066 Self::Overridden {
1067 objection: MaterialObjection::sample_full(),
1068 },
1069 Self::Warned {
1070 objection: MaterialObjection::Undeclared(UncomparedMaterial::sample_full()),
1071 },
1072 ]
1073 }
1074}
1075
1076impl Sample for SheetComparison {
1077 fn sample_full() -> Self {
1078 Self {
1079 sheet: sheet("smooth-pei"),
1080 material: material("PETG"),
1081 allowed: vec![sheet("textured-pei")],
1082 }
1083 }
1084}
1085
1086impl Sample for SheetObjection {
1087 fn sample_full() -> Self {
1088 Self::NotAllowed(SheetComparison::sample_full())
1089 }
1090
1091 fn sample_alternates() -> Vec<Self> {
1092 vec![
1093 Self::UnlistedMaterial {
1094 sheet: sheet("smooth-pei"),
1095 material: material("ASA"),
1096 },
1097 Self::UnknownSheet {
1098 sheet: sheet("glass"),
1099 material: material("PLA"),
1100 known: vec![sheet("smooth-pei"), sheet("textured-pei")],
1101 },
1102 ]
1103 }
1104}
1105
1106impl Sample for SheetResult {
1107 fn sample_full() -> Self {
1108 Self::Refused {
1109 objection: SheetObjection::sample_full(),
1110 }
1111 }
1112
1113 fn sample_minimal() -> Self {
1114 Self::Unchecked
1115 }
1116
1117 fn sample_alternates() -> Vec<Self> {
1118 vec![
1119 Self::Passed(SheetComparison {
1120 sheet: sheet("textured-pei"),
1121 ..SheetComparison::sample_full()
1122 }),
1123 Self::Undeclared,
1124 Self::Overridden {
1125 objection: SheetObjection::sample_full(),
1126 },
1127 Self::Warned {
1128 objection: SheetObjection::sample_full(),
1129 },
1130 ]
1131 }
1132}
1133
1134impl Sample for SpoolCommand {
1135 fn sample_full() -> Self {
1136 Self::RegisterSpool {
1137 name: "Galaxy black".to_owned(),
1138 material: "PLA".to_owned(),
1139 color: Some("black".to_owned()),
1140 diameter_mm: Some(1.75),
1141 density_g_cm3: Some(1.24),
1142 initial_g: 1_000.0,
1143 remaining_g: Some(742.5),
1144 tare_g: Some(250.0),
1145 reason: "a new spool went on the shelf".to_owned(),
1146 actor: Actor::Operator,
1147 }
1148 }
1149
1150 fn sample_minimal() -> Self {
1151 Self::RegisterSpool {
1152 name: "Galaxy black".to_owned(),
1153 material: "PLA".to_owned(),
1154 color: None,
1155 diameter_mm: None,
1156 density_g_cm3: None,
1157 initial_g: 1_000.0,
1158 remaining_g: None,
1159 tare_g: None,
1160 reason: "a new spool went on the shelf".to_owned(),
1161 actor: Actor::Operator,
1162 }
1163 }
1164
1165 fn sample_alternates() -> Vec<Self> {
1166 let reason = || "the spool on the shelf changed".to_owned();
1167 vec![
1168 Self::LoadSpool {
1169 spool_id: spool_id(),
1170 tool: 0,
1171 reason: reason(),
1172 actor: Actor::Operator,
1173 },
1174 Self::UnloadSpool {
1175 spool_id: spool_id(),
1176 reason: reason(),
1177 actor: Actor::Operator,
1178 },
1179 Self::AdjustSpool {
1180 spool_id: spool_id(),
1181 remaining_g: Some(700.0),
1182 gross_g: None,
1183 reason: reason(),
1184 actor: Actor::Operator,
1185 },
1186 Self::AdjustSpool {
1187 spool_id: spool_id(),
1188 remaining_g: None,
1189 gross_g: Some(950.0),
1190 reason: reason(),
1191 actor: Actor::sample_full(),
1192 },
1193 Self::RetireSpool {
1194 spool_id: spool_id(),
1195 reason: reason(),
1196 actor: Actor::Operator,
1197 },
1198 ]
1199 }
1200}