Skip to content

Commit

Permalink
ask about summit register fixes #561
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoniecz committed Sep 3, 2020
1 parent 0cd97f4 commit abc62e2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Boolean> {

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<String, String>) = 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()))

}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -889,5 +889,6 @@ Otherwise, you can download another keyboard in the app store. Popular keyboards
<string name="at_conscription_and_street_number">conscription number %1$s, orientation number %2$s:</string>
<string name="at_conscription_number">conscription number %s:</string>
<string name="at_housenumber">house number %s:</string>
<string name="quest_summit_register_title">Is there a summit register at %s?</string>

</resources>

0 comments on commit abc62e2

Please sign in to comment.