//! This mainly concerns converting collected data into things that the canvas
//! can actually handle.
use crate::Pid;
use crate::{
app::{data_farmer, data_harvester, App, Filter, ProcWidgetState},
utils::{self, gen_util::*},
};
use data_harvester::processes::ProcessSorting;
use indexmap::IndexSet;
use std::collections::{HashMap, VecDeque};
/// Point is of time, data
type Point = (f64, f64);
#[derive(Default, Debug)]
pub struct ConvertedBatteryData {
pub battery_name: String,
pub charge_percentage: f64,
pub watt_consumption: String,
pub duration_until_full: Option<String>,
pub duration_until_empty: Option<String>,
pub health: String,
}
#[derive(Default, Debug)]
pub struct ConvertedNetworkData {
pub rx: Vec<Point>,
pub tx: Vec<Point>,
pub rx_display: String,
pub tx_display: String,
pub total_rx_display: Option<String>,
pub total_tx_display: Option<String>,
// TODO: [NETWORKING] add min/max/mean of each
// min_rx : f64,
// max_rx : f64,
// mean_rx: f64,
// min_tx: f64,
// max_tx: f64,
// mean_tx: f64,
}
// TODO: [REFACTOR] Process data... stuff really needs a rewrite. Again.
#[derive(Clone, Default, Debug)]
pub struct ConvertedProcessData {
pub pid: Pid,
pub ppid: Option<Pid>,
pub name: String,
pub command: String,
pub is_thread: Option<bool>,
pub cpu_percent_usage: f64,
pub mem_percent_usage: f64,
pub mem_usage_bytes: u64,
pub mem_usage_str: (f64, String),
pub group_pids: Vec<Pid>,
pub read_per_sec: String,
pub write_per_sec: String,
pub total_read: String,
pub total_write: String,
pub rps_f64: f64,
pub wps_f64: f64,
pub tr_f64: f64,
pub tw_f64: f64,
pub process_state: String,
pub process_char: char,
/// Prefix printed before the process when displayed.
pub process_description_prefix: Option<String>,
/// Whether to mark this process entry as disabled (mostly for tree mode).
pub is_disabled_entry: bool,
}
#[derive(Clone, Default, Debug)]
pub struct ConvertedCpuData {
pub cpu_name: String,
pub short_cpu_name: String,
/// Tuple is time, value
pub cpu_data: Vec<Point>,
/// Represents the value displayed on the legend.
pub legend_value: String,
}
pub fn convert_temp_row(app: &App) -> Vec<Vec<String>> {
let current_data = &app.data_collection;
let temp_type = &app.app_config_fields.temperature_type;
let temp_filter = &app.filters.temp_filter;
let mut sensor_vector: Vec<Vec<String>> = current_data
.temp_harvest
.iter()
.filter_map(|temp_harvest| {
let name = match (&temp_harvest.component_name, &temp_harvest.component_label) {
(Some(name), Some(label)) => format!("{}: {}", name, label),
(None, Some(label)) => label.to_string(),
(Some(name), None) => name.to_string(),
(None, None) => String::default(),
};
let to_keep = if let Some(temp_filter) = temp_filter {
let mut ret = temp_filter.is_list_ignored;
for r in &temp_filter.list {
if r.is_match(&name) {
ret = !temp_filter.is_list_ignored;
break;
}
}
ret
} else {
true
};
if to_keep {
Some(vec![
name,
(temp_harvest.temperature.ceil() as u64).to_string()
+ match temp_type {
data_harvester::temperature::TemperatureType::Celsius => "C",
data_harvester::temperature::TemperatureType::Kelvin => "K",
data_harvester::temperature::TemperatureType::Fahrenheit => "F",
},
])
} else {
None
}
})
.collect();
if sensor_vector.is_empty() {
sensor_vector.push(vec!