scout_rs 0.95.95

A Rust client for the synchornizing state with the Scout database
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
// V10: hard swap of Tag.detector -> Tag.model_id; drops score / score_source.
// Mirrors migration 120 (database). TagLocal is native_model id 17, version 5.

use native_db::{native_db, ToKey};
use native_model::{native_model, Model};
use serde::{Deserialize, Serialize};

// ===== TAG (id 17, version 5) - model_id replaces detector; score/score_source removed =====
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[native_model(id = 17, version = 5)]
#[native_db]
pub struct TagLocal {
    pub id: Option<i64>,
    #[primary_key]
    pub id_local: Option<String>,
    pub inserted_at: Option<String>,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub conf: f64,
    pub observation_type: super::v1::TagObservationType,
    #[serde(rename = "class")]
    pub class: String,
    #[secondary_key]
    pub event_id: Option<i64>,
    #[secondary_key]
    pub ancestor_id_local: Option<String>,
    pub origin_location: Option<String>,
    pub origin_pitch: Option<f64>,
    pub origin_heading: Option<f64>,
    pub origin_roll: Option<f64>,
    pub sensor_pitch: Option<f64>,
    pub sensor_yaw: Option<f64>,
    pub sensor_roll: Option<f64>,
    pub origin_height: Option<f64>,
    pub subject_location: Option<String>,
    pub subject_height: Option<f64>,
    pub artifact_id: Option<i64>,
    pub timestamp_observation: Option<String>,
    pub frame_index: Option<i64>,
    #[serde(default)]
    pub subject_id: Option<i64>,
    #[serde(default)]
    pub model_id: Option<i64>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Tag {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inserted_at: Option<String>,
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
    pub conf: f64,
    pub observation_type: super::v1::TagObservationType,
    #[serde(rename = "class")]
    pub class: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_id: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub origin_location: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub origin_pitch: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub origin_heading: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub origin_roll: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sensor_pitch: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sensor_yaw: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sensor_roll: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub origin_height: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subject_location: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subject_height: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub artifact_id: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timestamp_observation: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub frame_index: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subject_id: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub model_id: Option<i64>,
}

impl Default for TagLocal {
    fn default() -> Self {
        Self {
            id: None,
            id_local: None,
            inserted_at: None,
            x: 0.0,
            y: 0.0,
            width: 0.0,
            height: 0.0,
            conf: 0.0,
            observation_type: super::v1::TagObservationType::Auto,
            class: String::new(),
            event_id: None,
            ancestor_id_local: None,
            origin_location: None,
            origin_pitch: None,
            origin_heading: None,
            origin_roll: None,
            sensor_pitch: None,
            sensor_yaw: None,
            sensor_roll: None,
            origin_height: None,
            subject_location: None,
            subject_height: None,
            artifact_id: None,
            timestamp_observation: None,
            frame_index: None,
            subject_id: None,
            model_id: None,
        }
    }
}

impl Default for Tag {
    fn default() -> Self {
        Self {
            id: None,
            inserted_at: None,
            x: 0.0,
            y: 0.0,
            width: 0.0,
            height: 0.0,
            conf: 0.0,
            observation_type: super::v1::TagObservationType::Manual,
            class: String::new(),
            event_id: None,
            origin_location: None,
            origin_pitch: None,
            origin_heading: None,
            origin_roll: None,
            sensor_pitch: None,
            sensor_yaw: None,
            sensor_roll: None,
            origin_height: None,
            subject_location: None,
            subject_height: None,
            artifact_id: None,
            timestamp_observation: None,
            frame_index: None,
            subject_id: None,
            model_id: None,
        }
    }
}

impl super::v1::Syncable for TagLocal {
    fn id(&self) -> Option<i64> {
        self.id
    }
    fn set_id(&mut self, id: i64) {
        self.id = Some(id);
    }
    fn id_local(&self) -> Option<String> {
        self.id_local.clone()
    }
    fn set_id_local(&mut self, id_local: String) {
        self.id_local = Some(id_local);
    }
}

impl super::v1::Syncable for Tag {
    fn id(&self) -> Option<i64> {
        self.id
    }
    fn set_id(&mut self, id: i64) {
        self.id = Some(id);
    }
    fn id_local(&self) -> Option<String> {
        None
    }
    fn set_id_local(&mut self, _: String) {}
}

impl super::v1::AncestorLocal for TagLocal {
    fn ancestor_id_local(&self) -> Option<String> {
        self.ancestor_id_local.clone()
    }
    fn set_ancestor_id_local(&mut self, ancestor_id_local: String) {
        self.ancestor_id_local = Some(ancestor_id_local);
    }
}

impl From<TagLocal> for Tag {
    fn from(local: TagLocal) -> Self {
        Self {
            id: local.id,
            inserted_at: local.inserted_at,
            x: local.x,
            y: local.y,
            width: local.width,
            height: local.height,
            conf: local.conf,
            observation_type: local.observation_type,
            class: local.class,
            event_id: local.event_id,
            origin_location: local.origin_location,
            origin_pitch: local.origin_pitch,
            origin_heading: local.origin_heading,
            origin_roll: local.origin_roll,
            sensor_pitch: local.sensor_pitch,
            sensor_yaw: local.sensor_yaw,
            sensor_roll: local.sensor_roll,
            origin_height: local.origin_height,
            subject_location: local.subject_location,
            subject_height: local.subject_height,
            artifact_id: local.artifact_id,
            timestamp_observation: local.timestamp_observation,
            frame_index: local.frame_index,
            subject_id: local.subject_id,
            model_id: local.model_id,
        }
    }
}

impl From<Tag> for TagLocal {
    fn from(tag: Tag) -> Self {
        Self {
            id: tag.id,
            id_local: None,
            inserted_at: tag.inserted_at,
            x: tag.x,
            y: tag.y,
            width: tag.width,
            height: tag.height,
            conf: tag.conf,
            observation_type: tag.observation_type,
            class: tag.class,
            event_id: tag.event_id,
            ancestor_id_local: None,
            origin_location: tag.origin_location,
            origin_pitch: tag.origin_pitch,
            origin_heading: tag.origin_heading,
            origin_roll: tag.origin_roll,
            sensor_pitch: tag.sensor_pitch,
            sensor_yaw: tag.sensor_yaw,
            sensor_roll: tag.sensor_roll,
            origin_height: tag.origin_height,
            subject_location: tag.subject_location,
            subject_height: tag.subject_height,
            artifact_id: tag.artifact_id,
            timestamp_observation: tag.timestamp_observation,
            frame_index: tag.frame_index,
            subject_id: tag.subject_id,
            model_id: tag.model_id,
        }
    }
}

// Upgrade from version 4 (v8::TagLocal): detector/score/score_source dropped, model_id starts NULL.
impl From<super::v8::TagLocal> for TagLocal {
    fn from(prev: super::v8::TagLocal) -> Self {
        Self {
            id: prev.id,
            id_local: prev.id_local,
            inserted_at: prev.inserted_at,
            x: prev.x,
            y: prev.y,
            width: prev.width,
            height: prev.height,
            conf: prev.conf,
            observation_type: prev.observation_type,
            class: prev.class,
            event_id: prev.event_id,
            ancestor_id_local: prev.ancestor_id_local,
            origin_location: prev.origin_location,
            origin_pitch: prev.origin_pitch,
            origin_heading: prev.origin_heading,
            origin_roll: prev.origin_roll,
            sensor_pitch: prev.sensor_pitch,
            sensor_yaw: prev.sensor_yaw,
            sensor_roll: prev.sensor_roll,
            origin_height: prev.origin_height,
            subject_location: prev.subject_location,
            subject_height: prev.subject_height,
            artifact_id: prev.artifact_id,
            timestamp_observation: prev.timestamp_observation,
            frame_index: prev.frame_index,
            subject_id: prev.subject_id,
            model_id: None,
        }
    }
}

impl Tag {
    pub fn new(
        _class_id: i64,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
        conf: f64,
        observation_type: super::v1::TagObservationType,
        class: String,
    ) -> Self {
        Self {
            x,
            y,
            width,
            height,
            conf,
            observation_type,
            class,
            ..Default::default()
        }
    }
    pub fn new_with_location(
        _class_id: i64,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
        conf: f64,
        observation_type: super::v1::TagObservationType,
        class: String,
        latitude: f64,
        longitude: f64,
    ) -> Self {
        let mut tag = Self::new(
            _class_id,
            x,
            y,
            width,
            height,
            conf,
            observation_type,
            class,
        );
        tag.set_location(latitude, longitude);
        tag
    }
    pub fn update_event_id(&mut self, event_id: i64) {
        self.event_id = Some(event_id);
    }
    pub fn set_location(&mut self, latitude: f64, longitude: f64) {
        self.origin_location = Some(Self::format_location(latitude, longitude));
    }
    pub fn clear_location(&mut self) {
        self.origin_location = None;
    }
    pub fn format_location(latitude: f64, longitude: f64) -> String {
        format!("POINT({} {})", longitude, latitude)
    }
    pub fn parse_location(location: &str) -> Option<(f64, f64)> {
        if let Some(coords) = location
            .strip_prefix("POINT(")
            .and_then(|s| s.strip_suffix(")"))
        {
            let parts: Vec<&str> = coords.split_whitespace().collect();
            if parts.len() == 2 {
                if let (Ok(lon), Ok(lat)) = (parts[0].parse::<f64>(), parts[1].parse::<f64>()) {
                    return Some((lat, lon));
                }
            }
        }
        None
    }
    pub fn get_coordinates(&self) -> Option<(f64, f64)> {
        self.origin_location
            .as_ref()
            .and_then(|loc| Self::parse_location(loc))
    }
}

impl TagLocal {
    pub fn new(
        _class_id: i64,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
        conf: f64,
        observation_type: super::v1::TagObservationType,
        class: String,
    ) -> Self {
        Self {
            x,
            y,
            width,
            height,
            conf,
            observation_type,
            class,
            ..Default::default()
        }
    }
    pub fn new_with_location(
        _class_id: i64,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
        conf: f64,
        observation_type: super::v1::TagObservationType,
        class: String,
        latitude: f64,
        longitude: f64,
    ) -> Self {
        let mut tag = Self::new(
            _class_id,
            x,
            y,
            width,
            height,
            conf,
            observation_type,
            class,
        );
        tag.set_location(latitude, longitude);
        tag
    }
    pub fn update_event_id(&mut self, event_id: i64) {
        self.event_id = Some(event_id);
    }
    pub fn update_ancestor_id_local(&mut self, ancestor_id_local: String) {
        self.ancestor_id_local = Some(ancestor_id_local);
    }
    pub fn set_location(&mut self, latitude: f64, longitude: f64) {
        self.origin_location = Some(Self::format_location(latitude, longitude));
    }
    pub fn clear_location(&mut self) {
        self.origin_location = None;
    }
    pub fn format_location(latitude: f64, longitude: f64) -> String {
        format!("POINT({} {})", longitude, latitude)
    }
    pub fn parse_location(location: &str) -> Option<(f64, f64)> {
        if let Some(coords) = location
            .strip_prefix("POINT(")
            .and_then(|s| s.strip_suffix(")"))
        {
            let parts: Vec<&str> = coords.split_whitespace().collect();
            if parts.len() == 2 {
                if let (Ok(lon), Ok(lat)) = (parts[0].parse::<f64>(), parts[1].parse::<f64>()) {
                    return Some((lat, lon));
                }
            }
        }
        None
    }
    pub fn get_coordinates(&self) -> Option<(f64, f64)> {
        self.origin_location
            .as_ref()
            .and_then(|loc| Self::parse_location(loc))
    }
}