Skip to content

Commit

Permalink
Clean up Places Nearby filter implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbro committed Sep 7, 2024
1 parent 97e660e commit 3ffa533
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 153 deletions.

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1533,11 +1533,21 @@
/* Filters, Transit */
"filter.transit" = "Public Transit";

/* Filters, Landmarks */
"filter.landmarks" = "Landmarks";
/* Filters, Food & Drink */
"filter.food_drink" = "Food & Drink";

/* Filters, Parks */
"filter.park" = "Park";
"filter.parks" = "Parks";

/* Filter, Things To Do */
"filter.things_to_do" = "Things to do";

/* Filters, Groceries & Convenience Stores */
"filter.groceries" = "Groceries & Convenience Stores";

/* Filters, Banks & ATMs */
"filter.banks" = "Banks & ATMs";


/* Displayed next to the name of the filter to indicate that the filter is currently selected. %@ is the name of a filter */
"filter.selected" = "%@ (selected)";
Expand Down Expand Up @@ -3268,13 +3278,13 @@
"osm.tag.coffee_shop" = "coffee_shop";

/* Open Street Map term. A monument is a structure created to commemorate a person. */
"osm.tag.monument" = "monument";
"osm.tag.monument" = "Monument";
/* Other OSM tags... */
"osm.tag.statue" = "statue";
"osm.tag.museum" = "museum";
"osm.tag.historic" = "historic";
"osm.tag.landmark" = "landmark";
"osm.tag.cathedral" = "cathedral";
"osm.tag.statue" = "Statue";
"osm.tag.museum" = "Museum";
"osm.tag.historic" = "Historic";
"osm.tag.landmark" = "Landmark";
"osm.tag.cathedral" = "Cathedral";

/* Open Street Map term. Used as a display name for place or a location. %@ is a bus stop id, such as "Bus Stop 7" or "Bus Stop B". */
"osm.tag.bus_stop.refed" = "Bus Stop %@";
Expand Down Expand Up @@ -3310,18 +3320,17 @@
"osm.tag.garden" = "Garden";

/* Open Street Map term. An area of open space for recreational use, usually designed and in semi-natural state with grassy areas, trees and bushes. Parks are usually urban, but not always. */
"osm.tag.park" = "leisure=park";

//TODO JON
"osm.tag.garden" = "leisure=garden";
"osm.tag.playground" = "leisure=playground";
"osm.tag.nature_reserve" = "leisure=nature_reserve";
"osm.tag.botanical_garden" = "leisure=botanical_garden";
"osm.tag.public_garden" = "leisure=public_garden";
"osm.tag.field" = "leisure=field";
"osm.tag.reserve" = "leisure=reserve";
"osm.tag.green_space" = "leisure=green_space";
"osm.tag.recreation_area" = "leisure=recreation_area";
"osm.tag.park" = "Park";

"osm.tag.playground" = "Playground";
"osm.tag.nature_reserve" = "Nature Reserve";
"osm.tag.botanical_garden" = "Botanical Garden";
"osm.tag.public_garden" = "Public Garden";
"osm.tag.field" = "Field";
"osm.tag.reserve" = "Reserve";
"osm.tag.green_space" = "Green Space";
"osm.tag.recreation_area" = "Recreation Area";

