feat: time display

This commit is contained in:
Artemy 2024-05-29 22:01:06 +03:00
parent 817f117ac4
commit a3ea2a093c
2 changed files with 56 additions and 30 deletions

View file

@ -1,4 +1,4 @@
use std::{fs, path::Path};
use std::{fs, path::Path, time};
use geojson::{Feature, FeatureCollection};
use serde_json::json;
@ -12,8 +12,10 @@ use crate::{
pub fn build() {
let config = read_config();
let total_time = time::Instant::now();
for processing_item in config.processing {
let features: Vec<Feature> = vec![];
let processed_time = time::Instant::now();
let out_folder = Path::new(&processing_item.output_folder);
@ -22,48 +24,72 @@ pub fn build() {
let mut countries: Vec<CountryData> = vec![];
for country_id in &config.main.layers {
let country = get_country(country_id.to_owned());
{
let dissolved_time = time::Instant::now();
let mut matches = false;
for glob in &globs {
for tag in &country.config.tags.clone().unwrap_or(vec![]) {
if glob.is_match(tag.as_str()) {
matches = true;
for country_id in &config.main.layers {
let country = get_country(country_id.to_owned());
let mut matches = false;
for glob in &globs {
for tag in &country.config.tags.clone().unwrap_or(vec!["*".to_owned()]) {
if glob.is_match(tag.as_str()) {
matches = true;
}
}
}
if !matches {
continue;
}
countries.push(country);
}
if !matches {
continue;
}
countries.push(country);
println!("Dissolved in {:?}", dissolved_time.elapsed());
}
// TODO: Add country_rewrite support
let countries = diff_countries(countries);
let countries = {
let diff_time = time::Instant::now();
let countries = diff_countries(countries);
println!("Diffed in {:?}", diff_time.elapsed());
countries
};
// TODO: Add nature support
{
let generated_time = time::Instant::now();
let countries_json = serde_json::to_string_pretty(&serde_json::Map::from_iter(
countries
.iter()
.map(|country| (country.id.clone(), json!(country.config))),
))
.unwrap();
let countries_json = serde_json::to_string_pretty(&serde_json::Map::from_iter(
countries
.iter()
.map(|country| (country.id.clone(), json!(country.config))),
))
.unwrap();
fs::create_dir_all(out_folder).unwrap();
let feature_collection = countries.to_collection().to_string();
fs::write(
out_folder.join("geo.geojson"),
countries.to_collection().to_string(),
)
.unwrap();
fs::write(out_folder.join("countries.json"), countries_json).unwrap();
fs::create_dir_all(out_folder).unwrap();
if let Some(public) = processing_item.public {
let public = serde_json::to_string(&public).unwrap();
fs::write(out_folder.join("public.json"), public).unwrap();
}
fs::write(out_folder.join("geo.geojson"), feature_collection).unwrap();
fs::write(out_folder.join("countries.json"), countries_json).unwrap();
if let Some(public) = processing_item.public {
let public = serde_json::to_string(&public).unwrap();
fs::write(out_folder.join("public.json"), public).unwrap();
println!("Generated files in {:?}", generated_time.elapsed());
}
println!("Processed in {:?}\n---\n", processed_time.elapsed());
}
println!("Total time: {:?}", total_time.elapsed());
}

View file

@ -144,7 +144,7 @@ impl ToFeature for Marker {
serde_json::Map::from_iter([
("title".to_owned(), json!(self.title)),
("description".to_owned(), json!(self.description)),
("marker-type".to_owned(), json!(self.ty.to_str())),
("type".to_owned(), json!(self.ty.to_str())),
])
.into(),
),