From 27e0850e77b0edfc6b40f39f29425ac9ccf82455 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Tue, 10 Sep 2024 07:22:24 +0900 Subject: [PATCH] fix: handling u64 properly in coeff results --- mixnet-rs/ordering/src/bin/aggregate.rs | 4 ++-- mixnet-rs/ordering/src/bin/coeff_aggr.rs | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mixnet-rs/ordering/src/bin/aggregate.rs b/mixnet-rs/ordering/src/bin/aggregate.rs index 887ddbc..41d352b 100644 --- a/mixnet-rs/ordering/src/bin/aggregate.rs +++ b/mixnet-rs/ordering/src/bin/aggregate.rs @@ -71,11 +71,11 @@ fn aggregate(path: &str) { fn add_stats_columns(df: &mut DataFrame, path: PathBuf, col_prefix: &str) { let mut schema = Schema::new(); - schema.with_column("min".into(), DataType::Float64); + schema.with_column("min".into(), DataType::UInt64); schema.with_column("median".into(), DataType::Float64); schema.with_column("mean".into(), DataType::Float64); schema.with_column("std".into(), DataType::Float64); - schema.with_column("max".into(), DataType::Float64); + schema.with_column("max".into(), DataType::UInt64); let stats_df = CsvReadOptions::default() .with_has_header(true) diff --git a/mixnet-rs/ordering/src/bin/coeff_aggr.rs b/mixnet-rs/ordering/src/bin/coeff_aggr.rs index c2fb11e..8eee577 100644 --- a/mixnet-rs/ordering/src/bin/coeff_aggr.rs +++ b/mixnet-rs/ordering/src/bin/coeff_aggr.rs @@ -5,6 +5,13 @@ use std::fs::File; use walkdir::WalkDir; fn aggregate(path: &str) { + let mut input_schema = Schema::new(); + input_schema.with_column("sender".into(), DataType::UInt64); + input_schema.with_column("receiver".into(), DataType::UInt64); + input_schema.with_column("strong".into(), DataType::UInt64); + input_schema.with_column("casual".into(), DataType::UInt64); + input_schema.with_column("weak".into(), DataType::UInt64); + for entry in WalkDir::new(path) .into_iter() .filter_map(|e| e.ok()) @@ -12,14 +19,15 @@ fn aggregate(path: &str) { { let dir_name = entry.path().file_name().unwrap().to_string_lossy(); if dir_name.starts_with("paramset_") { - let mut strongs = Series::new_empty("", &DataType::Int64); - let mut casuals = Series::new_empty("", &DataType::Int64); - let mut weaks = Series::new_empty("", &DataType::Int64); + let mut strongs = Series::new_empty("", &DataType::UInt64); + let mut casuals = Series::new_empty("", &DataType::UInt64); + let mut weaks = Series::new_empty("", &DataType::UInt64); let pattern = format!("{}/**/coeffs_*.csv", entry.path().display()); for file in glob(&pattern).unwrap().filter_map(Result::ok) { let df = CsvReadOptions::default() .with_has_header(true) + .with_schema(Some(SchemaRef::new(input_schema.clone()))) .try_into_reader_with_file_path(Some(file.clone())) .unwrap() .finish() @@ -53,7 +61,7 @@ fn extend_series(series: &mut Series, df: &DataFrame, column: &str) { .extend( &df.column(column) .unwrap() - .i64() + .u64() .unwrap() .clone() .into_series(), @@ -63,11 +71,11 @@ fn extend_series(series: &mut Series, df: &DataFrame, column: &str) { fn save_stats(aggregated: &Series, outpath: &str) { let mut df = DataFrame::new(vec![ - Series::new("min", &[aggregated.min::().unwrap()]), + Series::new("min", &[aggregated.min::().unwrap()]), Series::new("median", &[aggregated.median().unwrap()]), Series::new("mean", &[aggregated.mean().unwrap()]), Series::new("std", &[aggregated.std(1).unwrap()]), - Series::new("max", &[aggregated.max::().unwrap()]), + Series::new("max", &[aggregated.max::().unwrap()]), ]) .unwrap();