fix: tag match

This commit is contained in:
Artemy 2024-05-30 10:22:48 +03:00
parent 3f6e7fccb5
commit 0acf4ecc5c
4 changed files with 44 additions and 24 deletions

View file

@ -1,11 +1,10 @@
use std::{fs, path::Path, time}; use std::{fs, path::Path, time};
use geojson::{Feature, FeatureCollection};
use serde_json::json; use serde_json::json;
use wax::{Glob, Pattern}; use wax::{Glob, Pattern};
use crate::{ use crate::{
types::{CountryData, ToCollection, ToFeature, ToFeatures}, types::{CountryData, ToCollection},
utils::{diff_countries, get_country, read_config}, utils::{diff_countries, get_country, read_config},
}; };
@ -15,11 +14,13 @@ pub fn build() {
let total_time = time::Instant::now(); let total_time = time::Instant::now();
for processing_item in config.processing { for processing_item in config.processing {
println!("--- {} ---", processing_item.output_folder);
let processed_time = time::Instant::now(); let processed_time = time::Instant::now();
let out_folder = Path::new(&processing_item.output_folder); let out_folder = Path::new(&processing_item.output_folder);
let tags = processing_item.tags.unwrap_or(vec!["*".to_string()]); let tags = processing_item.tags.unwrap_or(vec![]);
let globs: Vec<Glob> = tags.iter().map(|tag| Glob::new(tag).unwrap()).collect(); let globs: Vec<Glob> = tags.iter().map(|tag| Glob::new(tag).unwrap()).collect();
let mut countries: Vec<CountryData> = vec![]; let mut countries: Vec<CountryData> = vec![];
@ -27,12 +28,19 @@ pub fn build() {
{ {
let dissolved_time = time::Instant::now(); let dissolved_time = time::Instant::now();
if tags.len() == 0 {
for country_id in &config.main.layers {
countries.push(get_country(country_id.to_owned()));
}
} else {
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());
match &country.config.tags {
Some(tags) => {
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!["*".to_owned()]) { for tag in tags {
if glob.is_match(tag.as_str()) { if glob.is_match(tag.as_str()) {
matches = true; matches = true;
} }
@ -45,6 +53,12 @@ pub fn build() {
countries.push(country); countries.push(country);
} }
None => {
continue;
}
}
}
}
println!("Dissolved in {:?}", dissolved_time.elapsed()); println!("Dissolved in {:?}", dissolved_time.elapsed());
} }
@ -62,6 +76,7 @@ pub fn build() {
}; };
// TODO: Add nature support // TODO: Add nature support
{ {
let generated_time = time::Instant::now(); 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(
@ -88,7 +103,13 @@ pub fn build() {
println!("Generated files in {:?}", generated_time.elapsed()); println!("Generated files in {:?}", generated_time.elapsed());
} }
println!("Processed in {:?}\n---\n", processed_time.elapsed()); let processed = format!("{:?}", processed_time.elapsed());
println!(
"--- {} {}---\n",
processed,
"-".repeat(processing_item.output_folder.len() - processed.len())
);
} }
println!("Total time: {:?}", total_time.elapsed()); println!("Total time: {:?}", total_time.elapsed());

View file

@ -8,6 +8,8 @@ output_folder = "./out/map"
# show_markers = false # show_markers = false
# Information for public repository in cimengine. See: https://github.com/CIMEngine/MapList # Information for public repository in cimengine. See: https://github.com/CIMEngine/MapList
# If you want to add your map to MapList, add link to public.json file in repository at index.json
# {..., "id": { "external": "https://example.com/index.json" } }
# [processing.public] # [processing.public]
# name = "Sample Map" # name = "Sample Map"
# description = "This is a sample map" # description = "This is a sample map"

View file

@ -1,7 +1,7 @@
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use geo::{Geometry, MultiPolygon}; use geo::{Geometry, MultiPolygon};
use geo::{Point, Polygon}; use geo::{Point, Polygon};
use geojson::{Feature, FeatureCollection, Value}; use geojson::{FeatureCollection, Value};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;

View file

@ -1,12 +1,9 @@
use std::{fs, marker, path::Path}; use std::{fs, path::Path};
use geo::{BooleanOps, MultiPolygon}; use geo::{BooleanOps, MultiPolygon};
use geojson::{Feature, FeatureCollection, GeoJson}; use geojson::GeoJson;
use crate::types::{ use crate::types::{Config, CountryConfig, CountryData, Territory, ToMultiPolygon, ToSplitGeo};
Config, CountryConfig, CountryData, Marker, Territory, ToCollection, ToCountryFeature,
ToFeature, ToFeatures, ToMultiPolygon, ToSplitGeo, UnsplitGeo,
};
pub fn read_config() -> Config { pub fn read_config() -> Config {
let c = toml::from_str::<Config>(&fs::read_to_string("config.toml").unwrap()); let c = toml::from_str::<Config>(&fs::read_to_string("config.toml").unwrap());