Some FD work

This commit is contained in:
Joshua Coles 2023-03-15 13:39:15 +00:00
parent 717b3172e7
commit ad00c260b5

View File

@ -1,6 +1,8 @@
#![feature(generic_const_exprs)] #![feature(generic_const_exprs)]
#![feature(let_chains)]
mod system; mod system;
mod cli;
use std::fs::File; use std::fs::File;
use std::os::unix::fs::symlink; use std::os::unix::fs::symlink;
@ -8,6 +10,7 @@ use bevy::tasks::ParallelSlice;
use crate::system::spaces::square_grid::{Grid2D, Grid3D}; use crate::system::spaces::square_grid::{Grid2D, Grid3D};
use itertools::{Itertools, MinMaxResult}; use itertools::{Itertools, MinMaxResult};
use clap::Parser; use clap::Parser;
use crate::cli::cli::OutputFormat;
use crate::system::{GriddedPosition, Position}; use crate::system::{GriddedPosition, Position};
use crate::system::model::HistoryLine; use crate::system::model::HistoryLine;
@ -90,9 +93,9 @@ fn box_count_3d(data: &Vec<Grid3D>, size: u32) -> usize {
let grid_points = data.iter() let grid_points = data.iter()
.map(|Grid3D { x, y, z }| [ .map(|Grid3D { x, y, z }| [
((x - x_min) as f64 / w) as u32, ((x - x_min) as f64 / w) as i32,
((y - y_min) as f64 / w) as u32, ((y - y_min) as f64 / w) as i32,
((z - z_min) as f64 / w) as u32, ((z - z_min) as f64 / w) as i32,
]) ])
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -120,19 +123,31 @@ fn box_count_nd<const N: usize>(data: &Vec<[f32; N]>, size: u32) -> usize {
#[derive(Parser)] #[derive(Parser)]
struct FDArgs { struct FDArgs {
format: OutputFormat,
path: std::path::PathBuf, path: std::path::PathBuf,
} }
fn main() { fn main() {
let args = FDArgs::parse(); let args = FDArgs::parse();
let lines: Vec<HistoryLine<Grid3D>> = serde_json::from_reader(File::open(args.path).unwrap())
.expect("Failed to read json");
let a = lines.iter() let qa = match args.format {
.map(|l| l.position.to_cartesian()) OutputFormat::FullDataJson => {
.collect::<Vec<_>>(); serde_json::from_reader::<_, Vec<HistoryLine<Grid3D>>>(File::open(args.path).unwrap())
.expect("Failed to read json")
.iter()
.map(|l| l.position.clone())
.collect::<Vec<_>>()
}
OutputFormat::Positions => {
csv::Reader::from_path(args.path).unwrap().deserialize::<Grid3D>()
.collect::<Result<Vec<Grid3D>, _>>()
.unwrap()
}
};
assert_eq!(qa.iter().unique().collect::<Vec<_>>().len(), qa.len());
for size in 1..250 { for size in 1..250 {
println!("[{}, {:?}],", size, box_count_nd(&a, size)); println!("[{}, {:?}],", size, box_count_3d(&qa, size));
} }
} }