Skip to content

Commit

Permalink
#156 - querying data with datatypename 30 sec before fault
Browse files Browse the repository at this point in the history
  • Loading branch information
RChandler234 committed Sep 26, 2024
1 parent 6bce55b commit faae121
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
? 'background-color: #d4760b ; width: 100%; border-radius: 2px'
: 'background-color: #4d453c; width: 100%; border-radius: 2px'
"
(click)="setSelectedFault(fault)"
>
<div style="display: flex; flex-direction: row; justify-content: space-between; height: 45px; padding: 10px">
<typography variant="info-subtitle" [content]="fault.type" style="align-self: center"></typography>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from '@angular/core';
import { Component, Input } from '@angular/core';
import Storage from 'src/services/storage.service';
import { IdentifierDataType } from 'src/utils/enumerations/identifier-data-type';

Expand Down Expand Up @@ -34,6 +34,7 @@ enum FaultType {
styleUrls: ['./fault-log.component.css']
})
export default class FaultLog {
@Input() setSelectedFault!: (fault: { type: string; name: string; time: string; displayTime: string }) => void;
faults: { type: string; name: string; time: string; displayTime: string }[] = [];
faultsShifted: boolean = false;
resetButton = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<latency-display style="margin-bottom: -30px; margin-top: -10px" />
</div>
<div style="align-self: end; width: 100%; display: flex; justify-content: space-around">
<fault-log style="width: 30%" />
<fault-log style="width: 30%" [setSelectedFault]="setSelectedFault" />
<fault-box style="width: 35%" />
<graph-sidebar-desktop style="width: 30%" [nodes]="[]" [selectDataType]="onSelectDataType" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class FaultPage implements OnInit {
}, 1000);

this.setSelectedFault = (fault: { type: string; name: string; time: string; displayTime: string }) => {
console.log(fault);
const dataQueryResponse = this.serverService.query<DataValue[]>(() => getDataByDatetime(fault.time));
dataQueryResponse.isLoading.subscribe((isLoading: boolean) => {
this.selectedFaultDataValuesIsLoading = isLoading;
Expand Down
6 changes: 3 additions & 3 deletions scylla-server/src/controllers/data_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::{
};

use crate::{
error::ScyllaError, services::data_service, transformers::data_transformer::PublicData,
error::ScyllaError, services::data_service, transformers::data_transformer::PublicData, transformers::data_transformer::PublicDataWithDataType,
Database,
};

Expand All @@ -26,11 +26,11 @@ pub async fn get_data(
pub async fn get_data_by_datetime(
State(db): State<Database>,
Path(datetime): Path<String>,
) -> Result<Json<Vec<PublicData>>, ScyllaError> {
) -> Result<Json<Vec<PublicDataWithDataType>>, ScyllaError> {
let data = data_service::get_data_by_datetime(&db, datetime).await?;

// map data to frontend data types according to the From func of the client struct
let mut transformed_data: Vec<PublicData> = data.iter().map(PublicData::from).collect();
let mut transformed_data: Vec<PublicDataWithDataType> = data.iter().map(PublicDataWithDataType::from).collect();
transformed_data.sort();

Ok(Json::from(transformed_data))
Expand Down
28 changes: 16 additions & 12 deletions scylla-server/src/services/data_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ prisma::data::select! {public_data {
values
}}

/// Get datapoints that mach criteria
prisma::data::select! {public_data_with_dataType {
time
values
data_type_name
}}

/// Get datapoints that match criteria
/// * `db` - The prisma client to make the call to
/// * `data_type_name` - The data type name to filter the data by
/// * `run_id` - The run id to filter the data
/// * `fetch_run` whether to fetch the run assocaited with this data
/// * `fetch_data_type` whether to fetch the data type associated with this data
/// returns: A result containing the data or the QueryError propogated by the db
pub async fn get_data(
db: &Database,
Expand All @@ -30,25 +34,25 @@ pub async fn get_data(
.await
}

/// Get datapoints that mach criteria
/// Get all datapoints from the 30 seconds preceding the fault received
/// * `db` - The prisma client to make the call to
/// * `data_type_name` - The data type name to filter the data by
/// * `run_id` - The run id to filter the data
/// * `fetch_run` whether to fetch the run assocaited with this data
/// * `fetch_data_type` whether to fetch the data type associated with this data
/// * `datetime` - The datetime in unix time since epoch in ms
/// returns: A result containing the data or the QueryError propogated by the db
pub async fn get_data_by_datetime(
db: &Database,
datetime: String,
) -> Result<Vec<public_data::Data>, QueryError> {
) -> Result<Vec<public_data_with_dataType::Data>, QueryError> {
let datetime_utc = DateTime::from_timestamp_millis(datetime.parse::<i64>().unwrap())
.expect("Could not parse timestamp");
let datetime_30_sec = DateTime::from_timestamp_millis(datetime.parse::<i64>().unwrap() - 30000)
.expect("Could not parse timestamp");

db.data()
.find_many(vec![
prisma::data::time::equals(datetime_utc.into()),
prisma::data::time::lte(datetime_utc.into()),
prisma::data::time::gte(datetime_30_sec.into()),
])
.select(public_data::select())
.select(public_data_with_dataType::select())
.exec()
.await
}
Expand All @@ -58,7 +62,7 @@ pub async fn get_data_by_datetime(
/// * `serverdata` - The protobuf message to parse, note the unit is ignored!
/// * `unix_time` - The time im miliseconds since unix epoch of the message
/// * `data_type_name` - The name of the data type, note this data type must already exist!
/// * `rin_id` - The run id to assign the data point to, note this run must already exist!
/// * `run_id` - The run id to assign the data point to, note this run must already exist!
/// returns: A result containing the data or the QueryError propogated by the db
pub async fn add_data(
db: &Database,
Expand Down
18 changes: 18 additions & 0 deletions scylla-server/src/transformers/data_transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ pub struct PublicData {
pub values: Vec<String>,
}

#[derive(Serialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct PublicDataWithDataType {
pub time: i64,
pub values: Vec<String>,
pub dataTypeName: String,
}

/// convert the prisma type to the client type for JSON encoding
impl From<&data_service::public_data::Data> for PublicData {
fn from(value: &data_service::public_data::Data) -> Self {
Expand All @@ -19,6 +26,17 @@ impl From<&data_service::public_data::Data> for PublicData {
}
}

/// convert the prisma type to the client type for JSON encoding
impl From<&data_service::public_data_with_dataType::Data> for PublicDataWithDataType {
fn from(value: &data_service::public_data_with_dataType::Data) -> Self {
PublicDataWithDataType {
values: value.values.iter().map(f64::to_string).collect(),
time: value.time.timestamp_millis(),
dataTypeName: value.data_type_name.clone(),
}
}
}

/// convert from the client (socket) type to the client type, for debugging and testing only probably
impl From<ClientData> for PublicData {
fn from(value: ClientData) -> Self {
Expand Down

0 comments on commit faae121

Please sign in to comment.