Skip to content

Commit

Permalink
Merge pull request #3682 from streetcomplete/opening-hours-signed-res…
Browse files Browse the repository at this point in the history
…urvey

Resurvey for `opening_hours:signed=no` (fixes #3130)
  • Loading branch information
westnordost authored Jan 27, 2022
2 parents 906d58a + 412ee48 commit c134919
Show file tree
Hide file tree
Showing 149 changed files with 619 additions and 348 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.westnordost.streetcomplete.data.osm.osmquests

import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement
import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment
Expand All @@ -10,7 +10,7 @@ open class TestQuestType : OsmElementQuestType<String> {

override fun getTitle(tags: Map<String, String>) = 0
override fun isApplicableTo(element: Element): Boolean? = null
override fun applyAnswerTo(answer: String, tags: StringMapChangesBuilder) {}
override fun applyAnswerTo(answer: String, tags: Tags, timestampEdited: Long) {}
override val icon = 0
override fun createForm(): AbstractQuestAnswerFragment<String> = object : AbstractQuestAnswerFragment<String>() {}
override val changesetComment = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.westnordost.streetcomplete.data.meta

import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import java.time.DateTimeException
import java.time.LocalDate
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -39,7 +39,7 @@ fun String.toCheckDate(): LocalDate? {

/** adds or modifies the given tag. If the updated tag is the same as before, sets the check date
* tag to today instead. */
fun StringMapChangesBuilder.updateWithCheckDate(key: String, value: String) {
fun Tags.updateWithCheckDate(key: String, value: String) {
val previousValue = get(key)
if (previousValue != value) {
set(key, value)
Expand All @@ -55,44 +55,45 @@ fun StringMapChangesBuilder.updateWithCheckDate(key: String, value: String) {

/** Set/update solely the check date to today for the given key, this also removes other less
* preferred check date keys. */
fun StringMapChangesBuilder.updateCheckDateForKey(key: String) {
set("$SURVEY_MARK_KEY:$key", LocalDate.now().toCheckDateString())
// remove old check date keys (except the one we want to set)
getLastCheckDateKeys(key).forEach {
if (it != "$SURVEY_MARK_KEY:$key") remove(it)
}
fun Tags.updateCheckDateForKey(key: String) {
setCheckDateForKey(key, LocalDate.now())
}

fun Tags.setCheckDateForKey(key: String, date: LocalDate) {
removeCheckDatesForKey(key)
set("$SURVEY_MARK_KEY:$key", date.toCheckDateString())
}

/** Return whether a check date is set for the given key */
fun StringMapChangesBuilder.hasCheckDateForKey(key: String): Boolean =
fun Tags.hasCheckDateForKey(key: String): Boolean =
getLastCheckDateKeys(key).any { get(it) != null }

/** Delete any check date keys for the given key */
fun StringMapChangesBuilder.removeCheckDatesForKey(key: String) {
fun Tags.removeCheckDatesForKey(key: String) {
getLastCheckDateKeys(key).forEach { remove(it) }
}

/** Set/update solely the check date for the entire item to today, this also removes other less
* preferred check date keys for the entire item. */
fun StringMapChangesBuilder.updateCheckDate() {
fun Tags.updateCheckDate() {
set(SURVEY_MARK_KEY, LocalDate.now().toCheckDateString())
removeOtherCheckDates()
}

/** Delete solely the other check date for the entire item, don't touch SURVEY_MARK_KEY */
fun StringMapChangesBuilder.removeOtherCheckDates() {
fun Tags.removeOtherCheckDates() {
// remove old check dates (except the one we want to set)
LAST_CHECK_DATE_KEYS.forEach {
if (it != SURVEY_MARK_KEY) remove(it)
}
}

/** Return whether any check dates are set */
fun StringMapChangesBuilder.hasCheckDate(): Boolean =
fun Tags.hasCheckDate(): Boolean =
LAST_CHECK_DATE_KEYS.any { get(it) != null }

/** Delete any check date for the entire item */
fun StringMapChangesBuilder.removeCheckDates() {
fun Tags.removeCheckDates() {
remove(SURVEY_MARK_KEY)
removeOtherCheckDates()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ fun Element.changesApplied(changes: StringMapChanges): Element {
timestampEdited = currentTimeMillis()
)
}

fun StringMapChangesBuilder.deleteIfExistList(keys: List<String>) {
keys.forEach { remove(it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ interface OsmElementQuestType<T> : QuestType<T> {
* any mix-ups that far apart */
val highlightedElementsRadius: Double get() = 30.0

/** applies the data from [answer] to the given element. The element is not directly modified,
* instead, a map of [tags] is built */
fun applyAnswerTo(answer: T, tags: StringMapChangesBuilder)
/** applies the data from [answer] to the element that has last been edited at [timestampEdited].
* The element is not directly modified, instead, a map of [tags] is built */
fun applyAnswerTo(answer: T, tags: Tags, timestampEdited: Long)

@Suppress("UNCHECKED_CAST")
fun applyAnswerToUnsafe(answer: Any, tags: StringMapChangesBuilder) {
applyAnswerTo(answer as T, tags)
fun applyAnswerToUnsafe(answer: Any, tags: Tags, timestampEdited: Long) {
applyAnswerTo(answer as T, tags, timestampEdited)
}
}

typealias Tags = StringMapChangesBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ import kotlin.collections.ArrayList

private fun createOsmQuestChanges(quest: OsmQuest, element: Element, answer: Any) : StringMapChanges {
val changesBuilder = StringMapChangesBuilder(element.tags)
quest.osmElementQuestType.applyAnswerToUnsafe(answer, changesBuilder)
quest.osmElementQuestType.applyAnswerToUnsafe(answer, changesBuilder, element.timestampEdited)
return changesBuilder.create()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import de.westnordost.streetcomplete.quests.fuel_service.AddFuelSelfService
import de.westnordost.streetcomplete.quests.lanes.AddLanes
import de.westnordost.streetcomplete.quests.kerb_height.AddKerbHeight
import de.westnordost.streetcomplete.quests.level.AddLevel
import de.westnordost.streetcomplete.quests.opening_hours_signed.CheckOpeningHoursSigned
import de.westnordost.streetcomplete.quests.orchard_produce.AddOrchardProduce
import de.westnordost.streetcomplete.quests.parking_access.AddBikeParkingAccess
import de.westnordost.streetcomplete.quests.parking_access.AddParkingAccess
Expand Down Expand Up @@ -287,6 +288,7 @@ import javax.inject.Singleton
AddAddressStreet(),

// shops: text input / opening hours input take longer than other quests
CheckOpeningHoursSigned(featureDictionaryFuture),
AddPlaceName(featureDictionaryFuture),
SpecifyShopType(),
CheckShopType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import de.westnordost.osmfeatures.FeatureDictionary
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.quest.NoCountriesExcept
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.ktx.arrayOfNotNull
import de.westnordost.streetcomplete.ktx.toYesNo
Expand Down Expand Up @@ -68,7 +68,7 @@ class AddAcceptsCash(

override fun createForm() = YesNoQuestAnswerFragment()

override fun applyAnswerTo(answer: Boolean, tags: StringMapChangesBuilder) {
override fun applyAnswerTo(answer: Boolean, tags: Tags, timestampEdited: Long) {
tags["payment:cash"] = answer.toYesNo()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.westnordost.streetcomplete.quests.address
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.ElementType
import de.westnordost.streetcomplete.data.osm.mapdata.Relation
Expand Down Expand Up @@ -65,7 +65,7 @@ class AddAddressStreet : OsmElementQuestType<AddressStreetAnswer> {

override fun createForm() = AddAddressStreetForm()

override fun applyAnswerTo(answer: AddressStreetAnswer, tags: StringMapChangesBuilder) {
override fun applyAnswerTo(answer: AddressStreetAnswer, tags: Tags, timestampEdited: Long) {
val key = when(answer) {
is StreetName -> "addr:street"
is PlaceName -> "addr:place"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.westnordost.streetcomplete.quests.address

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.geometry.ElementPolygonsGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.*
import de.westnordost.streetcomplete.data.osm.osmquests.OsmElementQuestType
Expand Down Expand Up @@ -126,7 +126,7 @@ class AddHousenumber : OsmElementQuestType<HousenumberAnswer> {

override fun createForm() = AddHousenumberForm()

override fun applyAnswerTo(answer: HousenumberAnswer, tags: StringMapChangesBuilder) {
override fun applyAnswerTo(answer: HousenumberAnswer, tags: Tags, timestampEdited: Long) {
when(answer) {
is NoHouseNumber -> tags["nohousenumber"] = "yes"
is HouseNumber -> tags["addr:housenumber"] = answer.number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.westnordost.streetcomplete.quests.air_conditioning

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.ktx.arrayOfNotNull
import de.westnordost.streetcomplete.ktx.toYesNo
Expand Down Expand Up @@ -39,7 +39,7 @@ class AddAirConditioning : OsmFilterQuestType<Boolean>() {

override fun createForm() = YesNoQuestAnswerFragment()

override fun applyAnswerTo(answer: Boolean, tags: StringMapChangesBuilder) {
override fun applyAnswerTo(answer: Boolean, tags: Tags, timestampEdited: Long) {
tags["air_conditioning"] = answer.toYesNo()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.westnordost.streetcomplete.quests.atm_operator

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.filter
Expand All @@ -25,7 +25,7 @@ class AddAtmOperator : OsmFilterQuestType<String>() {

override fun createForm() = AddAtmOperatorForm()

override fun applyAnswerTo(answer: String, tags: StringMapChangesBuilder) {
override fun applyAnswerTo(answer: String, tags: Tags, timestampEdited: Long) {
tags["operator"] = answer
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package de.westnordost.streetcomplete.quests.baby_changing_table

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.ktx.toYesNo
import de.westnordost.streetcomplete.quests.YesNoQuestAnswerFragment
Expand Down Expand Up @@ -37,7 +37,7 @@ class AddBabyChangingTable : OsmFilterQuestType<Boolean>() {

override fun createForm() = YesNoQuestAnswerFragment()

override fun applyAnswerTo(answer: Boolean, tags: StringMapChangesBuilder) {
override fun applyAnswerTo(answer: Boolean, tags: Tags, timestampEdited: Long) {
tags["changing_table"] = answer.toYesNo()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.westnordost.streetcomplete.quests.barrier_bicycle_barrier_type

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.BICYCLIST
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.BLIND
Expand All @@ -21,7 +21,7 @@ class AddBicycleBarrierType : OsmFilterQuestType<BicycleBarrierType>() {

override fun createForm() = AddBicycleBarrierTypeForm()

override fun applyAnswerTo(answer: BicycleBarrierType, tags: StringMapChangesBuilder) {
override fun applyAnswerTo(answer: BicycleBarrierType, tags: Tags, timestampEdited: Long) {
tags["cycle_barrier"] = answer.osmValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.westnordost.streetcomplete.quests.barrier_type
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.data.meta.ALL_PATHS
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Node
Expand Down Expand Up @@ -41,5 +41,6 @@ class AddBarrierOnPath: OsmElementQuestType<BarrierType> {

override fun createForm() = AddBarrierTypeForm()

override fun applyAnswerTo(answer: BarrierType, tags: StringMapChangesBuilder) = answer.applyTo(tags)
override fun applyAnswerTo(answer: BarrierType, tags: Tags, timestampEdited: Long) =
answer.applyTo(tags)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.westnordost.streetcomplete.quests.barrier_type
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.data.meta.ALL_ROADS
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Node
Expand Down Expand Up @@ -39,5 +39,6 @@ class AddBarrierOnRoad: OsmElementQuestType<BarrierType> {

override fun createForm() = AddBarrierTypeForm()

override fun applyAnswerTo(answer: BarrierType, tags: StringMapChangesBuilder) = answer.applyTo(tags)
override fun applyAnswerTo(answer: BarrierType, tags: Tags, timestampEdited: Long) =
answer.applyTo(tags)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.westnordost.streetcomplete.quests.barrier_type

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.BICYCLIST
import de.westnordost.streetcomplete.data.user.achievements.QuestTypeAchievement.BLIND
Expand Down Expand Up @@ -34,5 +34,6 @@ class AddBarrierType : OsmFilterQuestType<BarrierType>() {

override fun createForm() = AddBarrierTypeForm()

override fun applyAnswerTo(answer: BarrierType, tags: StringMapChangesBuilder) = answer.applyTo(tags)
override fun applyAnswerTo(answer: BarrierType, tags: Tags, timestampEdited: Long) =
answer.applyTo(tags)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression
import de.westnordost.streetcomplete.data.meta.hasCheckDate
import de.westnordost.streetcomplete.data.meta.updateCheckDate
import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.edits.update_tags.deleteIfExistList
import de.westnordost.streetcomplete.data.osm.osmquests.Tags
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.osmquests.OsmElementQuestType
Expand Down Expand Up @@ -49,7 +48,7 @@ class AddStileType : OsmElementQuestType<StileTypeAnswer> {

override fun createForm() = AddStileTypeForm()

override fun applyAnswerTo(answer: StileTypeAnswer, tags: StringMapChangesBuilder) {
override fun applyAnswerTo(answer: StileTypeAnswer, tags: Tags, timestampEdited: Long) {
when (answer) {
is StileType -> {
val newType = answer.osmValue
Expand All @@ -60,25 +59,17 @@ class AddStileType : OsmElementQuestType<StileTypeAnswer> {
oldType != null && oldType != newType ||
newMaterial != null && oldMaterial != null && oldMaterial != newMaterial

// => properties that refer to the old replaced stile should be removed
if (stileWasRebuilt) {
// => properties that refer to the old replaced stile should be removed
tags.deleteIfExistList(STILE_PROPERTIES - "material")
if(newMaterial != null) {
tags["material"] = newMaterial
} else {
tags.remove("material")
}
} else if (newMaterial != null && oldMaterial == null) {
// not considered as rebuilt, but material info still
// can be added where it was missing
tags["material"] = newMaterial
STILE_PROPERTIES.forEach { tags.remove(it) }
}
if (newType != oldType) {
tags["stile"] = newType
if(newMaterial != null) {
tags["material"] = newMaterial
}
tags["stile"] = newType
}
is ConvertedStile -> {
tags.deleteIfExistList(STILE_PROPERTIES)
STILE_PROPERTIES.forEach { tags.remove(it) }
tags.remove("stile")
tags["barrier"] = answer.newBarrier
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.westnordost.streetcomplete.quests.barrier_type

import de.westnordost.streetcomplete.data.osm.edits.update_tags.StringMapChangesBuilder
import de.westnordost.streetcomplete.data.osm.osmquests.Tags

enum class BarrierType(val osmValue: String) {
PASSAGE("entrance"),
Expand Down Expand Up @@ -28,7 +28,7 @@ enum class BarrierType(val osmValue: String) {
BICYCLE_BARRIER("cycle_barrier")
}

fun BarrierType.applyTo(tags: StringMapChangesBuilder) {
fun BarrierType.applyTo(tags: Tags) {
tags["barrier"] = this.osmValue
when (this) {
BarrierType.STILE_SQUEEZER -> {
Expand Down
Loading

0 comments on commit c134919

Please sign in to comment.