/* Open Street Map term. A table with benches, ideal for food and rest. */
"osm.tag.picnic_table" = "Picnic Table";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class AuthoredActivityLoader {

for (wptIndex, waypoint) in content.waypoints.enumerated() {
for (clipIndex, image) in waypoint.images.enumerated() {
guard let key = manager.cacheKey(for: image.url), await manager.imageCache.containsImage!(forKey: key, cacheType: .all) == .none else {
guard let key = manager.cacheKey(for: image.url), await manager.imageCache.containsImage(forKey: key, cacheType: .all) == .none else {
GDLogInfo(.authoredContent, "Image \(image.url.lastPathComponent) already cached (waypoint: \(wptIndex), clip: \(clipIndex))")
continue
}
Expand Down Expand Up @@ -554,7 +554,7 @@ class AuthoredActivityLoader {

for image in images {
if let key = manager.cacheKey(for: image) {
manager.imageCache.removeImage!(forKey: key, cacheType: .all)
manager.imageCache.removeImage(forKey: key, cacheType: .all)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ extension GDASpatialDataResultEntity: Typeable {
return isOfType(.transitStop)
case .food:
return isFood()
case .landmarks:
return isLandmarks()
case .park:
return isPark()
case .hotel:
return isHotel()
case .bank:
return isBank()
case .grocery:
return isGrocery()
}
}

Expand All @@ -31,94 +31,48 @@ extension GDASpatialDataResultEntity: Typeable {
return isTransitStop()
case .food:
return isFood()
case .landmarks:
return isLandmarks()
case .park:
return isPark()
case .hotel:
return isHotel()
case .bank:
return isBank()
case .grocery:
return isGrocery()
}
}

private func isTransitStop() -> Bool {
print("Raw superCategory: \(superCategory)")
guard let category = SuperCategory(rawValue: superCategory) else {
return false
}
print("Mapped category: \(category)")
let isTransitLocation = category == .mobility && localizedName.lowercased().contains(GDLocalizedString("osm.tag.bus_stop").lowercased())

return isTransitLocation
}

private func isFood() -> Bool {

guard let category = SuperCategory(rawValue: superCategory) else {
return false
}
print("Mapped category: \(category)")

let restaurantTags = [
GDLocalizedString("osm.tag.restaurant"),
GDLocalizedString("osm.tag.fast_food"),
GDLocalizedString("osm.tag.cafe"),
GDLocalizedString("osm.tag.bar"),
GDLocalizedString("osm.tag.ice_cream"),
GDLocalizedString("osm.tag.pub"),
GDLocalizedString("osm.tag.coffee_shop")

]

let isRestaurantLocation = category == .places && restaurantTags.contains(amenity)

return isRestaurantLocation
/// All filters follow the same pattern: is amenity any one of a set of tags?
private func isAnyOf(tags: Array<String>) -> Bool {
return tags.contains(amenity)
}

private func isLandmarks() -> Bool {
guard let category = SuperCategory(rawValue: superCategory) else {
print("Failed to map superCategory to SuperCategory enum")
return false
}

let landmarkTags = [
"monument", "statue", "museum", "historic", "cathedral"
]

let lowercasedAmenity = amenity.lowercased()

let isLandmarkLocation = category == .landmarks && landmarkTags.contains { tag in tag == lowercasedAmenity }

print("Place name: \(localizedName)")
print("Landmark location check: \(isLandmarkLocation)")
print("Raw superCategory: \(superCategory)")
print("Mapped category: \(category)")

return isLandmarkLocation
private func isFood() -> Bool {
return isAnyOf(tags: [
"restaurant", "fast_food", "cafe", "bar", "ice_cream", "pub",
"coffee_shop"
]);
}

private func isPark() -> Bool {
guard let category = SuperCategory(rawValue: superCategory) else {
print("Failed to map superCategory to SuperCategory enum")
return false
}

let parkTags = [
"park", "garden", "green_space", "recreation_area", "playground",
"nature_reserve", "botanical_garden", "public_garden", "field", "reserve"
]

let lowercasedAmenity = amenity.lowercased()

let isParkLocation = category == .places && parkTags.contains { tag in tag == lowercasedAmenity }
print("Place name: \(localizedName)")
print("Park location check: \(isParkLocation)")
print("Raw superCategory: \(superCategory)")
print("Mapped category: \(category)")
return isParkLocation
return isAnyOf(tags: [
"park", "garden", "green_space", "recreation_area", "playground",
"nature_reserve", "botanical_garden", "public_garden", "field", "reserve"
]);
}

private func isBank() -> Bool {
return isAnyOf(tags: ["bank", "atm"]);
}
private func isHotel() -> Bool {
return false

private func isGrocery() -> Bool {
return isAnyOf(tags: ["convenience", "supermarket"]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ enum SuperCategory: String {
case landmarks = "landmark"
case places = "place"
case mobility = "mobility"
case foods = "food"
case parks = "park"
case information = "information"
case objects = "object"
case safety = "safety"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ enum PrimaryType: String, CaseIterable, Type {

case transit
case food
case landmarks
case park
case hotel
case bank
case grocery

func matches(poi: POI) -> Bool {
guard let typeable = poi as? Typeable else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ enum SecondaryType: Type {

case transitStop
case food
case landmarks
case park
case hotel
case bank
case grocery

func matches(poi: POI) -> Bool {
guard let typeable = poi as? Typeable else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,6 @@ class GeoJsonFeature {
return
}

//TODO JON
if value == "fast_food"{
superCategory = SuperCategory.foods
return
}

if value == "restaurants"{
superCategory = SuperCategory.foods
return
}


if value == "food"{
superCategory = SuperCategory.foods
return
}


if value == "deli"{
superCategory = SuperCategory.foods
return
}


// Case: Banks
if value == "bank" {
superCategory = SuperCategory.places
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ struct NearbyTableFilter: Equatable {
.defaultFilter,
NearbyTableFilter(type: .transit),
NearbyTableFilter(type: .food),
NearbyTableFilter(type: .landmarks),
NearbyTableFilter(type: .park),
NearbyTableFilter(type: .hotel)
NearbyTableFilter(type: .grocery),
NearbyTableFilter(type: .bank),
]
}

Expand Down Expand Up @@ -54,24 +54,24 @@ struct NearbyTableFilter: Equatable {
self.type = type

if let type = type {
switch type {
case .transit:
self.localizedString = GDLocalizedString("filter.transit")
self.image = UIImage(named: "Transit")
case .food:
self.localizedString = GDLocalizedString("filter.food_drink")
self.image = UIImage(named: "Food and Drinks")
case .landmarks:
self.localizedString = GDLocalizedString("filter.landmarks")
self.image = UIImage(named: "Landmarks")
case .park:
self.localizedString = GDLocalizedString("filter.park")
self.image = UIImage(named: "Parks")
case .hotel:
self.localizedString = GDLocalizedString("filter.hotel")
self.image = UIImage(named: "Hotel")
}
} else {
switch type {
case .transit:
self.localizedString = GDLocalizedString("filter.transit")
self.image = UIImage(named: "Transit")
case .food:
self.localizedString = GDLocalizedString("filter.food_drink")
self.image = UIImage(named: "Food and Drinks")
case .park:
self.localizedString = GDLocalizedString("filter.parks")
self.image = UIImage(named: "Parks")
case .bank:
self.localizedString = GDLocalizedString("filter.banks")
self.image = UIImage(named: "Banks & ATMs")
case .grocery:
self.localizedString = GDLocalizedString("filter.groceries")
self.image = UIImage(named: "Groceries")
}
} else {
// There is no `PrimaryType` filter selected
self.localizedString = GDLocalizedString("filter.all")
self.image = UIImage(named: "AllPlaces")
Expand Down

0 comments on commit 3ffa533

Please sign in to comment.