From 4d2a71d028a7c7e565c907e77fda019a0e05c590 Mon Sep 17 00:00:00 2001 From: Kinesin Data Technologies Incorporated <93931750+kinesintech@users.noreply.github.com> Date: Thu, 6 Oct 2022 21:55:18 -0300 Subject: [PATCH] Adding in structure for expected payload --- src/bin/wfd/main.rs | 36 ++++++++++++++++++++++++++++++++++++ src/prelude.rs | 5 ++++- src/runner.rs | 36 ++++++++++++++++++------------------ 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/bin/wfd/main.rs b/src/bin/wfd/main.rs index 4843c34..edf2b57 100644 --- a/src/bin/wfd/main.rs +++ b/src/bin/wfd/main.rs @@ -105,6 +105,42 @@ async fn get_state(state: web::Data) -> 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; 2], + val: ActionState, +} + +struct TimelineLabel { + label: String, + data: Vec, +} + +struct TimelineGroup { + group: String, + data: Vec, +} + async fn timeline(span: web::Query, state: web::Data) -> impl Responder { let interval = span.into_inner(); diff --git a/src/prelude.rs b/src/prelude.rs index 9c100cf..92071a7 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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; diff --git a/src/runner.rs b/src/runner.rs index 3092941..82d2b3c 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -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, DateTime, ActionState)>>>; +pub type ResourceStateDetails = HashMap>>; #[derive(Debug)] pub enum RunnerMessage { @@ -368,12 +367,13 @@ impl Runner { response: oneshot::Sender, ) { // HashMap, DateTime, ActionState)>>>; - let mut res : ResourceStateDetails = HashMap::new(); + let mut res: ResourceStateDetails = HashMap::new(); - let all_resources : HashSet = self.tasks.iter().fold(HashSet::new(), |mut acc, t| { - acc.extend(t.provides.clone()); - acc - }); + let all_resources: HashSet = + self.tasks.iter().fold(HashSet::new(), |mut acc, t| { + acc.extend(t.provides.clone()); + acc + }); // Build out the hash for resource in all_resources { @@ -386,25 +386,25 @@ impl Runner { res.insert(resource.clone(), res_ints); } - let actions = self + let actions: Vec = 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) {