Refactor Models for InfluxDB (#1)
Update to InfluxDB 2.0 and update all interfaces to work with it. MAC has been deprecated, since current `influxdb2` doesn't support non built-in types for read/write into the DB. Co-authored-by: Felipe Diniello <felipediniello@pm.me> Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
31
kairo-common/src/models/known_position.rs
Normal file
31
kairo-common/src/models/known_position.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use influxdb2_derive::{FromDataPoint, WriteDataPoint};
|
||||
|
||||
use crate::Point;
|
||||
|
||||
#[derive(
|
||||
Debug, Default, PartialEq, Clone, Serialize, Deserialize, FromDataPoint, WriteDataPoint,
|
||||
)]
|
||||
#[measurement = "known_positions"]
|
||||
pub struct KnownPosition {
|
||||
#[influxdb(tag)]
|
||||
pub id: String,
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
pub z: f64,
|
||||
#[influxdb(timestamp)]
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
impl KnownPosition {
|
||||
pub fn new(device_id: &str, pos: Point) -> KnownPosition {
|
||||
KnownPosition {
|
||||
id: device_id.into(),
|
||||
time: chrono::Utc::now().timestamp_nanos(),
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
z: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user