Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move data availability checks to lib from visualizer #78

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use chrono::prelude::*;
use log::{debug, error, info};
use serde::{Deserialize, Serialize};
use serde_json::{self};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::{fs, time};
use std::path::{Path, PathBuf};
use std::sync::Mutex;
Expand Down Expand Up @@ -263,6 +263,7 @@ pub struct VisualizationData {
pub visualizers: HashMap<String, visualizer::DataVisualizer>,
pub js_files: HashMap<String, String>,
pub run_names: Vec<String>,
pub data_available: HashSet<String>,
}

impl VisualizationData {
Expand All @@ -271,6 +272,7 @@ impl VisualizationData {
visualizers: HashMap::new(),
js_files: HashMap::new(),
run_names: Vec::new(),
data_available: HashSet::new(),
}
}

Expand All @@ -281,14 +283,16 @@ impl VisualizationData {
let visualizers_len = self.visualizers.len();
let mut error_count = 0;

for (_name, visualizer) in self.visualizers.iter_mut() {
for (name, visualizer) in self.visualizers.iter_mut() {
debug!("Initializing visualizer for: {}", name);
match visualizer.init_visualizer(dir.clone(), dir_name.clone(), tmp_dir.clone(), fin_dir.clone()) {
Err(e) => {
error!("{:#?}", e);
visualizer.data_not_available(dir_name.clone())?;
debug!("Error: {:?}", e);
error_count += 1;
},
Ok(_) => {},
Ok(_) => {
self.data_available.insert(name.to_string());
},
}
}

Expand Down Expand Up @@ -321,6 +325,10 @@ impl VisualizationData {

pub fn unpack_data(&mut self, name: String) -> Result<()> {
for (dvname, datavisualizer) in self.visualizers.iter_mut() {
if !self.data_available.contains(dvname) {
debug!("Raw data not available for: {}", dvname);
continue;
}
debug!("Unpacking data for: {}", dvname);
datavisualizer.process_raw_data(name.clone())?;
}
Expand All @@ -345,6 +353,10 @@ impl VisualizationData {
}

pub fn get_data(&mut self, run_name: &String, visualizer_name: &str, query: String) -> Result<String> {
if !self.data_available.contains(&visualizer_name.to_string()) {
debug!("Skipping getting data for: {}", visualizer_name);
return Ok("No data collected".to_string());
}
let visualizer = self.visualizers.get_mut(visualizer_name).ok_or(PDError::VisualizerHashMapEntryError(visualizer_name.to_string().into()))?;
visualizer.get_data(run_name.to_string(), query.clone())
}
Expand Down
18 changes: 1 addition & 17 deletions src/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub struct DataVisualizer {
pub js: String,
pub api_name: String,
pub has_custom_raw_data_parser: bool,
pub data_available: HashMap<String, bool>,
pub report_params: ReportParams,
}

Expand All @@ -51,7 +50,6 @@ impl DataVisualizer {
js: js,
api_name: api_name,
has_custom_raw_data_parser: false,
data_available: HashMap::new(),
report_params: ReportParams::new(),
}
}
Expand All @@ -70,20 +68,10 @@ impl DataVisualizer {
self.report_params.data_file_path = fs::read_link(full_path).unwrap();
self.file_handle = Some(file);
self.run_values.insert(name.clone(), Vec::new());
self.data_available.insert(name, true);
Ok(())
}

pub fn data_not_available(&mut self, name: String) -> Result<()> {
self.data_available.insert(name, false);
Ok(())
}

pub fn process_raw_data(&mut self, name: String) -> Result<()> {
if !self.data_available.get(&name).unwrap() {
debug!("Raw data unavailable for: {}", self.api_name);
return Ok(())
}
debug!("Processing raw data for: {}", self.api_name);
if self.has_custom_raw_data_parser {
self.run_values.insert(name.clone(), self.data.custom_raw_data_parser(self.report_params.clone())?);
Expand All @@ -109,11 +97,7 @@ impl DataVisualizer {
Ok(())
}

pub fn get_data(&mut self, name: String, query: String) -> Result<String> {
if !self.data_available.get(&name).unwrap() {
debug!("No data available for: {} query: {}", self.api_name, query);
return Ok("No data collected".to_string());
}
pub fn get_data(&mut self, _name: String, query: String) -> Result<String> {
/* Get run name from Query */
let param: Vec<(String, String)> = serde_urlencoded::from_str(&query)?;
let (_, run) = param[0].clone();
Expand Down
Loading