printobserver_printer_api/
file.rs1use printobserver_types::Timestamp;
10use printobserver_types::contract::Sample;
11use printobserver_types::schemars::JsonSchema;
12use printobserver_types::serde::{Deserialize, Serialize};
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
16#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
17#[schemars(crate = "printobserver_types::schemars")]
18pub struct ToolFilament {
19 pub tool: i64,
21 pub length_mm: f64,
23 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub volume_cm3: Option<f64>,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
31#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
32#[schemars(crate = "printobserver_types::schemars")]
33pub struct FilePrint {
34 pub at: Timestamp,
36 pub success: bool,
39}
40
41#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
43#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
44#[schemars(crate = "printobserver_types::schemars")]
45pub struct FileFacts {
46 pub file_name: String,
48 pub origin: String,
50 #[serde(default, skip_serializing_if = "Option::is_none")]
52 pub size_bytes: Option<i64>,
53 #[serde(default, skip_serializing_if = "Option::is_none")]
58 pub filament: Option<Vec<ToolFilament>>,
59 pub successes: i64,
61 pub failures: i64,
63 #[serde(default, skip_serializing_if = "Option::is_none")]
65 pub last_print: Option<FilePrint>,
66}
67
68impl Sample for ToolFilament {
69 fn sample_full() -> Self {
70 Self {
71 tool: 0,
72 length_mm: 1_000.0,
73 volume_cm3: Some(2.41),
74 }
75 }
76
77 fn sample_minimal() -> Self {
78 Self {
79 volume_cm3: None,
80 ..Self::sample_full()
81 }
82 }
83}
84
85impl Sample for FilePrint {
86 fn sample_full() -> Self {
87 Self {
88 at: Timestamp::sample_full(),
89 success: true,
90 }
91 }
92}
93
94impl Sample for FileFacts {
95 fn sample_full() -> Self {
96 Self {
97 file_name: "benchy.gcode".to_owned(),
98 origin: "local".to_owned(),
99 size_bytes: Some(4_194_304),
100 filament: Some(vec![ToolFilament::sample_full()]),
101 successes: 3,
102 failures: 1,
103 last_print: Some(FilePrint::sample_full()),
104 }
105 }
106
107 fn sample_minimal() -> Self {
108 Self {
109 file_name: "benchy.gcode".to_owned(),
110 origin: "sdcard".to_owned(),
111 size_bytes: None,
112 filament: None,
113 successes: 0,
114 failures: 0,
115 last_print: None,
116 }
117 }
118}
119
120#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
123#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
124#[schemars(crate = "printobserver_types::schemars")]
125pub struct Footprint {
126 pub min_x: f64,
128 pub min_y: f64,
130 pub max_x: f64,
132 pub max_y: f64,
134}
135
136#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
139#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
140#[schemars(crate = "printobserver_types::schemars")]
141pub struct PrintedExtent {
142 pub tallest_mm: f64,
144 pub footprint: Footprint,
146}
147
148impl Sample for Footprint {
149 fn sample_full() -> Self {
150 Self {
151 min_x: 90.0,
152 min_y: 90.0,
153 max_x: 110.0,
154 max_y: 110.0,
155 }
156 }
157
158 fn sample_minimal() -> Self {
159 Self {
160 min_x: 0.0,
161 min_y: 0.0,
162 max_x: 0.0,
163 max_y: 0.0,
164 }
165 }
166}
167
168impl Sample for PrintedExtent {
169 fn sample_full() -> Self {
170 Self {
171 tallest_mm: 6.0,
172 footprint: Footprint::sample_full(),
173 }
174 }
175
176 fn sample_minimal() -> Self {
177 Self {
178 tallest_mm: 0.2,
179 footprint: Footprint::sample_minimal(),
180 }
181 }
182}