Skip to content

Commit

Permalink
Merge branch 'develop' into 200-switch-new-run-to-static-atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 authored Oct 25, 2024
2 parents 5de9cc1 + edac72d commit 9aa0127
Show file tree
Hide file tree
Showing 28 changed files with 270 additions and 245 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
cursor: pointer;
display: inline-block;
font-weight: bold;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
font-family: 'Roboto';
font-size: 12px;
color: #cacaca;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.divider-line {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
font-size: 18px;
color: gray;
padding-top: 22px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.mat-icon {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.disable-text-selection {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p [style]="style">{{ content }}</p>
<p class="disable-text-selection" [style]="style">{{ content }}</p>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { StyleVariant } from 'src/utils/enumerations/style-variant';
*/
@Component({
selector: 'typography',
templateUrl: './typography.component.html'
templateUrl: './typography.component.html',
styleUrls: ['./typography.component.css']
})
export default class Typography implements OnInit {
@Input() variant!: StyleVariant;
Expand Down
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
7 changes: 4 additions & 3 deletions scylla-server/src/controllers/run_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use axum::{
extract::{Path, State},
Json,
};
use prisma_client_rust::chrono;

use tokio::sync::mpsc;
use tracing::warn;

use crate::{
error::ScyllaError, services::run_service, transformers::run_transformer::PublicRun, Database,
Expand Down Expand Up @@ -40,8 +42,7 @@ pub async fn get_run_by_id(
/// create a new run with an auto-incremented ID
/// note the new run must be updated so the channel passed in notifies the data processor to use the new run
pub async fn new_run(State(db): State<Database>) -> 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?;

crate::RUN_ID.store(run_data.id, Ordering::Relaxed);

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 @@ -9,7 +9,6 @@ use axum::{
Extension, Router,
};
use clap::Parser;
use prisma_client_rust::chrono;
use rumqttc::v5::AsyncClient;
use scylla_server::RUN_ID;
use scylla_server::{
Expand Down Expand Up @@ -197,7 +196,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
56 changes: 18 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 @@ -247,39 +247,32 @@ impl DbHandler {

// if data has some special meanings, push them to the database immediately, notably no matter what also enter batching logic
match msg.name.as_str() {
// TODO remove driver from here, as driver is not car sourced
"Driver" => {
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(),
msg.run_id,
)
.await
{
warn!("Driver upsert error: {:?}", err);
}
}
// TODO see above
"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;
}
// TODO see above
"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 +283,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 +304,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
Loading

0 comments on commit 9aa0127

Please sign in to comment.