more effecient lodestone-fetcher usage
parent
54278f5506
commit
7997857d65
20
src/main.rs
20
src/main.rs
|
@ -4,23 +4,27 @@ mod raw_data;
|
|||
use crate::compile_data::{DpsRole, JobStats, Role};
|
||||
use crate::raw_data::RawJobStats;
|
||||
|
||||
use std::io::BufRead;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
fn get_job_stats(lodestone_ids: &[usize]) -> anyhow::Result<Vec<Vec<JobStats>>> {
|
||||
let mut player_stats = Vec::new();
|
||||
for id in lodestone_ids {
|
||||
let output = Command::new("lodestone-fetcher")
|
||||
.arg(id.to_string())
|
||||
.args(lodestone_ids.iter().map(|id| id.to_string()))
|
||||
.stdout(Stdio::piped())
|
||||
.output()
|
||||
.expect("Failed to execute lodestone-fetcher");
|
||||
|
||||
let raw: Vec<RawJobStats> = serde_json::from_reader(&output.stdout[..])?;
|
||||
let raw_data = output.stdout.lines();
|
||||
let data: Vec<Result<Vec<JobStats>, _>> = raw_data
|
||||
.map_while(Result::ok)
|
||||
.map(|raw| serde_json::from_str(&raw))
|
||||
.map(|raw_stats: Result<Vec<RawJobStats>, _>| {
|
||||
raw_stats.map(|raw| raw.into_iter().map(|r| r.into()).collect())
|
||||
})
|
||||
.map(|stats| stats.map_err(|err| anyhow::anyhow!(err)))
|
||||
.collect();
|
||||
|
||||
player_stats.push(Ok(raw.into_iter().map(|r| r.into()).collect()));
|
||||
}
|
||||
|
||||
player_stats.into_iter().collect()
|
||||
data.into_iter().collect()
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
|
|
Loading…
Reference in New Issue