mirror of
https://github.com/CIMEngine/cimengine-build-tools.git
synced 2024-11-21 19:56:22 +03:00
feat: time display
This commit is contained in:
parent
817f117ac4
commit
a3ea2a093c
2 changed files with 56 additions and 30 deletions
84
src/build.rs
84
src/build.rs
|
@ -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,48 +24,72 @@ pub fn build() {
|
||||||
|
|
||||||
let mut countries: Vec<CountryData> = vec![];
|
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 country_id in &config.main.layers {
|
||||||
for glob in &globs {
|
let country = get_country(country_id.to_owned());
|
||||||
for tag in &country.config.tags.clone().unwrap_or(vec![]) {
|
|
||||||
if glob.is_match(tag.as_str()) {
|
let mut matches = false;
|
||||||
matches = true;
|
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 {
|
println!("Dissolved in {:?}", dissolved_time.elapsed());
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
countries.push(country);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add country_rewrite support
|
// 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
|
// 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(
|
fs::create_dir_all(out_folder).unwrap();
|
||||||
countries
|
|
||||||
.iter()
|
|
||||||
.map(|country| (country.id.clone(), json!(country.config))),
|
|
||||||
))
|
|
||||||
.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();
|
println!("Generated files in {:?}", generated_time.elapsed());
|
||||||
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!("Processed in {:?}\n---\n", processed_time.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Total time: {:?}", total_time.elapsed());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Reference in a new issue