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:
@@ -1,10 +1,9 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use influxdb::InfluxDbWriteable;
|
||||
use kairo_common::helper::for_async::get_influx_cli;
|
||||
use serde::Serialize;
|
||||
use tokio::time;
|
||||
|
||||
use kairo_common::{influxdb_models::KnownPosition, Point};
|
||||
use kairo_common::Point;
|
||||
|
||||
use crate::Config;
|
||||
|
||||
@@ -14,7 +13,7 @@ pub struct Error {
|
||||
speed: f64,
|
||||
time: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn thread(config: Config) {
|
||||
let period = time::Duration::from_millis(500);
|
||||
|
||||
@@ -23,37 +22,37 @@ pub async fn thread(config: Config) {
|
||||
position.rotate_by(f64::to_radians(config.angle_step));
|
||||
speed -= position;
|
||||
|
||||
let speed = speed.module();
|
||||
let _speed = speed.module();
|
||||
|
||||
loop {
|
||||
let start = time::Instant::now();
|
||||
|
||||
let real = KnownPosition::get_last_for("real", 1).await;
|
||||
let calc = KnownPosition::get_last_for(config.id.as_str(), 1).await;
|
||||
if real.is_ok() && calc.is_ok() {
|
||||
let real = real.unwrap();
|
||||
let calc = calc.unwrap();
|
||||
// let real = KnownPosition::get_last_for("real", 1).await;
|
||||
// let calc = KnownPosition::get_last_for(config.id.as_str(), 1).await;
|
||||
// if real.is_ok() && calc.is_ok() {
|
||||
// let real = real.unwrap();
|
||||
// let calc = calc.unwrap();
|
||||
|
||||
if real.is_some() && calc.is_some() {
|
||||
let real = real.unwrap();
|
||||
let calc = calc.unwrap();
|
||||
#[allow(non_snake_case)]
|
||||
let Δx = real.x - calc.x;
|
||||
#[allow(non_snake_case)]
|
||||
let Δy = real.y - calc.y;
|
||||
let error = Error {
|
||||
speed,
|
||||
error: f64::sqrt(Δx.powi(2) + Δy.powi(2)),
|
||||
time: chrono::Utc::now(),
|
||||
};
|
||||
// if real.is_some() && calc.is_some() {
|
||||
// let real = real.unwrap();
|
||||
// let calc = calc.unwrap();
|
||||
// #[allow(non_snake_case)]
|
||||
// let Δx = real.x - calc.x;
|
||||
// #[allow(non_snake_case)]
|
||||
// let Δy = real.y - calc.y;
|
||||
// let error = Error {
|
||||
// speed,
|
||||
// error: f64::sqrt(Δx.powi(2) + Δy.powi(2)),
|
||||
// time: chrono::Utc::now(),
|
||||
// };
|
||||
|
||||
let table_name = format!("error_{}", config.id.as_str());
|
||||
get_influx_cli()
|
||||
.query(error.into_query(table_name.as_str()))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
time::sleep(period - start.elapsed()).await;
|
||||
}
|
||||
// let table_name = format!("error_{}", config.id.as_str());
|
||||
// get_influx_cli()
|
||||
// .query(error.into_query(table_name.as_str()))
|
||||
// .await
|
||||
// .unwrap();
|
||||
// }
|
||||
time::sleep(period - start.elapsed()).await;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user