Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ServerData Protobuf to v2, switch internal struct to chrono + f32, update time sourcing logic #216

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/client-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ jobs:
provenance: false
build-args: |
PROD=true
BACKEND_URL=http://192.168.100.1:8000
BACKEND_URL=http://192.168.100.11:8000
MAP_ACCESS_TOKEN=pk.eyJ1IjoibWNrZWVwIiwiYSI6ImNscXBrcmU1ZTBscWIya284cDFyYjR3Nm8ifQ.6TQHlxhAJzptZyV-W28dnw
7 changes: 5 additions & 2 deletions scylla-server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions scylla-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ console-subscriber = { version = "0.3.0", optional = true }
ringbuffer = "0.15.0"
clap = { version = "4.5.11", features = ["derive", "env"] }
axum-extra = { version = "0.9.3", features = ["query"] }
chrono = { version = "0.4.38", features = ["serde"] }
serde_json = "1.0.128"

[features]
top = ["dep:console-subscriber"]
Expand Down
45 changes: 22 additions & 23 deletions scylla-server/prisma/seed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{sync::Arc, time::Duration};

use prisma_client_rust::{chrono, QueryError};
use prisma_client_rust::QueryError;
use scylla_server::{
prisma::PrismaClient,
processors::ClientData,
Expand Down Expand Up @@ -35,8 +35,7 @@ async fn main() -> Result<(), QueryError> {

client.system().delete_many(vec![]).exec().await?;

let created_run =
run_service::create_run(&client, chrono::offset::Utc::now().timestamp_millis()).await?;
let created_run = run_service::create_run(&client, chrono::offset::Utc::now()).await?;

system_service::upsert_system(&client, "Data And Controls".to_string(), created_run.id).await?;
driver_service::upsert_driver(&client, "Fergus".to_string(), created_run.id).await?;
Expand Down Expand Up @@ -67,72 +66,72 @@ async fn main() -> Result<(), QueryError> {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["20".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis(),
values: vec![20f32],
timestamp: chrono::offset::Utc::now(),
node: "BMS".to_string(),
},
ClientData {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["21".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis() + 1000,
values: vec![21f32],
timestamp: chrono::offset::Utc::now() + Duration::from_millis(1000),
node: "BMS".to_string(),
},
ClientData {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["22".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis() + 2000,
values: vec![22f32],
timestamp: chrono::offset::Utc::now() + Duration::from_millis(2000),
node: "BMS".to_string(),
},
ClientData {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["17".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis() + 3000,
values: vec![17f32],
timestamp: chrono::offset::Utc::now() + Duration::from_millis(3000),
node: "BMS".to_string(),
},
ClientData {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["25".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis() + 4000,
values: vec![17f32],
timestamp: chrono::offset::Utc::now() + Duration::from_millis(4000),
node: "BMS".to_string(),
},
ClientData {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["30".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis() + 5000,
values: vec![17f32],
timestamp: chrono::offset::Utc::now() + Duration::from_millis(5000),
node: "BMS".to_string(),
},
ClientData {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["38".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis() + 6000,
values: vec![17f32],
timestamp: chrono::offset::Utc::now() + Duration::from_millis(6000),
node: "BMS".to_string(),
},
ClientData {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["32".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis() + 7000,
values: vec![17f32],
timestamp: chrono::offset::Utc::now() + Duration::from_millis(7000),
node: "BMS".to_string(),
},
ClientData {
run_id: created_run.id,
name: "Pack-Temp".to_string(),
unit: "C".to_string(),
values: vec!["26".to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis() + 8000,
values: vec![17f32],
timestamp: chrono::offset::Utc::now() + Duration::from_millis(8000),
node: "BMS".to_string(),
},
],
Expand Down Expand Up @@ -215,8 +214,8 @@ async fn simulate_route(db: Database, curr_run: i32) -> Result<(), QueryError> {
run_id: curr_run,
name: "Points".to_string(),
unit: "Coord".to_string(),
values: vec![inter_lat.to_string(), inter_long.to_string()],
timestamp: chrono::offset::Utc::now().timestamp_millis(),
values: vec![inter_lat as f32, inter_long as f32],
timestamp: chrono::offset::Utc::now(),
node: "TPU".to_string(),
},
)
Expand Down
4 changes: 1 addition & 3 deletions scylla-server/src/controllers/run_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use axum::{
extract::{Path, State},
Extension, Json,
};
use prisma_client_rust::chrono;
use tokio::sync::mpsc;
use tracing::warn;

Expand Down Expand Up @@ -43,8 +42,7 @@ pub async fn new_run(
State(db): State<Database>,
Extension(channel): Extension<mpsc::Sender<run_service::public_run::Data>>,
) -> Result<Json<PublicRun>, ScyllaError> {
let run_data =
run_service::create_run(&db, chrono::offset::Utc::now().timestamp_millis()).await?;
let run_data = run_service::create_run(&db, chrono::offset::Utc::now()).await?;

// notify the mqtt receiver a new run has been created
if let Err(err) = channel.send(run_data.clone()).await {
Expand Down
3 changes: 1 addition & 2 deletions scylla-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use axum::{
Extension, Router,
};
use clap::Parser;
use prisma_client_rust::chrono;
use rumqttc::v5::AsyncClient;
use scylla_server::{
controllers::{
Expand Down Expand Up @@ -196,7 +195,7 @@ async fn main() {
None
} else {
// creates the initial run
let curr_run = run_service::create_run(&db, chrono::offset::Utc::now().timestamp_millis())
let curr_run = run_service::create_run(&db, chrono::offset::Utc::now())
.await
.expect("Could not create initial run!");
debug!("Configuring current run: {:?}", curr_run);
Expand Down
53 changes: 15 additions & 38 deletions scylla-server/src/processors/db_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use super::{ClientData, LocationData};
/// A struct defining an in progress location packet
struct LocLock {
location_name: Option<String>,
points: Option<(f64, f64)>,
radius: Option<f64>,
points: Option<(f32, f32)>,
radius: Option<f32>,
}

impl LocLock {
Expand All @@ -37,12 +37,12 @@ impl LocLock {
}

/// Add points to the packet
pub fn add_points(&mut self, lat: f64, long: f64) {
pub fn add_points(&mut self, lat: f32, long: f32) {
self.points = Some((lat, long));
}

/// Add a radius to the packet
pub fn add_radius(&mut self, radius: f64) {
pub fn add_radius(&mut self, radius: f32) {
self.radius = Some(radius);
}

Expand Down Expand Up @@ -251,10 +251,7 @@ impl DbHandler {
debug!("Upserting driver: {:?}", msg.values);
if let Err(err) = driver_service::upsert_driver(
&self.db,
msg.values
.first()
.unwrap_or(&"PizzaTheHut".to_string())
.to_string(),
(*msg.values.first().unwrap_or(&0.0f32)).to_string(),
jr1221 marked this conversation as resolved.
Show resolved Hide resolved
msg.run_id,
)
.await
Expand All @@ -264,22 +261,15 @@ impl DbHandler {
}
"location" => {
debug!("Upserting location name: {:?}", msg.values);
self.location_lock.add_loc_name(
msg.values
.first()
.unwrap_or(&"PizzaTheHut".to_string())
.to_string(),
);
self.location_lock
.add_loc_name((*msg.values.first().unwrap_or(&0.0f32)).to_string());
self.is_location = true;
}
"system" => {
debug!("Upserting system: {:?}", msg.values);
if let Err(err) = system_service::upsert_system(
&self.db,
msg.values
.first()
.unwrap_or(&"PizzaTheHut".to_string())
.to_string(),
(*msg.values.first().unwrap_or(&0.0f32)).to_string(),
msg.run_id,
)
.await
Expand All @@ -290,28 +280,15 @@ impl DbHandler {
"GPS-Location" => {
debug!("Upserting location points: {:?}", msg.values);
self.location_lock.add_points(
msg.values
.first()
.unwrap_or(&"PizzaTheHut".to_string())
.parse::<f64>()
.unwrap_or_default(),
msg.values
.get(1)
.unwrap_or(&"PizzaTheHut".to_string())
.parse::<f64>()
.unwrap_or_default(),
*msg.values.first().unwrap_or(&0.0f32),
*msg.values.get(1).unwrap_or(&0.0f32),
);
self.is_location = true;
}
"Radius" => {
debug!("Upserting location radius: {:?}", msg.values);
self.location_lock.add_radius(
msg.values
.first()
.unwrap_or(&"PizzaTheHut".to_string())
.parse::<f64>()
.unwrap_or_default(),
);
self.location_lock
.add_radius(*msg.values.first().unwrap_or(&0.0f32));
self.is_location = true;
}
_ => {}
Expand All @@ -324,9 +301,9 @@ impl DbHandler {
if let Err(err) = location_service::upsert_location(
&self.db,
loc.location_name,
loc.lat,
loc.long,
loc.radius,
loc.lat as f64,
loc.long as f64,
loc.radius as f64,
msg.run_id,
)
.await
Expand Down
15 changes: 1 addition & 14 deletions scylla-server/src/processors/mock_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::mock_processor::{MockData, MockStringData};
use super::mock_processor::MockData;

pub const BASE_MOCK_DATA: [MockData; 17] = [
MockData {
Expand Down Expand Up @@ -121,16 +121,3 @@ pub const BASE_MOCK_DATA: [MockData; 17] = [
max: 600.0,
},
];

pub const BASE_MOCK_STRING_DATA: [MockStringData; 2] = [
MockStringData {
name: "Driver",
unit: "String",
vals: "Fergus",
},
MockStringData {
name: "Location",
unit: "String",
vals: "Max",
},
];
Loading
Loading