Adding in structure for expected payload
This commit is contained in:
parent
6f5f890b1e
commit
4d2a71d028
@@ -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 {
|
async fn timeline(span: web::Query<Interval>, state: web::Data<AppState>) -> impl Responder {
|
||||||
let interval = span.into_inner();
|
let interval = span.into_inner();
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -1,7 +1,10 @@
|
|||||||
|
pub use chrono::prelude::*;
|
||||||
|
pub use chrono_tz::*;
|
||||||
|
|
||||||
pub use crate::calendar::Calendar;
|
pub use crate::calendar::Calendar;
|
||||||
pub use crate::executors::*;
|
pub use crate::executors::*;
|
||||||
pub use crate::interval::Interval;
|
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::storage::*;
|
||||||
pub use crate::task::{TaskDefinition, TaskResources};
|
pub use crate::task::{TaskDefinition, TaskResources};
|
||||||
pub use crate::world::WorldDefinition;
|
pub use crate::world::WorldDefinition;
|
||||||
|
|||||||
+15
-15
@@ -13,7 +13,7 @@ use std::collections::VecDeque;
|
|||||||
- current = TaskSet::coverage (the theoretical)
|
- current = TaskSet::coverage (the theoretical)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
|
||||||
pub enum ActionState {
|
pub enum ActionState {
|
||||||
Queued,
|
Queued,
|
||||||
Running,
|
Running,
|
||||||
@@ -21,7 +21,7 @@ pub enum ActionState {
|
|||||||
Completed,
|
Completed,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy, Serialize)]
|
||||||
pub struct Action {
|
pub struct Action {
|
||||||
task: usize,
|
task: usize,
|
||||||
interval: Interval,
|
interval: Interval,
|
||||||
@@ -37,8 +37,7 @@ pub struct RunnerState {
|
|||||||
|
|
||||||
// Eventually we want to coerce the data into this format for timelines-chart
|
// Eventually we want to coerce the data into this format for timelines-chart
|
||||||
// Resource (group) -> Task (label) -> data [ { "timeRange": [date,date], "val": state } ]
|
// Resource (group) -> Task (label) -> data [ { "timeRange": [date,date], "val": state } ]
|
||||||
pub type ResourceStateDetails =
|
pub type ResourceStateDetails = HashMap<Resource, HashMap<String, Vec<Action>>>;
|
||||||
HashMap<Resource, HashMap<String, Vec<(DateTime<Utc>, DateTime<Utc>, ActionState)>>>;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RunnerMessage {
|
pub enum RunnerMessage {
|
||||||
@@ -368,9 +367,10 @@ impl Runner {
|
|||||||
response: oneshot::Sender<ResourceStateDetails>,
|
response: oneshot::Sender<ResourceStateDetails>,
|
||||||
) {
|
) {
|
||||||
// HashMap<Resource, HashMap<String, Vec<(DateTime<Utc>, DateTime<Utc>, ActionState)>>>;
|
// 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.extend(t.provides.clone());
|
||||||
acc
|
acc
|
||||||
});
|
});
|
||||||
@@ -386,25 +386,25 @@ impl Runner {
|
|||||||
res.insert(resource.clone(), res_ints);
|
res.insert(resource.clone(), res_ints);
|
||||||
}
|
}
|
||||||
|
|
||||||
let actions = self
|
let actions: Vec<Action> = self
|
||||||
.actions
|
.actions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| interval.is_contiguous(x.interval))
|
.filter(|x| interval.is_contiguous(x.interval))
|
||||||
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
||||||
for action in actions {
|
for action in actions {
|
||||||
let task = &self.tasks[action.task];
|
let task = &self.tasks[action.task];
|
||||||
for resource in task.provides {
|
for resource in &task.provides {
|
||||||
res.entry(resource.clone()).or_insert(HashMap::new()).entry(task.name).or_insert(Hash
|
res.get_mut(resource)
|
||||||
|
.unwrap()
|
||||||
|
.get_mut(&task.name)
|
||||||
|
.unwrap()
|
||||||
|
.push(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for task in &self.tasks {
|
response.send(res).unwrap();
|
||||||
for resource in &task.provides {}
|
|
||||||
}
|
|
||||||
|
|
||||||
response.send(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&mut self, mut stay_up: bool) {
|
pub async fn run(&mut self, mut stay_up: bool) {
|
||||||
|
|||||||
Reference in New Issue
Block a user