Compare commits

...

5 Commits

4 changed files with 241 additions and 91 deletions

182
Cargo.lock generated
View File

@ -49,7 +49,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "beanconqueror"
version = "0.1.0"
version = "0.4.0"
dependencies = [
"calamine",
"chrono",
@ -57,9 +57,11 @@ dependencies = [
"fast-float",
"palette",
"plotters",
"plotters-canvas",
"serde",
"serde_derive",
"toml",
"wasm-bindgen-test",
]
[[package]]
@ -107,6 +109,12 @@ version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -170,6 +178,16 @@ dependencies = [
"rand 0.6.5",
]
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen",
]
[[package]]
name = "const-cstr"
version = "0.3.0"
@ -235,7 +253,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -253,7 +271,7 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"dirs-sys-next",
]
@ -295,7 +313,7 @@ version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -396,13 +414,19 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "futures"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
[[package]]
name = "getrandom"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
@ -479,7 +503,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"winapi",
]
@ -489,7 +513,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@ -562,8 +586,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05eedf46a8e7c27f74af0c9cfcdb004ceca158cb1b918c6f68f8d7a549b3e427"
dependencies = [
"find-crate",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn",
]
@ -624,8 +648,8 @@ checksum = "92aacdc5f16768709a569e913f7451034034178b05bdc8acda226659a3dccc66"
dependencies = [
"phf_generator",
"phf_shared",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn",
]
@ -646,9 +670,8 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]]
name = "plotters"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "716b4eeb6c4a1d3ecc956f75b43ec2e8e8ba80026413e70a3f41fd3313d3492b"
version = "0.3.5"
source = "git+https://github.com/plotters-rs/plotters#e4c1052e40eee614d8932de19f5664165ee66852"
dependencies = [
"chrono",
"font-kit",
@ -656,7 +679,7 @@ dependencies = [
"lazy_static",
"num-traits",
"pathfinder_geometry",
"plotters-backend",
"plotters-backend 0.3.4 (git+https://github.com/plotters-rs/plotters)",
"plotters-bitmap",
"plotters-svg",
"ttf-parser",
@ -670,24 +693,39 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142"
[[package]]
name = "plotters-backend"
version = "0.3.4"
source = "git+https://github.com/plotters-rs/plotters#e4c1052e40eee614d8932de19f5664165ee66852"
[[package]]
name = "plotters-bitmap"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4a1f21490a6cf4a84c272ad20bd7844ed99a3178187a4c5ab7f2051295beef"
version = "0.3.3"
source = "git+https://github.com/plotters-rs/plotters#e4c1052e40eee614d8932de19f5664165ee66852"
dependencies = [
"gif",
"image",
"plotters-backend",
"plotters-backend 0.3.4 (git+https://github.com/plotters-rs/plotters)",
]
[[package]]
name = "plotters-canvas"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "498a82bf654581fa4df6c1bd73e56f8556bdeec5eca5a0989d170ca0728ccace"
dependencies = [
"js-sys",
"plotters-backend 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "plotters-svg"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f"
version = "0.3.4"
source = "git+https://github.com/plotters-rs/plotters#e4c1052e40eee614d8932de19f5664165ee66852"
dependencies = [
"plotters-backend",
"plotters-backend 0.3.4 (git+https://github.com/plotters-rs/plotters)",
]
[[package]]
@ -702,6 +740,15 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid",
]
[[package]]
name = "proc-macro2"
version = "1.0.43"
@ -721,13 +768,22 @@ dependencies = [
"memchr",
]
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]]
name = "quote"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
"proc-macro2",
"proc-macro2 1.0.43",
]
[[package]]
@ -898,6 +954,12 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "scoped-tls"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
[[package]]
name = "semver"
version = "0.11.0"
@ -928,8 +990,8 @@ version = "1.0.144"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn",
]
@ -945,8 +1007,8 @@ version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"unicode-ident",
]
@ -965,8 +1027,8 @@ version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn",
]
@ -992,9 +1054,9 @@ dependencies = [
[[package]]
name = "ttf-parser"
version = "0.15.2"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd"
checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff"
[[package]]
name = "ucd-trie"
@ -1008,6 +1070,12 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "walkdir"
version = "2.3.2"
@ -1037,7 +1105,7 @@ version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"wasm-bindgen-macro",
]
@ -1050,19 +1118,32 @@ dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83420b37346c311b9ed822af41ec2e82839bfe99867ec6c54e2da43b7538771c"
dependencies = [
"cfg-if 0.1.10",
"futures",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602"
dependencies = [
"quote",
"quote 1.0.21",
"wasm-bindgen-macro-support",
]
@ -1072,8 +1153,8 @@ version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
@ -1085,6 +1166,31 @@ version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a"
[[package]]
name = "wasm-bindgen-test"
version = "0.2.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2d9693b63a742d481c7f80587e057920e568317b2806988c59cd71618bc26c1"
dependencies = [
"console_error_panic_hook",
"futures",
"js-sys",
"scoped-tls",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test-macro",
]
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.2.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0789dac148a8840bbcf9efe13905463b733fa96543bfbf263790535c11af7ba5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
]
[[package]]
name = "web-sys"
version = "0.3.59"

