adds initial user defined panels

This commit is contained in:
2025-12-23 16:41:21 -05:00
parent a110aa6376
commit ebbf864af9
33 changed files with 2188 additions and 370 deletions

View File

@@ -0,0 +1,79 @@
use crate::http::error::HttpServerResultError;
use crate::telemetry::management_service::TelemetryManagementService;
use actix_web::{get, web, Responder};
use chrono::{DateTime, TimeDelta, Utc};
use log::trace;
use serde::Deserialize;
use std::sync::Arc;
use std::time::Duration;
use tokio::time::timeout;
#[get("/tlm/info/{name:[\\w\\d/_-]+}")]
pub(super) async fn get_tlm_definition(
data: web::Data<Arc<TelemetryManagementService>>,
name: web::Path<String>,
) -> Result<impl Responder, HttpServerResultError> {
let string = name.to_string();
trace!("get_tlm_definition {}", string);
let Some(data) = data.get_by_name(&string) else {
return Err(HttpServerResultError::TlmNameNotFound { tlm: string });
};
Ok(web::Json(data.definition.clone()))
}
#[get("/tlm/info")]
pub(super) async fn get_all_tlm_definitions(
data: web::Data<Arc<TelemetryManagementService>>,
) -> Result<impl Responder, HttpServerResultError> {
trace!("get_all_tlm_definitions");
Ok(web::Json(data.get_all_definitions()))
}
#[derive(Deserialize)]
struct HistoryQuery {
from: String,
to: String,
resolution: i64,
}
#[get("/tlm/history/{uuid:[0-9a-f]+}")]
pub(super) async fn get_tlm_history(
data_arc: web::Data<Arc<TelemetryManagementService>>,
uuid: web::Path<String>,
info: web::Query<HistoryQuery>,
) -> Result<impl Responder, HttpServerResultError> {
let uuid = uuid.to_string();
trace!(
"get_tlm_history {} from {} to {} resolution {}",
uuid,
info.from,
info.to,
info.resolution
);
let Ok(from) = info.from.parse::<DateTime<Utc>>() else {
return Err(HttpServerResultError::InvalidDateTime {
date_time: info.from.clone(),
});
};
let Ok(to) = info.to.parse::<DateTime<Utc>>() else {
return Err(HttpServerResultError::InvalidDateTime {
date_time: info.to.clone(),
});
};
let maximum_resolution = TimeDelta::milliseconds(info.resolution);
let history_service = data_arc.history_service();
let data = data_arc.pin();
match data.get_by_uuid(&uuid) {
None => Err(HttpServerResultError::TlmUuidNotFound { uuid }),
Some(tlm) => timeout(
Duration::from_secs(10),
tlm.get(from, to, maximum_resolution, &history_service),
)
.await
.map(|result| Ok(web::Json(result)))
.unwrap_or_else(|_| Err(HttpServerResultError::Timeout)),
}
}