Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating more filter options #101

Merged
merged 19 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/ios/GuideDogs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@
91C82AAD2A5DCF040086D126 /* GeolocationManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91C82AAC2A5DCF040086D126 /* GeolocationManagerTest.swift */; };
91C82ABE2A6B08500086D126 /* RouteGuidanceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91C82ABD2A6B08500086D126 /* RouteGuidanceTest.swift */; };
91DC0CF92A46134600244CC8 /* GeometryUtilsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 914DEBDC2A3CE901007B161C /* GeometryUtilsTest.swift */; };
AC3A3EE22C40C9080061EEB8 /* NearbyTableFilterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC3A3EE12C40C9080061EEB8 /* NearbyTableFilterTest.swift */; };
B90C27D61EAF81D600007368 /* Sound.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90C27D51EAF81D600007368 /* Sound.swift */; };
B918EE9825100FFF00A5354A /* CalloutRangeContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = B918EE9725100FFF00A5354A /* CalloutRangeContext.swift */; };
B91D3F6427AB5546004159A8 /* UserAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91D3F6327AB5546004159A8 /* UserAction.swift */; };
Expand Down Expand Up @@ -1587,6 +1588,7 @@
915FF9F42ADE3F91002B3690 /* AuthoredActivityContentTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthoredActivityContentTest.swift; sourceTree = "<group>"; };
91C82AAC2A5DCF040086D126 /* GeolocationManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = " GeolocationManagerTest.swift"; path = "UnitTests/Sensors/Geolocation/Geolocation Manager/ GeolocationManagerTest.swift"; sourceTree = SOURCE_ROOT; };
91C82ABD2A6B08500086D126 /* RouteGuidanceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RouteGuidanceTest.swift; path = "UnitTests/Behaviors/Route Guidance/RouteGuidanceTest.swift"; sourceTree = SOURCE_ROOT; };
AC3A3EE12C40C9080061EEB8 /* NearbyTableFilterTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyTableFilterTest.swift; sourceTree = "<group>"; };
B90C27D51EAF81D600007368 /* Sound.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Sound.swift; path = Code/Audio/Protocols/Sound.swift; sourceTree = "<group>"; };
B918EE9725100FFF00A5354A /* CalloutRangeContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalloutRangeContext.swift; sourceTree = "<group>"; };
B91D3F6327AB5546004159A8 /* UserAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserAction.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4283,6 +4285,7 @@
isa = PBXGroup;
children = (
914BAAF22AD745E400CB2171 /* DestinationManagerTest.swift */,
AC3A3EE12C40C9080061EEB8 /* NearbyTableFilterTest.swift */,
);
path = "Destination Manager";
sourceTree = "<group>";
Expand Down Expand Up @@ -5545,6 +5548,7 @@
914BAAFD2AD7483300CB2171 /* AudioEngineTest.swift in Sources */,
914BAAF32AD745E400CB2171 /* DestinationManagerTest.swift in Sources */,
91C82ABE2A6B08500086D126 /* RouteGuidanceTest.swift in Sources */,
AC3A3EE22C40C9080061EEB8 /* NearbyTableFilterTest.swift in Sources */,
91C82AAD2A5DCF040086D126 /* GeolocationManagerTest.swift in Sources */,
91DC0CF92A46134600244CC8 /* GeometryUtilsTest.swift in Sources */,
);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,22 @@
/* Filters, Transit */
"filter.transit" = "Public Transit";

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

/* Filters, Parks */
"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 @@ -3214,12 +3230,6 @@
/* Open Street Map term. Refers to any parking space designed for bicycles, where one can leave a pedal cycle unattended in reasonable security. */
"osm.tag.bike_parking" = "Bike Parking";

/* Open Street Map term. An informal place with sit-down facilities selling beverages and light meals and/or snacks. */
"osm.tag.cafe" = "Cafe";

/* Open Street Map term. Generally a formal eating places with sit-down facilities selling full meals served by waiters and often licensed (where allowed) to sell alcoholic drinks. */
"osm.tag.restaurant" = "Restaurant";

/* Open Street Map term. A public telephone, phone box, or telephone on a stand or wall. Usually you pay to use them, often only via a pre-pay card. */
"osm.tag.telephone" = "Telephone";

Expand All @@ -3240,10 +3250,42 @@

/* Open Street Map term. A bus stop is a place where passengers can board or alight from a bus. Its position may be marked by a shelter, pole, bus lay-by, or road markings. */
"osm.tag.bus_stop" = "Bus Stop";
/* Open Street Map term. A bus stop is a place where passengers can go to a landmark */
"osm.tag.landmark" = "Landmark";

/* Open Street Map term. Used as a display name for place or a location. %@ is a bus stop name, such as "London Bus Stop". */
"osm.tag.bus_stop.named" = "%@ Bus Stop";

/* Open Street Map term. An informal place with sit-down facilities selling beverages and light meals and/or snacks. */
"osm.tag.cafe" = "Cafe";

/* Open Street Map term. Generally a formal eating places with sit-down facilities selling full meals served by waiters and often licensed (where allowed) to sell alcoholic drinks. */
"osm.tag.restaurant" = "restaurant";

/* Open Street Map term. Fast food is a place where food that is prepared and served very quickly. */
"osm.tag.fast_food" = "fast_food";

