All good
Some checks failed
CI / Check (push) Has been cancelled
Build and publish Docker image / build-and-push (push) Has been cancelled

This commit is contained in:
Andras Schmelczer 2026-05-18 21:20:10 +01:00
parent 6ea544a0f6
commit 6cc7288126
45 changed files with 929 additions and 1043 deletions

View file

@ -30,16 +30,6 @@ const GROCERY_DASHBOARD_CATEGORIES: &[&str] = &[
"Budgens",
"Centra",
"Co-op",
"Central England Co-operative",
"Chelmsford Star Co-operative Society",
"East of England Co-operative",
"Heart of England Co-operative",
"Lincolnshire Co-operative",
"Midcounties Co-operative",
"Scottish Midland Co-operative",
"Tamworth Co-operative Society",
"The Radstock Co-operative Society",
"The Southern Co-operative",
"COOK",
"Costco",
"Dunnes Stores",
@ -104,10 +94,35 @@ fn add_category_filter_index(
}
}
fn canonical_poi_category(category: &str) -> &str {
match category {
"Allendale Co-operative Society"
| "Central England Co-operative"
| "Channel Islands Co-operative Society"
| "Chelmsford Star Co-operative Society"
| "Clydebank Co-operative"
| "Coniston Co-operative Society"
| "Co-op Food"
| "East of England Co-operative"
| "Heart of England Co-operative"
| "Langdale Co-operative Society"
| "Lincolnshire Co-operative"
| "Midcounties Co-operative"
| "Scottish Midland Co-operative"
| "Tamworth Co-operative Society"
| "The Co-operative Food"
| "The Co-operative Food PFS"
| "The Co-operative Group"
| "The Radstock Co-operative Society"
| "The Southern Co-operative" => "Co-op",
_ => category,
}
}
pub fn resolve_poi_category_filter(category_values: &[String], categories: &str) -> FxHashSet<u16> {
let mut selected = FxHashSet::default();
for part in categories.split(',') {
let category = part.trim();
let category = canonical_poi_category(part.trim());
if category.is_empty() {
continue;
}
@ -200,12 +215,18 @@ impl POIData {
let id_raw: Vec<String> = extract_str_col(&df, "id")?;
let name = extract_str_col(&df, "name")?;
let category_raw = extract_str_col(&df, "category")?;
let category_raw: Vec<String> = extract_str_col(&df, "category")?
.into_iter()
.map(|category| canonical_poi_category(&category).to_string())
.collect();
let group_raw = extract_str_col(&df, "group")?;
let lat = extract_f32_col(&df, "lat")?;
let lng = extract_f32_col(&df, "lng")?;
let emoji_raw = extract_str_col(&df, "emoji")?;
let icon_category_raw = extract_str_col(&df, "icon_category")?;
let icon_category_raw: Vec<String> = extract_str_col(&df, "icon_category")?
.into_iter()
.map(|category| canonical_poi_category(&category).to_string())
.collect();
// Pack POI IDs into a contiguous buffer
let total_id_bytes: usize = id_raw.iter().map(|s| s.len()).sum();
@ -351,4 +372,19 @@ mod tests {
assert!(selected.is_empty());
}
#[test]
fn coop_category_aliases_resolve_to_single_category() {
let values = vec!["Co-op".to_string(), "Tesco".to_string()];
let selected = resolve_poi_category_filter(
&values,
"Central England Co-operative,The Southern Co-operative",
);
assert!(selected.contains(&0));
assert_eq!(selected.len(), 1);
assert_eq!(canonical_poi_category("Lincolnshire Co-operative"), "Co-op");
assert_eq!(canonical_poi_category("Tesco"), "Tesco");
}
}