-
-
Notifications
You must be signed in to change notification settings - Fork 406
Sidewalk surface quest #3735
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
Merged
westnordost
merged 16 commits into
streetcomplete:master
from
arrival-spring:sidewalk-surface
Mar 4, 2022
Merged
Sidewalk surface quest #3735
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d0978ad
Add sidewalk surface quest
arrival-spring 7104099
Add sidewalk surface tests and fix
arrival-spring 664aa20
Improve checking if surface changed
arrival-spring b42f1bb
Display surface as floating circular image
arrival-spring 0e40b34
Fix surface image icon display
arrival-spring 86daf49
Show unknown icons correctly for left hand drive and remove unneeded …
arrival-spring 4d52783
Add sidewalk surface icon
arrival-spring 3b5ba3f
Don't include side in check_date
arrival-spring e3597eb
Simplify element filter
arrival-spring 3590944
Better comment
arrival-spring f2b5842
Check for sidewalk:both
arrival-spring 2435b29
Comment about filter and fix achievements
arrival-spring 3431791
Merge branch 'master' into sidewalk-surface
arrival-spring d4d6bad
Fixes after merge and tidying
arrival-spring bb74e8f
shortcut
westnordost 71a523d
consistent naming + simplify return statement
westnordost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...treetcomplete/quests/sidewalk/Sidewalk.kt → ...t/streetcomplete/osm/sidewalk/Sidewalk.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/src/main/java/de/westnordost/streetcomplete/osm/sidewalk/SidewalkParser.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package de.westnordost.streetcomplete.osm.sidewalk | ||
|
|
||
| import de.westnordost.streetcomplete.ktx.containsAny | ||
| import de.westnordost.streetcomplete.osm.sidewalk.Sidewalk.NO | ||
| import de.westnordost.streetcomplete.osm.sidewalk.Sidewalk.SEPARATE | ||
| import de.westnordost.streetcomplete.osm.sidewalk.Sidewalk.YES | ||
|
|
||
|
|
||
| data class LeftAndRightSidewalk(val left: Sidewalk?, val right: Sidewalk?) | ||
|
|
||
| /** Returns on which sides are sidewalks. Returns null if tagging is unknown */ | ||
| fun createSidewalkSides(tags: Map<String, String>): LeftAndRightSidewalk? { | ||
| if (!tags.keys.containsAny(KNOWN_SIDEWALK_KEYS)) return null | ||
|
|
||
| val sidewalk = createSidewalksDefault(tags) | ||
| if (sidewalk != null) return sidewalk | ||
|
|
||
| // alternative tagging | ||
| val altSidewalk = createSidewalksAlternative(tags) | ||
| if (altSidewalk != null) return altSidewalk | ||
|
|
||
| return null | ||
| } | ||
|
|
||
| private fun createSidewalksDefault(tags: Map<String, String>): LeftAndRightSidewalk? = when(tags["sidewalk"]) { | ||
| "left" -> LeftAndRightSidewalk(left = YES, right = NO) | ||
| "right" -> LeftAndRightSidewalk(left = NO, right = YES) | ||
| "both" -> LeftAndRightSidewalk(left = YES, right = YES) | ||
| "no" -> LeftAndRightSidewalk(left = NO, right = NO) | ||
| "none" -> LeftAndRightSidewalk(left = NO, right = NO) | ||
| "separate" -> LeftAndRightSidewalk(left = SEPARATE, right = SEPARATE) | ||
| else -> null | ||
| } | ||
|
|
||
| private fun createSidewalksAlternative(tags: Map<String, String>): LeftAndRightSidewalk? { | ||
| val sidewalkLeft = tags["sidewalk:both"] ?: tags["sidewalk:left"] | ||
| val sidewalkRight = tags["sidewalk:both"] ?: tags["sidewalk:right"] | ||
| return if (sidewalkLeft != null || sidewalkRight != null) { | ||
| LeftAndRightSidewalk(left = createSidewalkSide(sidewalkLeft), right = createSidewalkSide(sidewalkRight)) | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| private fun createSidewalkSide(tag: String?): Sidewalk? = when(tag) { | ||
| "yes" -> YES | ||
| "no" -> NO | ||
| "separate" -> SEPARATE | ||
| else -> null | ||
| } | ||
|
|
||
| private val KNOWN_SIDEWALK_KEYS = listOf( | ||
| "sidewalk", "sidewalk:left", "sidewalk:right", "sidewalk:both" | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
app/src/main/java/de/westnordost/streetcomplete/quests/sidewalk/AddSidewalkForm.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
app/src/main/java/de/westnordost/streetcomplete/quests/sidewalk/SidewalkItem.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
app/src/main/java/de/westnordost/streetcomplete/quests/surface/AddSidewalkSurface.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| package de.westnordost.streetcomplete.quests.surface | ||
|
|
||
| import de.westnordost.streetcomplete.R | ||
| import de.westnordost.streetcomplete.data.meta.ANYTHING_UNPAVED | ||
| import de.westnordost.streetcomplete.data.meta.SIDEWALK_SURFACE_KEYS | ||
| import de.westnordost.streetcomplete.data.meta.hasCheckDateForKey | ||
| import de.westnordost.streetcomplete.data.meta.removeCheckDatesForKey | ||
| import de.westnordost.streetcomplete.data.meta.updateCheckDateForKey | ||
| import de.westnordost.streetcomplete.data.meta.updateWithCheckDate | ||
| import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType | ||
| import de.westnordost.streetcomplete.data.osm.osmquests.Tags | ||
| import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.OUTDOORS | ||
| import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.PEDESTRIAN | ||
| import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.WHEELCHAIR | ||
|
|
||
| class AddSidewalkSurface : OsmFilterQuestType<SidewalkSurfaceAnswer>() { | ||
|
|
||
| override val elementFilter = """ | ||
| ways with | ||
| highway ~ trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified|residential | ||
| and area != yes | ||
| and motorroad != yes | ||
| and ( | ||
| sidewalk = both or sidewalk = left or sidewalk = right or | ||
arrival-spring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (sidewalk:left = yes and sidewalk:right ~ yes|no|separate) or | ||
| (sidewalk:right = yes and sidewalk:left ~ yes|no|separate) | ||
westnordost marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| and ( | ||
| ${SIDEWALK_SURFACE_KEYS.joinToString(" and ") {"!$it"}} | ||
| or sidewalk:both:surface ~ ${ANYTHING_UNPAVED.joinToString("|")} and sidewalk:both:surface older today -4 years | ||
| or sidewalk:left:surface ~ ${ANYTHING_UNPAVED.joinToString("|")} and sidewalk:left:surface older today -4 years | ||
| or sidewalk:right:surface ~ ${ANYTHING_UNPAVED.joinToString("|")} and sidewalk:right:surface older today -4 years | ||
arrival-spring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| or ${SIDEWALK_SURFACE_KEYS.joinToString(" or ") {"$it older today -8 years"}} | ||
| or ( | ||
| sidewalk:both:surface ~ paved|unpaved|cobblestone | ||
| and !sidewalk:both:surface:note | ||
| and !note:sidewalk:both:surface | ||
| ) | ||
| or ( | ||
| sidewalk:left:surface ~ paved|unpaved|cobblestone | ||
| and !sidewalk:left:surface:note | ||
| and !note:sidewalk:left:surface | ||
| ) | ||
| or ( | ||
| sidewalk:right:surface ~ paved|unpaved|cobblestone | ||
| and !sidewalk:right:surface:note | ||
| and !note:sidewalk:right:surface | ||
| ) | ||
arrival-spring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| """ | ||
|
|
||
| override val changesetComment = "Add surface of sidewalks" | ||
| override val wikiLink = "Key:sidewalk" | ||
| override val icon = R.drawable.ic_quest_sidewalk_surface | ||
| override val isSplitWayEnabled = true | ||
| override val questTypeAchievements = listOf(PEDESTRIAN, WHEELCHAIR, OUTDOORS) | ||
arrival-spring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| override val defaultDisabledMessage = R.string.default_disabled_msg_difficult_and_time_consuming | ||
|
|
||
| override fun getTitle(tags: Map<String, String>) : Int = | ||
| R.string.quest_sidewalk_surface_title | ||
|
|
||
| override fun createForm() = AddSidewalkSurfaceForm() | ||
|
|
||
| override fun applyAnswerTo(answer: SidewalkSurfaceAnswer, tags: Tags, timestampEdited: Long) { | ||
| val leftChanged = answer.left?.let { sideSurfaceChanged(it, Side.LEFT, tags) } | ||
| val rightChanged = answer.right?.let { sideSurfaceChanged(it, Side.RIGHT, tags) } | ||
|
|
||
| if (leftChanged == true) { | ||
| deleteSmoothnessKeys(Side.LEFT, tags) | ||
| deleteSmoothnessKeys(Side.BOTH, tags) | ||
| } | ||
| if (rightChanged == true) { | ||
| deleteSmoothnessKeys(Side.RIGHT, tags) | ||
| deleteSmoothnessKeys(Side.BOTH, tags) | ||
| } | ||
|
|
||
| if (answer.left == answer.right) { | ||
| answer.left?.let { applySidewalkSurfaceAnswerTo(it, Side.BOTH, tags) } | ||
| deleteSidewalkSurfaceAnswerIfExists(Side.LEFT, tags) | ||
| deleteSidewalkSurfaceAnswerIfExists(Side.RIGHT, tags) | ||
| } else { | ||
| answer.left?.let { applySidewalkSurfaceAnswerTo(it, Side.LEFT, tags) } | ||
| answer.right?.let { applySidewalkSurfaceAnswerTo(it, Side.RIGHT, tags) } | ||
| deleteSidewalkSurfaceAnswerIfExists(Side.BOTH, tags) | ||
| } | ||
| deleteSidewalkSurfaceAnswerIfExists(null, tags) | ||
|
|
||
| // only set the check date if nothing was changed | ||
| if (!tags.hasChanges || tags.hasCheckDateForKey("sidewalk:surface")) { | ||
| tags.updateCheckDateForKey("sidewalk:surface") | ||
| } | ||
arrival-spring marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private enum class Side(val value: String) { | ||
| LEFT("left"), RIGHT("right"), BOTH("both") | ||
| } | ||
|
|
||
| private fun sideSurfaceChanged(surface: SurfaceAnswer, side: Side, tags: Tags): Boolean { | ||
| val previousSideValue = tags["sidewalk:${side.value}:surface"] | ||
| val previousBothOsmValue = tags["sidewalk:both:surface"] | ||
| val osmValue = surface.value.osmValue | ||
|
|
||
| return if (previousSideValue != null && previousSideValue != osmValue) { | ||
| true | ||
| } else previousBothOsmValue != null && previousBothOsmValue != osmValue | ||
westnordost marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private fun applySidewalkSurfaceAnswerTo(surface: SurfaceAnswer, side: Side, tags: Tags) | ||
| { | ||
| val sidewalkKey = "sidewalk:" + side.value | ||
| val sidewalkSurfaceKey = "$sidewalkKey:surface" | ||
|
|
||
| tags[sidewalkSurfaceKey] = surface.value.osmValue | ||
|
|
||
| // add/remove note - used to describe generic surfaces | ||
| if (surface.note != null) { | ||
| tags["$sidewalkSurfaceKey:note"] = surface.note | ||
| } else { | ||
| tags.remove("$sidewalkSurfaceKey:note") | ||
| } | ||
| // clean up old source tags - source should be in changeset tags | ||
| tags.remove("source:$sidewalkSurfaceKey") | ||
| } | ||
|
|
||
| /** clear smoothness tags for the given side*/ | ||
| private fun deleteSmoothnessKeys(side: Side, tags: Tags) { | ||
| val sidewalkKey = "sidewalk:" + side.value | ||
| tags.remove("$sidewalkKey:smoothness") | ||
| tags.remove("$sidewalkKey:smoothness:date") | ||
| tags.removeCheckDatesForKey("$sidewalkKey:smoothness") | ||
| } | ||
|
|
||
| /** clear previous answers for the given side */ | ||
| private fun deleteSidewalkSurfaceAnswerIfExists(side: Side?, tags: Tags) { | ||
| val sideVal = if (side == null) "" else ":" + side.value | ||
| val sidewalkSurfaceKey = "sidewalk$sideVal:surface" | ||
|
|
||
| // only things are cleared that are set by this quest | ||
| // for example cycleway:surface should only be cleared by a cycleway surface quest etc. | ||
| tags.remove(sidewalkSurfaceKey) | ||
| tags.remove("$sidewalkSurfaceKey:note") | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.