slight adjustments to pp-gen

This commit is contained in:
MaxOhn
2021-11-13 15:11:45 +01:00
parent 15cefe78d5
commit 092034a6d5
+12 -15
View File
@@ -84,9 +84,9 @@ async fn async_main() {
env::var("PERF_CALC_PATH").expect("missing `PERF_CALC_PATH` environment variable"); env::var("PERF_CALC_PATH").expect("missing `PERF_CALC_PATH` environment variable");
let perf_calc_path = perf_calc_path_.as_str(); let perf_calc_path = perf_calc_path_.as_str();
let mut output = StdFile::create("./output_.json").expect("failed to create output file"); let mut output = StdFile::create("./output.json").expect("failed to create output file");
let take = 50; let take = 250;
let pbr = Mutex::new(ProgressBar::new(take)); let pbr = Mutex::new(ProgressBar::new(take));
println!("[INFO] Calculating..."); println!("[INFO] Calculating...");
@@ -98,24 +98,21 @@ async fn async_main() {
.scan(0, |idx, entry| { .scan(0, |idx, entry| {
*idx += 1; *idx += 1;
future::ready(Some((*idx % 75 == 0).then(|| entry))) future::ready(Some((*idx % 76 == 0).then(|| entry)))
}) })
.filter_map(|opt| future::ready(opt)) .filter_map(|opt| future::ready(opt))
.take(take as usize) .take(take as usize)
.map(|dir_entry| async { .map(|dir_entry| async {
let dir_entry = dir_entry?; let dir_entry = dir_entry?;
let file_name = dir_entry.file_name(); let file_name = dir_entry.file_name();
let file_name_lossy = file_name.to_string_lossy();
let file_path = dir_entry.path(); let file_path = dir_entry.path();
let map_id = match file_name let map_id_str = file_name_lossy.split('.').next();
.to_string_lossy()
.split('.') let map_id = match map_id_str.map(str::parse) {
.next() Some(Ok(id)) => id,
.map(str::parse) Some(Err(_)) => return Err(Error::ParseId(map_id_str.unwrap().to_owned())),
.transpose()
.map_err(|_| Error::ParseId)?
{
Some(id) => id,
None => return Err(Error::EmptyFileName), None => return Err(Error::EmptyFileName),
}; };
@@ -244,7 +241,7 @@ async fn handle_map(
enum Error { enum Error {
EmptyFileName, EmptyFileName,
Io(std::io::Error), Io(std::io::Error),
ParseId, ParseId(String),
ParseMap(rosu_pp::ParseError), ParseMap(rosu_pp::ParseError),
Serde(serde_json::Error), Serde(serde_json::Error),
} }
@@ -254,7 +251,7 @@ impl fmt::Display for Error {
match self { match self {
Error::EmptyFileName => f.write_str("empty file name"), Error::EmptyFileName => f.write_str("empty file name"),
Error::Io(_) => f.write_str("io error"), Error::Io(_) => f.write_str("io error"),
Error::ParseId => f.write_str("failed to parse map id"), Error::ParseId(s) => write!(f, "failed to parse map id from `{}`", s),
Error::ParseMap(_) => f.write_str("failed to parse map"), Error::ParseMap(_) => f.write_str("failed to parse map"),
Error::Serde(_) => f.write_str("failed to deserialize"), Error::Serde(_) => f.write_str("failed to deserialize"),
} }
@@ -266,7 +263,7 @@ impl std::error::Error for Error {
match self { match self {
Self::EmptyFileName => None, Self::EmptyFileName => None,
Self::Io(src) => Some(src), Self::Io(src) => Some(src),
Self::ParseId => None, Self::ParseId(_) => None,
Self::ParseMap(src) => Some(src), Self::ParseMap(src) => Some(src),
Self::Serde(src) => Some(src), Self::Serde(src) => Some(src),
} }