//! 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, 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,
/// Whether this entry is collapsed, hiding all its children (for tree mode).
pub is_collapsed_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 mut sensor_vector: Vec<Vec<String>> = current_data
.temp_harvest
.iter()
.map(|temp_harvest| {
vec![
temp_harvest.name.clone(),
(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",
},
]
})
.collect();
if sensor_vector.is_empty() {
sensor_vector.push(vec!["No Sensors Found".to_string(), "".to_string()]);
}
sensor_vector
}
pub fn convert_disk_row(current_data: &data_farmer::DataCollection) ->