WIP, to be cleaned and merged
This commit is contained in:
parent
314adbeb1d
commit
d1e3152a83
30 changed files with 1498 additions and 248 deletions
68
rust/src/galaxy.rs
Normal file
68
rust/src/galaxy.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::Result;
|
||||
use serde_json;
|
||||
use std::fs::File;
|
||||
use std::io::Seek;
|
||||
use std::io::{BufRead, BufReader, BufWriter, SeekFrom};
|
||||
use std::path::PathBuf;
|
||||
use std::str;
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Coords {
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Body {
|
||||
name: String,
|
||||
#[serde(rename = "type")]
|
||||
body_type: String,
|
||||
subType: String,
|
||||
#[serde(rename = "distanceToArrival")]
|
||||
distance: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct System {
|
||||
coords: Coords,
|
||||
name: String,
|
||||
bodies: Vec<Body>,
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
better_panic::install();
|
||||
let mut buffer = String::new();
|
||||
let mut bz2_reader = std::process::Command::new("bzip2").args(
|
||||
&["-d","-c",r#"E:\EDSM\galaxy.json.bz2"#]
|
||||
).stdout(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.expect("Failed to spawn execute bzip2!");
|
||||
let mut reader = BufReader::new(bz2_reader.stdout.as_mut().expect("Failed to open stdout of child process"));
|
||||
let mut count = 0;
|
||||
while let Ok(n) = reader.read_line(&mut buffer) {
|
||||
if n==0 {
|
||||
break;
|
||||
}
|
||||
buffer = buffer
|
||||
.trim()
|
||||
.trim_end_matches(|c| c == ',')
|
||||
.trim()
|
||||
.to_string();
|
||||
if let Ok(sys) = serde_json::from_str::<System>(&buffer) {
|
||||
for b in &sys.bodies {
|
||||
if b.body_type == "Star" {
|
||||
count += 1;
|
||||
if (count % 100_000) == 0 {
|
||||
println!("{}: {:?}", count, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer.clear();
|
||||
}
|
||||
println!("Total: {}", count);
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue