use fso_graph::prelude::*;
use log::info;
use polars::prelude::*;
type AppResult = Result<(), Box<dyn std::error::Error>>;
type ID = u64;
fn main() -> AppResult {
env_logger::init();
let g: DirectedCsrGraph<ID> = GraphBuilder::new()
.csr_layout(CsrLayout::Deduplicated)
.file_format(Graph500Input::default())
.path("examples/scale_24.graph")
.build()?;
let (scores, iterations, _) = time(|| page_rank(&g, PageRankConfig::default()));
info!("PageRank ran iterations: {iterations}");
let height = scores.len();
let scores_col = Column::new(PlSmallStr::from_static("scores"), scores);
let df = DataFrame::new(height, vec![scores_col])?;
let scores_col = df.column("scores")?;
info!("size = {}", df.height());
info!("min = {:?}", scores_col.min_reduce()?.value());
info!("max = {:?}", scores_col.max_reduce()?.value());
info!("mean = {:?}", scores_col.mean_reduce()?.value());
info!("median = {:?}", scores_col.median_reduce()?.value());
let components = time(|| wcc_afforest(&g, WccConfig::default())).to_vec();
let height = components.len();
let components_col = Column::new(PlSmallStr::from_static("components"), components);
let df = DataFrame::new(height, vec![components_col])?;
info!("size = {}", df.height());
let df = df.unique::<&[String], String>(None, UniqueKeepStrategy::First, None)?;
info!("component count = {}", df.height());
let mut ug = time(|| g.to_undirected(CsrLayout::Deduplicated));
drop(g);
time(|| ug.make_degree_ordered());
let tc = time(|| global_triangle_count(&ug));
info!("TC: found {tc} triangles.");
Ok(())
}
fn time<T, F: FnOnce() -> T>(f: F) -> T {
let start = std::time::Instant::now();
let res = f();
info!("Execution took {:?}", start.elapsed());
res
}