Adding in structure for expected payload

This commit is contained in:
Kinesin Data Technologies Incorporated
2022-10-06 21:55:18 -03:00
parent 6f5f890b1e
commit 4d2a71d028
3 changed files with 58 additions and 19 deletions
+36
View File
@@ -105,6 +105,42 @@ async fn get_state(state: web::Data<AppState>) -> impl Responder {
}
}
/*
Generates the data structure for [timelines-chart](https://github.com/vasturiano/timelines-chart)
[
{
"group": "resource",
"data": [
{
label: "task_name",
"data": [
{
"timeRange": [ "start", "end" ],
"val": "State"
},
]
}
]
}
]
*/
struct TimelineInterval {
time_range: [DateTime<Utc>; 2],
val: ActionState,
}
struct TimelineLabel {
label: String,
data: Vec<TimelineInterval>,
}
struct TimelineGroup {
group: String,
data: Vec<TimelineLabel>,
}
async fn timeline(span: web::Query<Interval>, state: web::Data<AppState>) -> impl Responder {
let interval = span.into_inner();
+4 -1
View File
@@ -1,7 +1,10 @@
pub use chrono::prelude::*;
pub use chrono_tz::*;
pub use crate::calendar::Calendar;
pub use crate::executors::*;
pub use crate::interval::Interval;
pub use crate::runner::{Runner, RunnerMessage};
pub use crate::runner::{ActionState, Runner, RunnerMessage};
pub use crate::storage::*;
pub use crate::task::{TaskDefinition, TaskResources};
pub use crate::world::WorldDefinition;
+15 -15
View File
@@ -13,7 +13,7 @@ use std::collections::VecDeque;
- current = TaskSet::coverage (the theoretical)
*/
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
pub enum ActionState {
Queued,
Running,
@@ -21,7 +21,7 @@ pub enum ActionState {
Completed,
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy, Serialize)]
pub struct Action {
task: usize,
interval: Interval,
@@ -37,8 +37,7 @@ pub struct RunnerState {
// Eventually we want to coerce the data into this format for timelines-chart
// Resource (group) -> Task (label) -> data [ { "timeRange": [date,date], "val": state } ]
pub type ResourceStateDetails =
HashMap<Resource, HashMap<String, Vec<(DateTime<Utc>, DateTime<Utc>, ActionState)>>>;
pub type ResourceStateDetails = HashMap<Resource, HashMap<String, Vec<Action>>>;
#[derive(Debug)]
pub enum RunnerMessage {
@@ -368,9 +367,10 @@ impl Runner {
response: oneshot::Sender<ResourceStateDetails>,
) {
// HashMap<Resource, HashMap<String, Vec<(DateTime<Utc>, DateTime<Utc>, ActionState)>>>;
let mut res : ResourceStateDetails = HashMap::new();
let mut res: ResourceStateDetails = HashMap::new();
let all_resources : HashSet<Resource> = self.tasks.iter().fold(HashSet::new(), |mut acc, t| {
let all_resources: HashSet<Resource> =
self.tasks.iter().fold(HashSet::new(), |mut acc, t| {
acc.extend(t.provides.clone());
acc
});
@@ -386,25 +386,25 @@ impl Runner {
res.insert(resource.clone(), res_ints);
}
let actions = self
let actions: Vec<Action> = self
.actions
.iter()
.filter(|x| interval.is_contiguous(x.interval))
.cloned()
.collect();
for action in actions {
let task = &self.tasks[action.task];
for resource in task.provides {
res.entry(resource.clone()).or_insert(HashMap::new()).entry(task.name).or_insert(Hash
for resource in &task.provides {
res.get_mut(resource)
.unwrap()
.get_mut(&task.name)
.unwrap()
.push(action);
}
}
for task in &self.tasks {
for resource in &task.provides {}
}
response.send(res);
response.send(res).unwrap();
}
pub async fn run(&mut self, mut stay_up: bool) {