Skip to content

Commit

Permalink
added CeBrA custom config
Browse files Browse the repository at this point in the history
	modified:   Cargo.lock
	modified:   Cargo.toml
	modified:   src/histoer/configs.rs
	modified:   src/histoer/cuts.rs
	modified:   src/histoer/histogrammer.rs
	modified:   src/histogram_scripter/custom_scripts.rs
	modified:   src/ui/app.rs
	modified:   src/util/processer.rs
  • Loading branch information
alconley committed Dec 31, 2024
1 parent c2e70f3 commit f019e1e
Show file tree
Hide file tree
Showing 8 changed files with 886 additions and 525 deletions.
90 changes: 21 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde = { version = "1.0.217", features = ["derive"] }
egui_plot = {version = "0.30", features = ["serde"] }
egui_tiles = "0.11"
egui_extras = {version = "0.30", features = ["syntect"] }
egui_file = "0.19"
egui_file = "0.20.0"
epaint = "0.30"
env_logger = "0.11.6"
polars = { version = "0.45.0", features = ["lazy", "parquet", "performant"] }
Expand Down
49 changes: 32 additions & 17 deletions src/histoer/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ impl Configs {

pub fn config_ui(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.heading("Histograms");
ui.label("Histograms");

if ui.button("+1D").clicked() {
self.configs.push(Config::Hist1D(Hist1DConfig {
Expand Down Expand Up @@ -464,7 +464,7 @@ impl Configs {

pub fn column_ui(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.heading("Column Creation");
ui.label("Column Creation");

if ui.button("+").clicked() {
self.columns.push(("".to_string(), "".to_string()));
Expand Down Expand Up @@ -1053,30 +1053,48 @@ fn expr_from_string(expression: &str) -> Result<Expr, PolarsError> {

let mut expr_stack: Vec<Expr> = Vec::new();
let mut op_stack: Vec<String> = Vec::new();
let mut is_first_token = true;

log::debug!("Starting evaluation of expression: '{}'", expression);
log::debug!("Tokens: {:?}", tokens);

for token in tokens {
let mut i = 0;
while i < tokens.len() {
let token = &tokens[i];
match token.as_str() {
"+" | "-" | "*" | "/" | "**" => {
// Handle consecutive operators like "- -" or "- +"
if i < tokens.len() - 1 && (tokens[i + 1] == "-" || tokens[i + 1] == "+") {
// Collapse consecutive operators into one
let mut sign = if *token == "-" { -1.0 } else { 1.0 };
let mut j = i + 1;
while j < tokens.len() && (tokens[j] == "-" || tokens[j] == "+") {
sign *= if tokens[j] == "-" { -1.0 } else { 1.0 };
j += 1;
}

if j < tokens.len() && tokens[j].parse::<f64>().is_ok() {
// Combine the collapsed operators with the number
let number = tokens[j].parse::<f64>().unwrap();
expr_stack.push(lit(sign * number));
i = j; // Skip to the next token after the number
continue;
}
}

// Normal operator precedence handling
while let Some(op) = op_stack.last() {
// Pop operators with higher or equal precedence
if precedence(op) > precedence(&token)
|| (precedence(op) == precedence(&token) && is_left_associative(&token))
if precedence(op) > precedence(token)
|| (precedence(op) == precedence(token) && is_left_associative(token))
{
apply_op(&mut expr_stack, op_stack.pop().unwrap().as_str());
} else {
break;
}
}
op_stack.push(token);
is_first_token = false;
op_stack.push(token.clone());
}
"(" => {
op_stack.push(token);
is_first_token = false;
op_stack.push(token.clone());
}
")" => {
while let Some(op) = op_stack.pop() {
Expand All @@ -1088,17 +1106,13 @@ fn expr_from_string(expression: &str) -> Result<Expr, PolarsError> {
}
_ if token.parse::<f64>().is_ok() => {
let number = token.parse::<f64>().unwrap();
if number < 0.0 && !is_first_token {
op_stack.push("+".to_string());
}
expr_stack.push(lit(number));
is_first_token = false;
}
_ => {
expr_stack.push(col(&token));
is_first_token = false;
expr_stack.push(col(token));
}
}
i += 1;
}

while let Some(op) = op_stack.pop() {
Expand Down Expand Up @@ -1160,6 +1174,7 @@ fn add_computed_column(
alias: &str,
) -> Result<(), PolarsError> {
let computed_expr = expr_from_string(expression)?;
log::info!("Computed expression: {:?}", computed_expr);
*lf = lf.clone().with_column(computed_expr.alias(alias)); // Use alias for the new column name
Ok(())
}
Expand Down
Loading

0 comments on commit f019e1e

Please sign in to comment.