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 geojson::{Feature, FeatureCollection};
use serde_json::json; use serde_json::json;
@ -12,8 +12,10 @@ use crate::{
pub fn build() { pub fn build() {
let config = read_config(); let config = read_config();
let total_time = time::Instant::now();
for processing_item in config.processing { 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); let out_folder = Path::new(&processing_item.output_folder);
@ -22,12 +24,15 @@ pub fn build() {
let mut countries: Vec<CountryData> = vec![]; let mut countries: Vec<CountryData> = vec![];
{
let dissolved_time = time::Instant::now();
for country_id in &config.main.layers { for country_id in &config.main.layers {
let country = get_country(country_id.to_owned()); let country = get_country(country_id.to_owned());
let mut matches = false; let mut matches = false;
for glob in &globs { for glob in &globs {
for tag in &country.config.tags.clone().unwrap_or(vec![]) { for tag in &country.config.tags.clone().unwrap_or(vec!["*".to_owned()]) {
if glob.is_match(tag.as_str()) { if glob.is_match(tag.as_str()) {
matches = true; matches = true;
} }
@ -41,12 +46,24 @@ pub fn build() {
countries.push(country); countries.push(country);
} }
println!("Dissolved in {:?}", dissolved_time.elapsed());
}
// TODO: Add country_rewrite support // TODO: Add country_rewrite support
let countries = {
let diff_time = time::Instant::now();
let countries = diff_countries(countries); let countries = diff_countries(countries);
// TODO: Add nature support 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( let countries_json = serde_json::to_string_pretty(&serde_json::Map::from_iter(
countries countries
.iter() .iter()
@ -54,16 +71,25 @@ pub fn build() {
)) ))
.unwrap(); .unwrap();
let feature_collection = countries.to_collection().to_string();
fs::create_dir_all(out_folder).unwrap(); fs::create_dir_all(out_folder).unwrap();
fs::write(out_folder.join("geo.geojson"), feature_collection).unwrap(); fs::write(
out_folder.join("geo.geojson"),
countries.to_collection().to_string(),
)
.unwrap();
fs::write(out_folder.join("countries.json"), countries_json).unwrap(); fs::write(out_folder.join("countries.json"), countries_json).unwrap();
if let Some(public) = processing_item.public { if let Some(public) = processing_item.public {
let public = serde_json::to_string(&public).unwrap(); let public = serde_json::to_string(&public).unwrap();
fs::write(out_folder.join("public.json"), 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([ serde_json::Map::from_iter([
("title".to_owned(), json!(self.title)), ("title".to_owned(), json!(self.title)),
("description".to_owned(), json!(self.description)), ("description".to_owned(), json!(self.description)),
("marker-type".to_owned(), json!(self.ty.to_str())), ("type".to_owned(), json!(self.ty.to_str())),
]) ])
.into(), .into(),
), ),