From abc62e2e0c8be23671a35a9f824afb0f02099205 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Thu, 3 Sep 2020 11:49:43 +0200 Subject: [PATCH] ask about summit register fixes #561 --- .../streetcomplete/quests/QuestModule.kt | 2 + .../summit_register/AddSummitRegister.kt | 74 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 77 insertions(+) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/quests/summit_register/AddSummitRegister.kt diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.kt index da021d7dff..c05535a845 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/QuestModule.kt @@ -57,6 +57,7 @@ import de.westnordost.streetcomplete.quests.postbox_collection_times.AddPostboxC import de.westnordost.streetcomplete.quests.postbox_ref.AddPostboxRef import de.westnordost.streetcomplete.quests.powerpoles_material.AddPowerPolesMaterial import de.westnordost.streetcomplete.quests.railway_crossing.AddRailwayCrossingBarrier +import de.westnordost.streetcomplete.quests.railway_crossing.AddSummitRegister import de.westnordost.streetcomplete.quests.recycling.AddRecyclingType import de.westnordost.streetcomplete.quests.recycling_glass.DetermineRecyclingGlass import de.westnordost.streetcomplete.quests.recycling_material.AddRecyclingContainerMaterials @@ -177,6 +178,7 @@ object QuestModule // ↓ 8. defined in the wiki, but not really used by anyone yet. Just collected for // the sake of mapping it in case it makes sense later + AddSummitRegister(o, r), AddCyclewayPartSurface(o, r), AddFootwayPartSurface(o, r), AddMotorcycleParkingCover(o), diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/summit_register/AddSummitRegister.kt b/app/src/main/java/de/westnordost/streetcomplete/quests/summit_register/AddSummitRegister.kt new file mode 100644 index 0000000000..d007cace7f --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/summit_register/AddSummitRegister.kt @@ -0,0 +1,74 @@ +package de.westnordost.streetcomplete.quests.railway_crossing + +import de.westnordost.osmapi.map.data.BoundingBox +import de.westnordost.osmapi.map.data.Element +import de.westnordost.streetcomplete.R +import de.westnordost.streetcomplete.data.elementfilter.filters.RelativeDate +import de.westnordost.streetcomplete.data.elementfilter.filters.TagOlderThan +import de.westnordost.streetcomplete.data.osm.elementgeometry.ElementGeometry +import de.westnordost.streetcomplete.data.osm.osmquest.OsmElementQuestType +import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder +import de.westnordost.streetcomplete.data.osm.mapdata.OverpassMapDataAndGeometryApi +import de.westnordost.streetcomplete.data.elementfilter.getQuestPrintStatement +import de.westnordost.streetcomplete.data.elementfilter.toGlobalOverpassBBox +import de.westnordost.streetcomplete.data.meta.updateWithCheckDate +import de.westnordost.streetcomplete.data.quest.NoCountriesExcept +import de.westnordost.streetcomplete.quests.YesNoQuestAnswerFragment +import de.westnordost.streetcomplete.settings.ResurveyIntervalsStore + +class AddSummitRegister( + private val overpassMapDataApi: OverpassMapDataAndGeometryApi, + private val r: ResurveyIntervalsStore +) : OsmElementQuestType { + + override val commitMessage = "Add whatever summit register is present" + override val wikiLink = "Key:summit:register" + override val icon = R.drawable.ic_quest_railway + + override val enabledInCountries = NoCountriesExcept( + // regions gathered in + // https://github.com/westnordost/StreetComplete/issues/561#issuecomment-325623974 + + // Europe + "AT", "DE", "CZ", "ES", "IT", "FR", "GR", "SI", "CH", "RO", "SK", + + //Americas + "US", "AR", "PE" + ) + + override fun getTitle(tags: Map) = R.string.quest_summit_register_title + + override fun createForm() = YesNoQuestAnswerFragment() + + override fun download(bbox: BoundingBox, handler: (element: Element, geometry: ElementGeometry?) -> Unit): Boolean { + return overpassMapDataApi.query(getOverpassQuery(bbox), handler) + } + + override fun isApplicableTo(element: Element): Boolean? = null + + override fun applyAnswerTo(answer: Boolean, changes: StringMapChangesBuilder) { + if (answer) { + changes.updateWithCheckDate("summit:register", "yes") + } else { + changes.updateWithCheckDate("summit:register", "no") + } + } + + private fun getOverpassQuery(bbox: BoundingBox) = """ + ${bbox.toGlobalOverpassBBox()} + + ( + relation["route"="hiking"]; + )->.hiking; + node(around.hiking:10)[natural=peak][!"summit:register"][name] -> .summits_with_unknown_status; + node(around.hiking:10)["summit:register"][name]${olderThan(8).toOverpassQLString()} -> .summits_with_old_status; + + (.summits_with_unknown_status; .summits_with_old_status;); + + ${getQuestPrintStatement()} + """.trimIndent() + + private fun olderThan(years: Int) = + TagOlderThan("summit:register", RelativeDate(-(r * 365 * years).toFloat())) + +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2670e44a6..9d15c967c2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -889,5 +889,6 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards conscription number %1$s, orientation number %2$s: conscription number %s: house number %s: + Is there a summit register at %s?