A lot of exploration of various things in rust
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
a85e8e33ea
commit
2b20df273b
1344
Cargo.lock
generated
1344
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
@ -49,6 +49,22 @@ kiddo = "0.2.5"
|
|||||||
anyhow = "1.0.69"
|
anyhow = "1.0.69"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
svg = "0.13.0"
|
svg = "0.13.0"
|
||||||
|
polars = { version = "0.27.2", features = [
|
||||||
|
"docs",
|
||||||
|
"zip_with",
|
||||||
|
"csv-file",
|
||||||
|
"temporal",
|
||||||
|
"fmt",
|
||||||
|
"dtype-slim",
|
||||||
|
"csv-file",
|
||||||
|
"lazy",
|
||||||
|
"nightly",
|
||||||
|
"performant"
|
||||||
|
] }
|
||||||
|
rayon = "1.7.0"
|
||||||
|
walkdir = "2.3.3"
|
||||||
|
parquet = { version = "35.0.0", features = ["serde"] }
|
||||||
|
colorous = "1.0.10"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cbindgen = "0.24.3"
|
cbindgen = "0.24.3"
|
||||||
|
|||||||
33
src/tools/analysis.rs
Normal file
33
src/tools/analysis.rs
Normal file
@ -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 boxcount;
|
||||||
pub mod render;
|
pub mod render;
|
||||||
|
pub mod analysis;
|
||||||
|
|
||||||
pub fn read<T: Position>(path: &Path, format: OutputFormat) -> Vec<T> where T: DeserializeOwned {
|
pub fn read<T: Position>(path: &Path, format: OutputFormat) -> Vec<T> where T: DeserializeOwned {
|
||||||
match format {
|
match format {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use crate::cli::cli::OutputFormat;
|
|||||||
use crate::system::model::HistoryLine;
|
use crate::system::model::HistoryLine;
|
||||||
use crate::system::spaces::square_grid::Grid2D;
|
use crate::system::spaces::square_grid::Grid2D;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use colorous::Color;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use svg::Node;
|
use svg::Node;
|
||||||
@ -25,13 +26,13 @@ struct Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait ToSvg {
|
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 {
|
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()
|
Box::new(Rectangle::new()
|
||||||
.set("fill", "rgb(0, 0, 0)")
|
.set("fill", format!("rgb({}, {}, {})", colour.r, colour.g, colour.b))
|
||||||
.set("width", size)
|
.set("width", size)
|
||||||
.set("height", size)
|
.set("height", size)
|
||||||
.set("x", self.x * size)
|
.set("x", self.x * size)
|
||||||
@ -40,7 +41,7 @@ impl ToSvg for Grid2D {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ToSvg for HexPosition {
|
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 = [
|
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]
|
[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();
|
let [x, y] = self.to_cartesian();
|
||||||
Box::new(Rectangle::new()
|
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("x", x * size)
|
||||||
.set("y", y * size))
|
.set("y", y * size))
|
||||||
}
|
}
|
||||||
@ -83,8 +84,9 @@ pub(crate) fn main(args: &RenderCli) {
|
|||||||
.set("y", -max_size)
|
.set("y", -max_size)
|
||||||
);
|
);
|
||||||
|
|
||||||
for position in positions {
|
for (n, position) in positions.iter().enumerate() {
|
||||||
svg.append(position.to_svg(size));
|
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();
|
svg::write(File::create(&args.output).unwrap(), &svg).unwrap();
|
||||||
|
|||||||
@ -2,16 +2,20 @@
|
|||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::ops::{Index, Mul};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use crate::cli::cli::OutputFormat;
|
use crate::cli::cli::OutputFormat;
|
||||||
use crate::system::model::HistoryLine;
|
use crate::system::model::HistoryLine;
|
||||||
use crate::system::spaces::square_grid::Grid2D;
|
use crate::system::spaces::square_grid::Grid2D;
|
||||||
use clap::{Parser, Command, Args, Subcommand};
|
use clap::{Parser, Command, Args, Subcommand};
|
||||||
|
use itertools::{concat, Itertools};
|
||||||
|
use polars::io::RowCount;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use svg::Node;
|
use svg::Node;
|
||||||
use svg::node::element::Rectangle;
|
use svg::node::element::Rectangle;
|
||||||
|
use walkdir::WalkDir;
|
||||||
use crate::system::Position;
|
use crate::system::Position;
|
||||||
use crate::system::spaces::hexagonal::HexPosition;
|
use crate::system::spaces::hexagonal::HexPosition;
|
||||||
|
|
||||||
@ -22,7 +26,8 @@ mod tools;
|
|||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
enum ToolsCli {
|
enum ToolsCli {
|
||||||
Render(RenderCli),
|
Render(RenderCli),
|
||||||
BoxCount(BoxCountCli)
|
BoxCount(BoxCountCli),
|
||||||
|
DataAnalysis(DataAnalysisCli),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(clap::ValueEnum, Clone, Debug, Copy)]
|
#[derive(clap::ValueEnum, Clone, Debug, Copy)]
|
||||||
@ -43,6 +48,9 @@ struct RenderCli {
|
|||||||
|
|
||||||
#[arg(short, long, default_value_t = 800)]
|
#[arg(short, long, default_value_t = 800)]
|
||||||
image_size: u32,
|
image_size: u32,
|
||||||
|
|
||||||
|
#[arg(short, long, default_value_t = false)]
|
||||||
|
colour: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
@ -53,12 +61,21 @@ struct BoxCountCli {
|
|||||||
output: PathBuf,
|
output: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[derive(Debug, Args)]
|
||||||
|
struct DataAnalysisCli {
|
||||||
|
sp_dir: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> anyhow::Result<()> {
|
||||||
let args = ToolsCli::parse();
|
let args = ToolsCli::parse();
|
||||||
dbg!(&args);
|
dbg!(&args);
|
||||||
|
|
||||||
match args {
|
match args {
|
||||||
ToolsCli::Render(cli) => tools::render::main(&cli),
|
ToolsCli::Render(cli) => tools::render::main(&cli),
|
||||||
ToolsCli::BoxCount(cli) => tools::boxcount::main(&cli),
|
ToolsCli::BoxCount(cli) => tools::boxcount::main(&cli),
|
||||||
|
ToolsCli::DataAnalysis(cli) => {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user