11use std:: { fs, path:: Path , time} ;
22
3- use geojson:: { Feature , FeatureCollection } ;
43use serde_json:: json;
54use wax:: { Glob , Pattern } ;
65
76use crate :: {
8- types:: { CountryData , ToCollection , ToFeature , ToFeatures } ,
7+ types:: { CountryData , ToCollection } ,
98 utils:: { diff_countries, get_country, read_config} ,
109} ;
1110
@@ -15,35 +14,50 @@ pub fn build() {
1514 let total_time = time:: Instant :: now ( ) ;
1615
1716 for processing_item in config. processing {
17+ println ! ( "--- {} ---" , processing_item. output_folder) ;
18+
1819 let processed_time = time:: Instant :: now ( ) ;
1920
2021 let out_folder = Path :: new ( & processing_item. output_folder ) ;
2122
22- let tags = processing_item. tags . unwrap_or ( vec ! [ "*" . to_string ( ) ] ) ;
23+ let tags = processing_item. tags . unwrap_or ( vec ! [ ] ) ;
2324 let globs: Vec < Glob > = tags. iter ( ) . map ( |tag| Glob :: new ( tag) . unwrap ( ) ) . collect ( ) ;
2425
2526 let mut countries: Vec < CountryData > = vec ! [ ] ;
2627
2728 {
2829 let dissolved_time = time:: Instant :: now ( ) ;
2930
30- for country_id in & config. main . layers {
31- let country = get_country ( country_id. to_owned ( ) ) ;
32-
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 ;
31+ if tags. len ( ) == 0 {
32+ for country_id in & config. main . layers {
33+ countries. push ( get_country ( country_id. to_owned ( ) ) ) ;
34+ }
35+ } else {
36+ for country_id in & config. main . layers {
37+ let country = get_country ( country_id. to_owned ( ) ) ;
38+
39+ match & country. config . tags {
40+ Some ( tags) => {
41+ let mut matches = false ;
42+ for glob in & globs {
43+ for tag in tags {
44+ if glob. is_match ( tag. as_str ( ) ) {
45+ matches = true ;
46+ }
47+ }
48+ }
49+
50+ if !matches {
51+ continue ;
52+ }
53+
54+ countries. push ( country) ;
55+ }
56+ None => {
57+ continue ;
3858 }
3959 }
4060 }
41-
42- if !matches {
43- continue ;
44- }
45-
46- countries. push ( country) ;
4761 }
4862
4963 println ! ( "Dissolved in {:?}" , dissolved_time. elapsed( ) ) ;
@@ -62,6 +76,7 @@ pub fn build() {
6276 } ;
6377
6478 // TODO: Add nature support
79+
6580 {
6681 let generated_time = time:: Instant :: now ( ) ;
6782 let countries_json = serde_json:: to_string_pretty ( & serde_json:: Map :: from_iter (
@@ -88,7 +103,13 @@ pub fn build() {
88103 println ! ( "Generated files in {:?}" , generated_time. elapsed( ) ) ;
89104 }
90105
91- println ! ( "Processed in {:?}\n ---\n " , processed_time. elapsed( ) ) ;
106+ let processed = format ! ( "{:?}" , processed_time. elapsed( ) ) ;
107+
108+ println ! (
109+ "--- {} {}---\n " ,
110+ processed,
111+ "-" . repeat( processing_item. output_folder. len( ) - processed. len( ) )
112+ ) ;
92113 }
93114
94115 println ! ( "Total time: {:?}" , total_time. elapsed( ) ) ;
0 commit comments