/* Open Street Map term. A bar is an place where alcoholic beverages are served. */
"osm.tag.bar" = "bar";

/* Open Street Map term. An ice cream shop is a place where ice cream is sold. */
"osm.tag.ice_cream" = "ice_cream";

/* Open Street Map term. A pub is a place selling beer and other alcoholic drinks; may also provide food or accommodation (UK). */
"osm.tag.pub" = "pub";

/* Open Street Map term. A coffee shop isa place that typically sells coffee and pastries. */
"osm.tag.coffee_shop" = "coffee_shop";

/* Open Street Map term. A monument is a structure created to commemorate a person. */
"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";

/* 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 @@ -3280,6 +3322,15 @@
/* 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" = "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 @@ -12,22 +12,67 @@ extension GDASpatialDataResultEntity: Typeable {

func isOfType(_ type: PrimaryType) -> Bool {
switch type {
case .transit: return isOfType(.transitStop)
case .transit:
return isOfType(.transitStop)
case .food:
return isFood()
case .park:
return isPark()
case .bank:
return isBank()
case .grocery:
return isGrocery()
}
}

func isOfType(_ type: SecondaryType) -> Bool {
switch type {
case .transitStop: return isTransitStop()
case .transitStop:
return isTransitStop()
case .food:
return isFood()
case .park:
return isPark()
case .bank:
return isBank()
case .grocery:
return isGrocery()
}
}

private func isTransitStop() -> Bool {
guard let category = SuperCategory(rawValue: superCategory) else {
return false
}

return category == .mobility && localizedName.lowercased().contains(GDLocalizedString("osm.tag.bus_stop").lowercased())
let isTransitLocation = category == .mobility && localizedName.lowercased().contains(GDLocalizedString("osm.tag.bus_stop").lowercased())

return isTransitLocation
}

/// 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 isFood() -> Bool {
return isAnyOf(tags: [
"restaurant", "fast_food", "cafe", "bar", "ice_cream", "pub",
"coffee_shop"
]);
}

private func isPark() -> Bool {
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 isGrocery() -> Bool {
return isAnyOf(tags: ["convenience", "supermarket"]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import Foundation
enum PrimaryType: String, CaseIterable, Type {

case transit
case food
case park
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 @@ -11,6 +11,10 @@ import Foundation
enum SecondaryType: Type {

case transitStop
case food
case park
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 @@ -19,7 +19,11 @@ struct NearbyTableFilter: Equatable {
static var defaultFilters: [NearbyTableFilter] {
return [
.defaultFilter,
NearbyTableFilter(type: .transit)
NearbyTableFilter(type: .transit),
NearbyTableFilter(type: .food),
NearbyTableFilter(type: .park),
NearbyTableFilter(type: .grocery),
NearbyTableFilter(type: .bank),
]
}

Expand Down Expand Up @@ -54,6 +58,18 @@ struct NearbyTableFilter: Equatable {
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 & Drink")
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 & Convenience Stores")
}
} else {
// There is no `PrimaryType` filter selected
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// NearbyTableFilterTest.swift
// UnitTests
//
// Created by Jonathan Ha on 7/11/24.
// Copyright © 2024 Soundscape community. All rights reserved.
//

import XCTest
@testable import Soundscape

final class NearbyTableFilterTest: XCTestCase {

override func setUpWithError() throws {
continueAfterFailure = false
}

override func tearDownWithError() throws {
}

func testDefaultFilter() throws {
let filter = NearbyTableFilter.defaultFilter
XCTAssertNil(filter.type)
XCTAssertEqual(filter.localizedString, GDLocalizedString("filter.all"))
XCTAssertEqual(filter.image, UIImage(named: "AllPlaces"))
}

func testPrimaryTypeFilters() throws {
let filters = NearbyTableFilter.primaryTypeFilters
XCTAssertEqual(filters.count, PrimaryType.allCases.count + 1) // +1 for the default filter

for (index, type) in PrimaryType.allCases.enumerated() {
let filter = filters[index + 1] // First filter is the default filter
XCTAssertEqual(filter.type, type)
switch type {
case .transit:
XCTAssertEqual(filter.localizedString, GDLocalizedString("filter.transit"))
XCTAssertEqual(filter.image, UIImage(named: "Transit"))
case .food:
XCTAssertEqual(filter.localizedString, GDLocalizedString("filter.food_drink"))
XCTAssertEqual(filter.image, UIImage(named: "Food & Drink"))
case .park:
XCTAssertEqual(filter.localizedString, GDLocalizedString("filter.parks"))
XCTAssertEqual(filter.image, UIImage(named: "Parks"))
case .bank:
XCTAssertEqual(filter.localizedString, GDLocalizedString("filter.banks"))
XCTAssertEqual(filter.image, UIImage(named: "Banks & ATMs"))
case .grocery:
XCTAssertEqual(filter.localizedString, GDLocalizedString("filter.groceries"))
XCTAssertEqual(filter.image, UIImage(named: "Groceries & Convenience Stores "))
}
}
}

func testEquality() throws {
let filter1 = NearbyTableFilter(type: .transit)
let filter2 = NearbyTableFilter(type: .transit)
let filter3 = NearbyTableFilter(type: .food)

XCTAssertEqual(filter1, filter2)
XCTAssertNotEqual(filter1, filter3)
}
}
Loading