View File

@ -1,19 +1,21 @@
[package]
name = "beanconqueror"
version = "0.1.0"
version = "0.4.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
calamine = "*"
chrono = "*"
colourado = "*"
fast-float = "*"
palette = "*"
plotters = "*"
# plotters-canvas = "*"
serde = "*"
serde_derive = "*"
toml = "*"
# wasm-bindgen-test = "0.2"
calamine = "0.18.0"
chrono = "0.4.22"
colourado = "0.2.0"
fast-float = "0.2.0"
palette = "0.6.1"
plotters-canvas = "*"
serde = "1.0.144"
serde_derive = "1.0.144"
toml = "0.5.9"
wasm-bindgen-test = "0.2"
[dependencies.plotters]
git = "https://github.com/plotters-rs/plotters"

View File

@ -4,10 +4,6 @@ output_dir = "images"
width = 1600
height = 900
max_time = 45
max_weight = 35
max_flow = 5
[shots]
@ -123,22 +119,37 @@ title = "Laura 19.07.2022 #1"
[charts.0]
title = "Elisabeth Shots"
shots = [0, 1, 10, 14, 15]
max_time = 45
max_weight = 35
max_flow = 5
[charts.1]
title = "Laura Shots"
shots = [2, 3, 4, 5, 6, 7, 8, 9, 12, 16, 17, 18, 19, 20, 21, 22, 23]
max_time = 45
max_weight = 35
max_flow = 5
[charts.2]
title = "Josephine Shots"
shots = [11, 13]
max_time = 45
max_weight = 35
max_flow = 5
[charts.3]
title = "First Shots"
shots = [0, 1, 2, 4, 5, 7, 9, 10, 12, 13, 14, 16, 18, 20, 23]
max_time = 45
max_weight = 35
max_flow = 5
[charts.4]
title = "Second Shots"
shots = [3, 6, 8, 15, 17, 19, 21]
max_time = 45
max_weight = 35
max_flow = 5

View File

