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:
2023-06-18 18:43:15 +02:00
parent a5976252e8
commit 962b90e1b8
22 changed files with 440 additions and 397 deletions

View 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,
}
}
}