#![allow(warnings)]
use polars::prelude::*;
use clap::Parser;
use polars_ai::cli::{Cli, Commands, InputCommands};
use polars_ai::dataframe::AIDataFrame;
use polars_ai::utils::display_ai_response;
use polars_ai::utils::display_dataframe;
fn _analyze_data(dfs: Vec<DataFrame>) -> DataFrame {
let df = &dfs[0];
let top_carriers = df
.group_by(&["Carrier"])
.expect("Columns must exist!")
.mean()
.unwrap()
.sort(["DepDelay_mean"], false, false)
.expect("DepDelay_mean must exist")
.head(Some(5))
.select(&["Carrier"])
.unwrap();
let result_df = df
.join(
&top_carriers,
&["Carrier"],
&["Carrier"],
JoinType::Inner.into(),
)
.expect("Carrier must exist")
.sort(["DepDelay"], false, false)
.expect("DepDelay must exist")
.head(Some(5));
result_df.select(&["Carrier", "DepDelay"]).unwrap()
}
#[tokio::main]
async fn main() -> Result<(), Box<PolarsError>> {
let args = Cli::parse();
match args.command {
Some(Commands::Input(file)) => {
match file.file_name {
Some(ref file_name) => {
let df_result = CsvReader::from_path(file_name)?.finish();
let df = match df_result {
Ok(df) => df,
Err(e) => {
eprintln!("Error loading CSV: {}", e);
return Err(Box::new(e));
}
};
match file.command {
InputCommands::Show(_show) => {
let _ = display_dataframe(&df, false);
}
InputCommands::Ask(ask) => {
match ask.query {
Some(ref query) => {
let mut ai_df = AIDataFrame::new(df);
let result = ai_df.ask(query).await.unwrap();
display_ai_response(&result);
}
None => {
eprintln!(
"\x1b[1;91m{}\x1b[0m",
"Missing 'query' argument for 'ask' command."
)
}
};
}
};
}
None => {
println!("Please provide a data file name");
}
};
}
None => println!(
"\x1b[1;91m{}\x1b[0m",
"Unknown command. Use 'help' for usage instructions."
),
None => todo!(),
};
Ok(())
}