scirs2_io/workflow/
functions_4.rs1use super::types::{TaskStatus, TaskType, Workflow, WorkflowState};
6
7pub mod visualization {
9 use super::*;
10 pub struct WorkflowVisualizer;
12 impl WorkflowVisualizer {
13 pub fn to_dot(workflow: &Workflow) -> String {
15 let mut dot = String::new();
16 dot.push_str("digraph workflow {\n");
17 dot.push_str(" rankdir=TB;\n");
18 dot.push_str(" node [shape=box, style=rounded];\n\n");
19 for task in &workflow.tasks {
20 let color = match task.task_type {
21 TaskType::DataIngestion => "lightblue",
22 TaskType::Transform => "lightgreen",
23 TaskType::Validation => "yellow",
24 TaskType::MLTraining => "orange",
25 TaskType::MLInference => "pink",
26 TaskType::Export => "lightgray",
27 _ => "white",
28 };
29 dot.push_str(&format!(
30 " {} [label=\"{}\", fillcolor={}, style=filled];\n",
31 task.id, task.name, color
32 ));
33 }
34 dot.push('\n');
35 for (task_id, deps) in &workflow.dependencies {
36 for dep in deps {
37 dot.push_str(&format!(" {dep} -> {task_id};\n"));
38 }
39 }
40 dot.push_str("}\n");
41 dot
42 }
43 pub fn to_mermaid(workflow: &Workflow) -> String {
45 let mut mermaid = String::new();
46 mermaid.push_str("graph TD\n");
47 for task in &workflow.tasks {
48 let shape = match task.task_type {
49 TaskType::DataIngestion => "[",
50 TaskType::Transform => "(",
51 TaskType::Validation => "{",
52 TaskType::MLTraining => "[[",
53 TaskType::MLInference => "((",
54 TaskType::Export => "[",
55 _ => "[",
56 };
57 let close = match task.task_type {
58 TaskType::DataIngestion => "]",
59 TaskType::Transform => ")",
60 TaskType::Validation => "}",
61 TaskType::MLTraining => "]]",
62 TaskType::MLInference => "))",
63 TaskType::Export => "]",
64 _ => "]",
65 };
66 mermaid.push_str(&format!(" {}{}{}{}\n", task.id, shape, task.name, close));
67 }
68 for (task_id, deps) in &workflow.dependencies {
69 for dep in deps {
70 mermaid.push_str(&format!(" {dep} --> {task_id}\n"));
71 }
72 }
73 mermaid
74 }
75 pub fn execution_timeline(state: &WorkflowState) -> String {
77 let mut timeline = String::new();
78 timeline.push_str("gantt\n");
79 timeline.push_str(" title Workflow Execution Timeline\n");
80 timeline.push_str(" dateFormat YYYY-MM-DD HH:mm:ss\n\n");
81 let mut tasks: Vec<_> = state.task_states.iter().collect();
82 tasks.sort_by_key(|(_, state)| state.start_time);
83 for (task_id, task_state) in tasks {
84 if let (Some(start), Some(end)) = (task_state.start_time, task_state.end_time) {
85 let status = match task_state.status {
86 TaskStatus::Success => "done",
87 TaskStatus::Failed => "crit",
88 TaskStatus::Running => "active",
89 _ => "",
90 };
91 timeline.push_str(&format!(
92 " {} :{}, {}, {}\n",
93 task_id,
94 status,
95 start.format("%Y-%m-%d %H:%M:%S"),
96 end.format("%Y-%m-%d %H:%M:%S")
97 ));
98 }
99 }
100 timeline
101 }
102 }
103}