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 authored and bracyw committed Oct 26, 2024
1 parent 4185c9e commit 7770268
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
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" />
<typography
Expand Down
5 changes: 3 additions & 2 deletions scylla-server/src/controllers/data_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ 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
18 changes: 10 additions & 8 deletions scylla-server/src/services/data_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,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())])
.select(public_data::select())
.find_many(vec![
prisma::data::time::lte(datetime_utc.into()),
prisma::data::time::gte(datetime_30_sec.into()),
])
.select(public_data_with_dataType::select())
.exec()
.await
}
Expand Down
18 changes: 0 additions & 18 deletions scylla-server/src/transformers/data_transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ pub struct PublicDataWithDataType {
pub dataTypeName: 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 @@ -67,17 +60,6 @@ impl From<&data_service::public_data_with_dataType::Data> for PublicDataWithData
}
}

/// 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 7770268

Please sign in to comment.