1- use std:: { fs, path:: Path } ;
1+ use std:: { fs, path:: Path , time } ;
22
33use geojson:: { Feature , FeatureCollection } ;
44use serde_json:: json;
@@ -12,8 +12,10 @@ use crate::{
1212pub fn build ( ) {
1313 let config = read_config ( ) ;
1414
15+ let total_time = time:: Instant :: now ( ) ;
16+
1517 for processing_item in config. processing {
16- let features : Vec < Feature > = vec ! [ ] ;
18+ let processed_time = time :: Instant :: now ( ) ;
1719
1820 let out_folder = Path :: new ( & processing_item. output_folder ) ;
1921
@@ -22,48 +24,72 @@ pub fn build() {
2224
2325 let mut countries: Vec < CountryData > = vec ! [ ] ;
2426
25- for country_id in & config. main . layers {
26- let country = get_country ( country_id. to_owned ( ) ) ;
27+ {
28+ let dissolved_time = time:: Instant :: now ( ) ;
29+
30+ for country_id in & config. main . layers {
31+ let country = get_country ( country_id. to_owned ( ) ) ;
2732
28- let mut matches = false ;
29- for glob in & globs {
30- for tag in & country. config . tags . clone ( ) . unwrap_or ( vec ! [ ] ) {
31- if glob. is_match ( tag. as_str ( ) ) {
32- matches = true ;
33+ let mut matches = false ;
34+ for glob in & globs {
35+ for tag in & country. config . tags . clone ( ) . unwrap_or ( vec ! [ "*" . to_owned( ) ] ) {
36+ if glob. is_match ( tag. as_str ( ) ) {
37+ matches = true ;
38+ }
3339 }
3440 }
35- }
3641
37- if !matches {
38- continue ;
42+ if !matches {
43+ continue ;
44+ }
45+
46+ countries. push ( country) ;
3947 }
4048
41- countries . push ( country ) ;
49+ println ! ( "Dissolved in {:?}" , dissolved_time . elapsed ( ) ) ;
4250 }
4351
4452 // TODO: Add country_rewrite support
4553
46- let countries = diff_countries ( countries) ;
54+ let countries = {
55+ let diff_time = time:: Instant :: now ( ) ;
4756
48- // TODO: Add nature support
57+ let countries = diff_countries ( countries ) ;
4958
50- let countries_json = serde_json:: to_string_pretty ( & serde_json:: Map :: from_iter (
51- countries
52- . iter ( )
53- . map ( |country| ( country. id . clone ( ) , json ! ( country. config) ) ) ,
54- ) )
55- . unwrap ( ) ;
59+ println ! ( "Diffed in {:?}" , diff_time. elapsed( ) ) ;
5660
57- let feature_collection = countries. to_collection ( ) . to_string ( ) ;
58-
59- fs:: create_dir_all ( out_folder) . unwrap ( ) ;
61+ countries
62+ } ;
6063
61- fs:: write ( out_folder. join ( "geo.geojson" ) , feature_collection) . unwrap ( ) ;
62- fs:: write ( out_folder. join ( "countries.json" ) , countries_json) . unwrap ( ) ;
64+ // TODO: Add nature support
65+ {
66+ let generated_time = time:: Instant :: now ( ) ;
67+ let countries_json = serde_json:: to_string_pretty ( & serde_json:: Map :: from_iter (
68+ countries
69+ . iter ( )
70+ . map ( |country| ( country. id . clone ( ) , json ! ( country. config) ) ) ,
71+ ) )
72+ . unwrap ( ) ;
73+
74+ fs:: create_dir_all ( out_folder) . unwrap ( ) ;
75+
76+ fs:: write (
77+ out_folder. join ( "geo.geojson" ) ,
78+ countries. to_collection ( ) . to_string ( ) ,
79+ )
80+ . unwrap ( ) ;
81+ fs:: write ( out_folder. join ( "countries.json" ) , countries_json) . unwrap ( ) ;
82+
83+ if let Some ( public) = processing_item. public {
84+ let public = serde_json:: to_string ( & public) . unwrap ( ) ;
85+ fs:: write ( out_folder. join ( "public.json" ) , public) . unwrap ( ) ;
86+ }
6387
64- if let Some ( public) = processing_item. public {
65- let public = serde_json:: to_string ( & public) . unwrap ( ) ;
66- fs:: write ( out_folder. join ( "public.json" ) , public) . unwrap ( ) ;
88+ println ! ( "Generated files in {:?}" , generated_time. elapsed( ) ) ;
6789 }
90+
91+ println ! ( "Processed in {:?}\n ---\n " , processed_time. elapsed( ) ) ;
6892 }
93+
94+ println ! ( "Total time: {:?}" , total_time. elapsed( ) ) ;
6995}
0 commit comments