@ -1,4 +1,4 @@
use calamine::{Reader, Xlsx, open_workbook};
use calamine::{open_workbook, Reader, Xlsx};
use chrono::{Duration, NaiveTime};
use colourado::{ColorPalette, PaletteType};
use plotters::prelude::*;
@ -19,6 +19,10 @@ struct Shot {
struct Chart {
title: String,
shots: Vec<u64>,
max_time: u64,
max_weight: u64,
max_flow: u64,
}
#[derive(Deserialize)]
@ -31,10 +35,6 @@ struct Config {
width: u32,
height: u32,
max_time: u64,
max_weight: u64,
max_flow: u64,
}
const WGHT_SHEET: usize = 0;
@ -61,35 +61,50 @@ fn deltatime(time: NaiveTime, start: NaiveTime) -> Duration {
time - start
}
fn process_sheet(path: &str, worksheet: usize, time_col: usize, data_col: usize) -> Vec<(f64, f64)> {
let mut workbook: Xlsx<_> = open_workbook(path).expect(&format!("Cannot open file at path \"{}\"", path));
fn process_sheet(
path: &str,
worksheet: usize,
time_col: usize,
data_col: usize,
) -> Vec<(f64, f64)> {
let mut workbook: Xlsx<_> =
open_workbook(path).unwrap_or_else(|_| panic!("Cannot open file at path \"{}\"", path));
if let Some(Ok(range)) = workbook.worksheet_range_at(worksheet) {
let starting_time: NaiveTime = cell_to_naivetime(range[(1, time_col)].get_string());
let time_range = range.range((1, time_col as u32), (range.height() as u32 - 1, time_col as u32));
let weight_range = range.range((1, data_col as u32), (range.height() as u32 - 1, data_col as u32));
let time_range = range.range(
(1, time_col as u32),
(range.height() as u32 - 1, time_col as u32),
);
let weight_range = range.range(
(1, data_col as u32),
(range.height() as u32 - 1, data_col as u32),
);
// println!("time column cells: {:?}", time_range.cells().next());
// println!("time column strings: {:?}", time_range.cells().map(|c| c.2.get_string().unwrap()).collect::<Vec<&str>>());
let map_time_range = time_range
.cells().map(|c| {
let timestamp = cell_to_naivetime(c.2.get_string());
let deltatime = deltatime(timestamp, starting_time);
let std_duration = deltatime.to_std().unwrap();
let map_time_range = time_range.cells().map(|c| {
let timestamp = cell_to_naivetime(c.2.get_string());
let deltatime = deltatime(timestamp, starting_time);
let std_duration = deltatime.to_std().unwrap();
std_duration.as_secs_f32() as f64
}).collect::<Vec<f64>>();
std_duration.as_secs_f32() as f64
});
let map_weight_range = weight_range
.cells()
.map(|c| c.2
.get_float()
.expect(&format!("Can't get float value of weight column at position ({},{})", c.0, c.1)))
.collect::<Vec<f64>>();
.map(|c| {
c.2.get_float().unwrap_or_else(|| {
panic!(
"Can't get float value of weight column at position ({},{})",
c.0, c.1
)
})
});
map_time_range.into_iter().zip(map_weight_range.into_iter()).collect()
map_time_range.zip(map_weight_range).collect()
} else {
vec![]
}
@ -101,13 +116,16 @@ fn load_data(path: &str, cutoff: Option<f64>) -> Option<Data> {
if let Some(cutoff_val) = cutoff {
if cutoff_val != -1.0 {
w = w.into_iter().filter(|x| &x.0 < &cutoff_val).collect();
fr = fr.into_iter().filter(|x| &x.0 < &cutoff_val).collect();
w.retain(|x| x.0 < cutoff_val);
fr.retain(|x| x.0 < cutoff_val);
}
}
if w.len() > 0 && fr.len() > 0 {
let data = Data { weight: w, flowrate: fr };
if !w.is_empty() && !fr.is_empty() {
let data = Data {
weight: w,
flowrate: fr,
};
Some(data)
} else {
None
@ -122,20 +140,23 @@ fn main() {
// println!("Chart: {}\n", chart.1.title);
let title = format!("{}/{}.svg", config.output_dir, chart.1.title);
let root_area = SVGBackend::new(&title, (config.width, config.height))
.into_drawing_area();
let root_area = SVGBackend::new(&title, (config.width, config.height)).into_drawing_area();
root_area.fill(&WHITE).unwrap();
let mut ctx = ChartBuilder::on(&root_area)
.set_label_area_size(LabelAreaPosition::Left, 40)
.set_label_area_size(LabelAreaPosition::Bottom, 40)
.caption(&chart.1.title, ("Fira Code", 24))
.build_cartesian_2d(0f64..(config.max_time as f64), 0f64..(config.max_weight as f64))
.build_cartesian_2d(
0f64..(chart.1.max_time as f64),
0f64..(chart.1.max_weight as f64),
)
.unwrap();
ctx.configure_mesh()
.label_style(("Fira Code", 12))
.draw().unwrap();
.draw()
.unwrap();
let shot_count = chart.1.shots.len();
@ -146,7 +167,10 @@ fn main() {
if let Some(shot) = config.shots.get(&shot_nr.to_string()) {
// println!("\tShot: {}n", shot.title);
if let Some(data) = load_data(&format!("{}/{}", config.shot_dir, shot.filename), shot.cutoff) {
if let Some(data) = load_data(
&format!("{}/{}", config.shot_dir, shot.filename),
shot.cutoff,
) {
if let Some(disable) = shot.disable {
if disable {
continue;
@ -167,16 +191,22 @@ fn main() {
f32_to_u8(color.red),
f32_to_u8(color.green),
f32_to_u8(color.blue),
1.0);
1.0,
);
ctx.draw_series(LineSeries::new(data.weight, color)).unwrap()
ctx.draw_series(LineSeries::new(data.weight, color))
.unwrap()
.label(&shot.title)
.legend(move |(x, y)|
Rectangle::new([(x - 20, y + 2), (x, y - 2)], ShapeStyle {
.legend(move |(x, y)| {
Rectangle::new(
[(x - 20, y + 2), (x, y - 2)],
ShapeStyle {
color,
filled: true,
stroke_width: 1
}));
stroke_width: 1,
},
)
});
}
}
}
@ -187,6 +217,7 @@ fn main() {
.margin(25)
.legend_area_size(10)
.label_font(("Fira Code", 12))
.draw().unwrap();
.draw()
.unwrap();
}
}