Compare commits

...

2 commits

Author SHA1 Message Date
b0748f370b
Add test dividers to CPU graph 2025-07-05 20:44:57 -07:00
cb3eb2876c
Switch to PNG output 2025-07-05 20:43:40 -07:00
2 changed files with 47 additions and 16 deletions

20
Cargo.lock generated
View file

@ -318,16 +318,6 @@ version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
[[package]]
name = "hmm"
version = "0.1.0"
dependencies = [
"chrono",
"plotters",
"serde",
"toml",
]
[[package]]
name = "iana-time-zone"
version = "0.1.63"
@ -1065,6 +1055,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "wk-cpu-graph"
version = "0.1.0"
dependencies = [
"chrono",
"plotters",
"serde",
"toml",
]
[[package]]
name = "yeslogic-fontconfig-sys"
version = "6.0.0"

View file

@ -90,18 +90,20 @@ struct Averages {
temp: f64,
}
const OUT_FILE_NAME: &str = "hmm.svg";
//const OUT_FILE_NAME: &str = "hmm.svg";
const OUT_FILE_NAME: &str = "hmm.png"; // TODO: Switch to SVG
fn main() -> Result<(), Box<dyn Error>> {
// Parse data
let toml_data = fs::read_to_string("data.toml").expect("Failed to read data file.");
let data: Data = toml::from_str(&toml_data).expect("Failed to parse TOML data");
let max_temp = data.max_temp() + 1.0;
let min_temp = data.min_temp() - 1.0;
let max_temp = f64::ceil((data.max_temp() + 1.0) / 5.0) * 5.0;
let min_temp = f64::floor((data.min_temp() - 1.0) / 5.0) * 5.0;
let num_temps = data.len();
// Chart data
let mut line_colors = LineColors::new();
let root = SVGBackend::new(OUT_FILE_NAME, (1600, 900)).into_drawing_area();
//let root = SVGBackend::new(OUT_FILE_NAME, (1600, 900)).into_drawing_area();
let root = BitMapBackend::new(OUT_FILE_NAME, (1600, 900)).into_drawing_area();
root.fill(&WHITE)?;
@ -123,6 +125,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.y_desc("Temps (C)")
.draw()?;
// CPU temp sensors
data.temps.iter().for_each(|temps| {
let color = line_colors.next();
chart
@ -184,16 +187,44 @@ fn main() -> Result<(), Box<dyn Error>> {
_ => {}
});
// Test dividers
data.tests
.iter()
.filter(|test| test.name != "Idle")
.for_each(|test| {
let color = match test.name.as_str() {
"Cooldown" => RGBAColor(0, 0, 255, 1.0),
"Prime95" => RGBAColor(255, 0, 0, 1.0),
"Sysbench" => RGBAColor(255, 165, 0, 1.0),
_ => line_colors.next().to_rgba(),
};
test.offsets.iter().for_each(|offset| {
let offset = *offset as i32;
chart
.draw_series(DashedLineSeries::new(
[(offset, min_temp + 1.0), (offset, max_temp - 1.0)],
10,
5,
ShapeStyle {
color,
filled: false,
stroke_width: 1,
},
))
.unwrap();
});
});
// Export to file
chart
.configure_series_labels()
.position(SeriesLabelPosition::LowerRight)
.margin(20)
.legend_area_size(5)
.border_style(BLACK)
.background_style(BLACK.mix(0.1))
.background_style(RGBColor(192, 192, 192))
.label_font(("Calibri", 20))
.draw()?;
println!("File exported?");
// To avoid the IO failure being ignored silently, we manually call the present function
root.present().expect("Unable to write result to file, please make sure 'plotters-doc-data' dir exists under current dir");