mirror of
https://github.com/CIMEngine/cimengine-build-tools.git
synced 2024-11-21 19:56:22 +03:00
fix: tag match
This commit is contained in:
parent
3f6e7fccb5
commit
0acf4ecc5c
4 changed files with 44 additions and 24 deletions
55
src/build.rs
55
src/build.rs
|
@ -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,23 +28,36 @@ pub fn build() {
|
||||||
{
|
{
|
||||||
let dissolved_time = time::Instant::now();
|
let dissolved_time = time::Instant::now();
|
||||||
|
|
||||||
for country_id in &config.main.layers {
|
if tags.len() == 0 {
|
||||||
let country = get_country(country_id.to_owned());
|
for country_id in &config.main.layers {
|
||||||
|
countries.push(get_country(country_id.to_owned()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for country_id in &config.main.layers {
|
||||||
|
let country = get_country(country_id.to_owned());
|
||||||
|
|
||||||
let mut matches = false;
|
match &country.config.tags {
|
||||||
for glob in &globs {
|
Some(tags) => {
|
||||||
for tag in &country.config.tags.clone().unwrap_or(vec!["*".to_owned()]) {
|
let mut matches = false;
|
||||||
if glob.is_match(tag.as_str()) {
|
for glob in &globs {
|
||||||
matches = true;
|
for tag in tags {
|
||||||
|
if glob.is_match(tag.as_str()) {
|
||||||
|
matches = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matches {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
countries.push(country);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !matches {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
countries.push(country);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
|
|
Loading…
Add table
Reference in a new issue