Skip to content

Commit 7c3be18

Browse files
committed
wokring on 1d cuts
modified: src/cutter/cut_handler.rs modified: src/cutter/cuts.rs modified: src/histoer/histo2d/keybinds.rs modified: src/histoer/histo2d/plot_settings.rs modified: src/histoer/histogrammer.rs modified: src/histogram_scripter/histogram_script.rs modified: src/util/lazyframer.rs modified: src/util/processer.rs modified: src/util/workspacer.rs
1 parent dd7e154 commit 7c3be18

File tree

9 files changed

+560
-838
lines changed

9 files changed

+560
-838
lines changed

src/cutter/cut_handler.rs

Lines changed: 130 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,130 @@
1-
use super::cuts::Cut;
2-
use crate::histoer::histogrammer::Histogrammer;
3-
use polars::prelude::*;
4-
5-
use std::fs::File;
6-
use std::io::BufReader;
7-
use std::path::PathBuf;
8-
9-
#[derive(Default, serde::Deserialize, serde::Serialize)]
10-
pub struct CutHandler {
11-
pub cuts: Vec<Cut>,
12-
}
13-
14-
impl CutHandler {
15-
// get a cut with a file dialog
16-
pub fn get_cut(&mut self) -> Result<(), Box<dyn std::error::Error>> {
17-
if let Some(file_path) = rfd::FileDialog::new()
18-
.set_file_name("cut.json") // Suggest a default file name for convenience
19-
.add_filter("JSON Files", &["json"]) // Filter for json files
20-
.pick_file()
21-
{
22-
let file = File::open(file_path)?;
23-
let reader = BufReader::new(file);
24-
let cut: Cut = serde_json::from_reader(reader)?;
25-
self.cuts.push(cut);
26-
}
27-
Ok(())
28-
}
29-
30-
pub fn cut_ui(&mut self, ui: &mut egui::Ui, histogrammer: &mut Histogrammer) {
31-
ui.collapsing("Cuts", |ui| {
32-
ui.horizontal(|ui| {
33-
if ui.button("Get Cut").clicked() {
34-
if let Err(e) = self.get_cut() {
35-
log::error!("Error loading cut: {:?}", e);
36-
}
37-
}
38-
39-
// Add a button to retrieve active cuts from histograms
40-
if ui.button("Retrieve Active Cuts").clicked() {
41-
histogrammer.retrieve_active_cuts(self);
42-
}
43-
});
44-
45-
if self.cuts.is_empty() {
46-
ui.label("No cuts loaded");
47-
} else {
48-
egui::Grid::new("cuts")
49-
.striped(true)
50-
.num_columns(6)
51-
.show(ui, |ui| {
52-
ui.label("Cuts");
53-
ui.label("X Column\t\t\t\t\t");
54-
ui.label("Y Column\t\t\t\t\t");
55-
ui.label("Polygon");
56-
ui.label("Active");
57-
ui.end_row();
58-
59-
let mut index_to_remove = None;
60-
for (index, cut) in self.cuts.iter_mut().enumerate() {
61-
ui.label(format!("Cut {}", index));
62-
63-
cut.ui(ui);
64-
65-
ui.horizontal(|ui| {
66-
if ui.button("🗙").clicked() {
67-
index_to_remove = Some(index);
68-
}
69-
});
70-
71-
ui.end_row();
72-
}
73-
74-
if let Some(index) = index_to_remove {
75-
self.cuts.remove(index);
76-
}
77-
});
78-
79-
// add button to remove all
80-
if ui.button("Remove All").clicked() {
81-
self.cuts.clear();
82-
}
83-
}
84-
});
85-
}
86-
87-
pub fn filter_lf_with_selected_cuts(
88-
&mut self,
89-
lf: &LazyFrame,
90-
) -> Result<LazyFrame, PolarsError> {
91-
let mut filtered_lf = lf.clone();
92-
93-
// Iterate through all cuts and apply their respective filters.
94-
for cut in &mut self.cuts {
95-
filtered_lf = cut.filter_lf_with_cut(&filtered_lf)?;
96-
}
97-
98-
Ok(filtered_lf)
99-
}
100-
101-
pub fn filter_files_and_save_to_one_file(
102-
&mut self,
103-
file_paths: Vec<PathBuf>,
104-
output_path: &PathBuf,
105-
) -> Result<(), PolarsError> {
106-
let files_arc: Arc<[PathBuf]> = Arc::from(file_paths.clone());
107-
108-
let args = ScanArgsParquet::default();
109-
110-
// Assuming LazyFrame::scan_parquet_files constructs a LazyFrame from the list of files
111-
let lf = LazyFrame::scan_parquet_files(files_arc, args)?;
112-
113-
// Apply filtering logic as before, leading to a filtered LazyFrame
114-
let filtered_lf = self.filter_lf_with_selected_cuts(&lf)?; // Placeholder for applying cuts
115-
116-
// Collect the LazyFrame into a DataFrame
117-
let mut filtered_df = filtered_lf.collect()?;
118-
119-
// Open a file in write mode at the specified output path
120-
let file = File::create(output_path).map_err(|e| PolarsError::IO {
121-
error: Arc::new(e),
122-
msg: None,
123-
})?;
124-
125-
// Write the filtered DataFrame to a Parquet file
126-
ParquetWriter::new(file)
127-
.set_parallel(true)
128-
.finish(&mut filtered_df)?;
129-
130-
Ok(())
131-
}
132-
}
1+
// use super::cuts::Cut2D;
2+
// use crate::histoer::histogrammer::Histogrammer;
3+
4+
// use std::fs::File;
5+
// use std::io::BufReader;
6+
7+
// #[derive(Default, serde::Deserialize, serde::Serialize)]
8+
// pub struct CutHandler {
9+
// pub cuts: Vec<Cut2D>,
10+
// }
11+
12+
// impl CutHandler {
13+
// // get a cut with a file dialog
14+
// pub fn get_cut(&mut self) -> Result<(), Box<dyn std::error::Error>> {
15+
// if let Some(file_path) = rfd::FileDialog::new()
16+
// .set_file_name("cut.json") // Suggest a default file name for convenience
17+
// .add_filter("JSON Files", &["json"]) // Filter for json files
18+
// .pick_file()
19+
// {
20+
// let file = File::open(file_path)?;
21+
// let reader = BufReader::new(file);
22+
// let cut: Cut2D = serde_json::from_reader(reader)?;
23+
// self.cuts.push(cut);
24+
// }
25+
// Ok(())
26+
// }
27+
28+
// pub fn cut_ui(&mut self, ui: &mut egui::Ui, histogrammer: &mut Histogrammer) {
29+
// ui.collapsing("Cuts", |ui| {
30+
// ui.horizontal(|ui| {
31+
// if ui.button("Get Cut").clicked() {
32+
// if let Err(e) = self.get_cut() {
33+
// log::error!("Error loading cut: {:?}", e);
34+
// }
35+
// }
36+
37+
// // Add a button to retrieve active cuts from histograms
38+
// if ui.button("Retrieve Active Cuts").clicked() {
39+
// histogrammer.retrieve_active_cuts(self);
40+
// }
41+
// });
42+
43+
// if self.cuts.is_empty() {
44+
// ui.label("No cuts loaded");
45+
// } else {
46+
// egui::Grid::new("cuts")
47+
// .striped(true)
48+
// .num_columns(6)
49+
// .show(ui, |ui| {
50+
// ui.label("Cuts");
51+
// ui.label("X Column\t\t\t\t\t");
52+
// ui.label("Y Column\t\t\t\t\t");
53+
// ui.label("Polygon");
54+
// ui.label("Active");
55+
// ui.end_row();
56+
57+
// let mut index_to_remove = None;
58+
// for (index, cut) in self.cuts.iter_mut().enumerate() {
59+
// ui.label(format!("Cut {}", index));
60+
61+
// cut.ui(ui);
62+
63+
// ui.horizontal(|ui| {
64+
// if ui.button("X").clicked() {
65+
// index_to_remove = Some(index);
66+
// }
67+
// });
68+
69+
// ui.end_row();
70+
// }
71+
72+
// if let Some(index) = index_to_remove {
73+
// self.cuts.remove(index);
74+
// }
75+
// });
76+
77+
// // add button to remove all
78+
// if ui.button("Remove All").clicked() {
79+
// self.cuts.clear();
80+
// }
81+
// }
82+
// });
83+
// }
84+
// }
85+
86+
// pub fn filter_lf_with_selected_cuts(
87+
// &mut self,
88+
// lf: &LazyFrame,
89+
// ) -> Result<LazyFrame, PolarsError> {
90+
// let mut filtered_lf = lf.clone();
91+
92+
// // Iterate through all cuts and apply their respective filters.
93+
// for cut in &mut self.cuts {
94+
// filtered_lf = cut.filter_lf_with_cut(&filtered_lf)?;
95+
// }
96+
97+
// Ok(filtered_lf)
98+
// }
99+
100+
// pub fn filter_files_and_save_to_one_file(
101+
// &mut self,
102+
// file_paths: Vec<PathBuf>,
103+
// output_path: &PathBuf,
104+
// ) -> Result<(), PolarsError> {
105+
// let files_arc: Arc<[PathBuf]> = Arc::from(file_paths.clone());
106+
107+
// let args = ScanArgsParquet::default();
108+
109+
// // Assuming LazyFrame::scan_parquet_files constructs a LazyFrame from the list of files
110+
// let lf = LazyFrame::scan_parquet_files(files_arc, args)?;
111+
112+
// // Apply filtering logic as before, leading to a filtered LazyFrame
113+
// let filtered_lf = self.filter_lf_with_selected_cuts(&lf)?; // Placeholder for applying cuts
114+
115+
// // Collect the LazyFrame into a DataFrame
116+
// let mut filtered_df = filtered_lf.collect()?;
117+
118+
// // Open a file in write mode at the specified output path
119+
// let file = File::create(output_path).map_err(|e| PolarsError::IO {
120+
// error: Arc::new(e),
121+
// msg: None,
122+
// })?;
123+
124+
// // Write the filtered DataFrame to a Parquet file
125+
// ParquetWriter::new(file)
126+
// .set_parallel(true)
127+
// .finish(&mut filtered_df)?;
128+
129+
// Ok(())
130+
// }

0 commit comments

Comments
 (0)