This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
use crate::DataAnalysisCli;
|
||||
|
||||
use polars::prelude::*;
|
||||
use polars::io::RowCount;
|
||||
use rayon::prelude::*;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
pub fn main(cli: &DataAnalysisCli) {
|
||||
let a: Vec<_> = WalkDir::new(&cli.sp_dir)
|
||||
.into_iter()
|
||||
.par_bridge()
|
||||
.filter(|run_file| run_file.as_ref().unwrap().path().is_file())
|
||||
.map(|run_file| {
|
||||
let run_file = run_file.unwrap().path().to_path_buf();
|
||||
let probability = run_file.parent().unwrap().file_name().unwrap().to_str().unwrap().parse::<f32>().unwrap();
|
||||
let run_seed = run_file.file_stem().unwrap().to_str().unwrap();
|
||||
|
||||
LazyCsvReader::new(&run_file)
|
||||
.has_header(true)
|
||||
// Add N, done at this stage to only count within single CSV file
|
||||
.with_row_count(Some(RowCount { name: String::from("N"), offset: 0 }))
|
||||
.finish().unwrap()
|
||||
.with_columns([
|
||||
lit(probability).alias("probability"),
|
||||
lit(run_seed).alias("run")
|
||||
])
|
||||
}).collect();
|
||||
|
||||
let p = concat(a, true, true).unwrap();
|
||||
let p = p.collect().unwrap();
|
||||
|
||||
println!("{:?}", p);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use crate::system::Position;
|
||||
|
||||
pub mod boxcount;
|
||||
pub mod render;
|
||||
pub mod analysis;
|
||||
|
||||
pub fn read<T: Position>(path: &Path, format: OutputFormat) -> Vec<T> where T: DeserializeOwned {
|
||||
match format {
|
||||
|
||||
+9
-7
@@ -8,6 +8,7 @@ use crate::cli::cli::OutputFormat;
|
||||
use crate::system::model::HistoryLine;
|
||||
use crate::system::spaces::square_grid::Grid2D;
|
||||
use clap::Parser;
|
||||
use colorous::Color;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Deserialize;
|
||||
use svg::Node;
|
||||
@@ -25,13 +26,13 @@ struct Args {
|
||||
}
|
||||
|
||||
trait ToSvg {
|
||||
fn to_svg(&self, size: i32) -> Box<dyn Node>;
|
||||
fn to_svg(&self, size: i32, colour: Color) -> Box<dyn Node>;
|
||||
}
|
||||
|
||||
impl ToSvg for Grid2D {
|
||||
fn to_svg(&self, size: i32) -> Box<dyn Node> {
|
||||
fn to_svg(&self, size: i32, colour: Color) -> Box<dyn Node> {
|
||||
Box::new(Rectangle::new()
|
||||
.set("fill", "rgb(0, 0, 0)")
|
||||
.set("fill", format!("rgb({}, {}, {})", colour.r, colour.g, colour.b))
|
||||
.set("width", size)
|
||||
.set("height", size)
|
||||
.set("x", self.x * size)
|
||||
@@ -40,7 +41,7 @@ impl ToSvg for Grid2D {
|
||||
}
|
||||
|
||||
impl ToSvg for HexPosition {
|
||||
fn to_svg(&self, size: i32) -> Box<dyn Node> {
|
||||
fn to_svg(&self, size: i32, colour: Color) -> Box<dyn Node> {
|
||||
let points = [
|
||||
[25.045, 128.0], [256.0, 0.0], [486.955, 128.0], [486.955, 384.0], [256.0, 512.0], [25.045, 384.0]
|
||||
];
|
||||
@@ -56,7 +57,7 @@ impl ToSvg for HexPosition {
|
||||
|
||||
let [x, y] = self.to_cartesian();
|
||||
Box::new(Rectangle::new()
|
||||
.set("fill", "rgb(0, 0, 0)")
|
||||
.set("fill", format!("rgb({}, {}, {})", colour.r, colour.g, colour.b))
|
||||
.set("x", x * size)
|
||||
.set("y", y * size))
|
||||
}
|
||||
@@ -83,8 +84,9 @@ pub(crate) fn main(args: &RenderCli) {
|
||||
.set("y", -max_size)
|
||||
);
|
||||
|
||||
for position in positions {
|
||||
svg.append(position.to_svg(size));
|
||||
for (n, position) in positions.iter().enumerate() {
|
||||
let colour = if args.colour { colorous::VIRIDIS.eval_rational(n, positions.len()) } else { Color::default() };
|
||||
svg.append(position.to_svg(size, colour));
|
||||
}
|
||||
|
||||
svg::write(File::create(&args.output).unwrap(), &svg).unwrap();
|
||||
|
||||
+19
-2
@@ -2,16 +2,20 @@
|
||||
#![feature(let_chains)]
|
||||
|
||||
use std::fs::File;
|
||||
use std::ops::{Index, Mul};
|
||||
use std::path::PathBuf;
|
||||
use anyhow::Context;
|
||||
use crate::cli::cli::OutputFormat;
|
||||
use crate::system::model::HistoryLine;
|
||||
use crate::system::spaces::square_grid::Grid2D;
|
||||
use clap::{Parser, Command, Args, Subcommand};
|
||||
use itertools::{concat, Itertools};
|
||||
use polars::io::RowCount;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Deserialize;
|
||||
use svg::Node;
|
||||
use svg::node::element::Rectangle;
|
||||
use walkdir::WalkDir;
|
||||
use crate::system::Position;
|
||||
use crate::system::spaces::hexagonal::HexPosition;
|
||||
|
||||
@@ -22,7 +26,8 @@ mod tools;
|
||||
#[derive(Debug, Parser)]
|
||||
enum ToolsCli {
|
||||
Render(RenderCli),
|
||||
BoxCount(BoxCountCli)
|
||||
BoxCount(BoxCountCli),
|
||||
DataAnalysis(DataAnalysisCli),
|
||||
}
|
||||
|
||||
#[derive(clap::ValueEnum, Clone, Debug, Copy)]
|
||||
@@ -43,6 +48,9 @@ struct RenderCli {
|
||||
|
||||
#[arg(short, long, default_value_t = 800)]
|
||||
image_size: u32,
|
||||
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
colour: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
@@ -53,12 +61,21 @@ struct BoxCountCli {
|
||||
output: PathBuf,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[derive(Debug, Args)]
|
||||
struct DataAnalysisCli {
|
||||
sp_dir: PathBuf,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let args = ToolsCli::parse();
|
||||
dbg!(&args);
|
||||
|
||||
match args {
|
||||
ToolsCli::Render(cli) => tools::render::main(&cli),
|
||||
ToolsCli::BoxCount(cli) => tools::boxcount::main(&cli),
|
||||
ToolsCli::DataAnalysis(cli) => {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user