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

Small changeset bboxes #5474

Merged
merged 6 commits into from
Feb 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ private fun updateTags(
StringMapEntryModify("c", "d", "e"),
StringMapEntryDelete("f", "g"),
))
)
),
false
)

private fun revertUpdateTags(timestamp: Long = 123L, isSynced: Boolean = false) = ElementEdit(
Expand All @@ -260,7 +261,8 @@ private fun revertUpdateTags(timestamp: Long = 123L, isSynced: Boolean = false)
StringMapEntryModify("c", "d", "e"),
StringMapEntryDelete("f", "g"),
))
)
),
false
)

private fun deletePoi(timestamp: Long = 123L, isSynced: Boolean = false) = ElementEdit(
Expand All @@ -270,7 +272,8 @@ private fun deletePoi(timestamp: Long = 123L, isSynced: Boolean = false) = Eleme
"survey",
timestamp,
isSynced,
DeletePoiNodeAction(node)
DeletePoiNodeAction(node),
false
)

private fun revertDeletePoi(timestamp: Long = 123L, isSynced: Boolean = false) = ElementEdit(
Expand All @@ -280,7 +283,8 @@ private fun revertDeletePoi(timestamp: Long = 123L, isSynced: Boolean = false) =
"survey",
timestamp,
isSynced,
RevertDeletePoiNodeAction(node)
RevertDeletePoiNodeAction(node),
false
)

private fun splitWay(timestamp: Long = 123L, isSynced: Boolean = false) = ElementEdit(
Expand All @@ -300,7 +304,8 @@ private fun splitWay(timestamp: Long = 123L, isSynced: Boolean = false) = Elemen
0.5
)
)
)
),
false
)

private fun createNode(timestamp: Long = 123L, isSynced: Boolean = false) = ElementEdit(
Expand All @@ -310,7 +315,8 @@ private fun createNode(timestamp: Long = 123L, isSynced: Boolean = false) = Elem
"survey",
timestamp,
isSynced,
CreateNodeAction(p, mapOf("shop" to "supermarket"))
CreateNodeAction(p, mapOf("shop" to "supermarket")),
false
)

private fun revertCreateNode(timestamp: Long = 123L, isSynced: Boolean = false) = ElementEdit(
Expand All @@ -320,7 +326,8 @@ private fun revertCreateNode(timestamp: Long = 123L, isSynced: Boolean = false)
"survey",
timestamp,
isSynced,
RevertCreateNodeAction(node)
RevertCreateNodeAction(node),
false
)

private val p = LatLon(56.7, 89.10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.westnordost.streetcomplete.data.osm.edits.upload.changesets

import de.westnordost.streetcomplete.data.ApplicationDbTestCase
import de.westnordost.streetcomplete.data.osm.mapdata.LatLon
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -24,7 +25,7 @@ class OpenChangesetsDaoTest : ApplicationDbTestCase() {
}

@Test fun createDelete() {
dao.put(OpenChangeset(Q, SOURCE, 1))
dao.put(OpenChangeset(Q, SOURCE, 1, LatLon(0.0, 0.0)))
assertTrue(dao.delete(Q, SOURCE))
assertNull(dao.get(Q, SOURCE))
}
Expand All @@ -34,26 +35,33 @@ class OpenChangesetsDaoTest : ApplicationDbTestCase() {
}

@Test fun insertChangesetId() {
dao.put(OpenChangeset(Q, SOURCE, 12))
dao.put(OpenChangeset(Q, SOURCE, 12, LatLon(0.0, 0.0)))
val info = dao.get(Q, SOURCE)!!
assertEquals(12, info.changesetId)
assertEquals(Q, info.questType)
assertEquals(SOURCE, info.source)
}

@Test fun replaceChangesetId() {
dao.put(OpenChangeset(Q, SOURCE, 12))
dao.put(OpenChangeset(Q, SOURCE, 6497))
dao.put(OpenChangeset(Q, SOURCE, 12, LatLon(0.0, 0.0)))
dao.put(OpenChangeset(Q, SOURCE, 6497, LatLon(0.0, 0.0)))
assertEquals(6497, dao.get(Q, SOURCE)!!.changesetId)
}

@Test fun replaceLastPosition() {
dao.put(OpenChangeset(Q, SOURCE, 12, LatLon(1.0, 2.0)))
assertEquals(LatLon(1.0, 2.0), dao.get(Q, SOURCE)!!.lastPosition)
dao.put(OpenChangeset(Q, SOURCE, 12, LatLon(23.0, 12.0)))
assertEquals(LatLon(23.0, 12.0), dao.get(Q, SOURCE)!!.lastPosition)
}

@Test fun getNone() {
assertTrue(dao.getAll().isEmpty())
}

@Test fun insertTwo() {
dao.put(OpenChangeset(Q, SOURCE, 1))
dao.put(OpenChangeset(P, SOURCE, 2))
dao.put(OpenChangeset(Q, SOURCE, 1, LatLon(0.0, 0.0)))
dao.put(OpenChangeset(P, SOURCE, 2, LatLon(0.0, 0.0)))
assertEquals(2, dao.getAll().size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import de.westnordost.streetcomplete.quests.oneway_suspects.data.WayTrafficFlowT

/** Creates the database and upgrades it */
object DatabaseInitializer {
const val DB_VERSION = 13
const val DB_VERSION = 14

fun onCreate(db: Database) {
// OSM notes
Expand Down Expand Up @@ -234,6 +234,11 @@ object DatabaseInitializer {

db.exec("DELETE FROM ${DownloadedTilesTable.NAME};")
}
if (oldVersion <= 13 && newVersion > 13) {
db.exec("ALTER TABLE ${ElementEditsTable.NAME} ADD COLUMN ${ElementEditsTable.Columns.IS_NEAR_USER_LOCATION} int DEFAULT 1 NOT NULL")
db.exec("ALTER TABLE ${OpenChangesetsTable.NAME} ADD COLUMN ${OpenChangesetsTable.Columns.LAST_POSITION_LATITUDE} double DEFAULT 0 NOT NULL")
db.exec("ALTER TABLE ${OpenChangesetsTable.NAME} ADD COLUMN ${OpenChangesetsTable.Columns.LAST_POSITION_LONGITUDE} double DEFAULT 0 NOT NULL")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import kotlin.coroutines.resume

/** Checks if geometry was looked at on a survey, either by looking at the GPS position or asking
* the user */
suspend fun checkIsSurvey(
context: Context,
geometry: ElementGeometry,
locations: Sequence<Location>
): Boolean {
if (dontShowAgain || isWithinSurveyDistance(geometry, locations)) {
return true
}
/** Asks user if he was really on-site */
suspend fun confirmIsSurvey(context: Context): Boolean {
if (dontShowAgain) return true
return suspendCancellableCoroutine { cont ->
val dialogBinding = QuestSourceDialogLayoutBinding.inflate(LayoutInflater.from(context))
dialogBinding.checkBoxDontShowAgain.isGone = timesShown < 1
Expand All @@ -49,7 +42,8 @@ suspend fun checkIsSurvey(
}
}

private suspend fun isWithinSurveyDistance(
/** Checks if geometry was looked at on a survey, by looking at the GPS position */
suspend fun checkIsSurvey(
geometry: ElementGeometry,
locations: Sequence<Location>
): Boolean = withContext(Dispatchers.Default) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface AddElementEditsController {
type: ElementEditType,
geometry: ElementGeometry,
source: String,
action: ElementEditAction
action: ElementEditAction,
isNearUserLocation: Boolean
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ data class ElementEdit(
override val isSynced: Boolean,

/** The action to perform */
val action: ElementEditAction
val action: ElementEditAction,

/** Whether the user was near the element that is being edited when this edit was created */
val isNearUserLocation: Boolean
) : Edit {
override val isUndoable: Boolean get() = !isSynced || action is IsActionRevertable
override val key: ElementEditKey get() = ElementEditKey(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ class ElementEditsController(
type: ElementEditType,
geometry: ElementGeometry,
source: String,
action: ElementEditAction
action: ElementEditAction,
isNearUserLocation: Boolean
) {
add(ElementEdit(0, type, geometry, source, nowAsEpochMilliseconds(), false, action))
add(ElementEdit(0, type, geometry, source, nowAsEpochMilliseconds(), false, action, isNearUserLocation))
}

override fun get(id: Long): ElementEdit? =
Expand Down Expand Up @@ -113,7 +114,7 @@ class ElementEditsController(
// need to delete the original edit from history because this should not be undoable anymore
delete(edit)
// ... and add a new revert to the queue
add(ElementEdit(0, edit.type, edit.originalGeometry, edit.source, nowAsEpochMilliseconds(), false, reverted))
add(ElementEdit(0, edit.type, edit.originalGeometry, edit.source, nowAsEpochMilliseconds(), false, reverted, edit.isNearUserLocation))
}
// not uploaded yet
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import de.westnordost.streetcomplete.data.osm.edits.ElementEditsTable.Columns.AC
import de.westnordost.streetcomplete.data.osm.edits.ElementEditsTable.Columns.CREATED_TIMESTAMP
import de.westnordost.streetcomplete.data.osm.edits.ElementEditsTable.Columns.GEOMETRY
import de.westnordost.streetcomplete.data.osm.edits.ElementEditsTable.Columns.ID
import de.westnordost.streetcomplete.data.osm.edits.ElementEditsTable.Columns.IS_NEAR_USER_LOCATION
import de.westnordost.streetcomplete.data.osm.edits.ElementEditsTable.Columns.IS_SYNCED
import de.westnordost.streetcomplete.data.osm.edits.ElementEditsTable.Columns.LATITUDE
import de.westnordost.streetcomplete.data.osm.edits.ElementEditsTable.Columns.LONGITUDE
Expand Down Expand Up @@ -104,7 +105,8 @@ class ElementEditsDao(
LONGITUDE to position.longitude,
CREATED_TIMESTAMP to createdTimestamp,
IS_SYNCED to if (isSynced) 1 else 0,
ACTION to json.encodeToString(action)
ACTION to json.encodeToString(action),
IS_NEAR_USER_LOCATION to if (isNearUserLocation) 1 else 0
)

private fun CursorPosition.toElementEdit() = ElementEdit(
Expand All @@ -115,6 +117,7 @@ class ElementEditsDao(
getString(SOURCE),
getLong(CREATED_TIMESTAMP),
getInt(IS_SYNCED) == 1,
json.decodeFromString(getString(ACTION))
json.decodeFromString(getString(ACTION)),
getInt(IS_NEAR_USER_LOCATION) == 1,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object ElementEditsTable {
const val CREATED_TIMESTAMP = "created"
const val IS_SYNCED = "synced"
const val ACTION = "action"
const val IS_NEAR_USER_LOCATION = "is_near"
}

const val CREATE = """
Expand All @@ -25,7 +26,8 @@ object ElementEditsTable {
${Columns.LONGITUDE} double NOT NULL,
${Columns.CREATED_TIMESTAMP} int NOT NULL,
${Columns.IS_SYNCED} int NOT NULL,
${Columns.ACTION} text
${Columns.ACTION} text,
${Columns.IS_NEAR_USER_LOCATION} int NOT NULL
);
"""
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class ElementEditUploader(
private fun uploadChanges(edit: ElementEdit, mapDataChanges: MapDataChanges, newChangeset: Boolean): MapDataUpdates {
val changesetId =
if (newChangeset) {
changesetManager.createChangeset(edit.type, edit.source)
changesetManager.createChangeset(edit.type, edit.source, edit.position)
} else {
changesetManager.getOrCreateChangeset(edit.type, edit.source)
changesetManager.getOrCreateChangeset(edit.type, edit.source, edit.position, edit.isNearUserLocation)
}
return mapDataApi.uploadChanges(changesetId, mapDataChanges, ApplicationConstants.IGNORED_RELATION_TYPES)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package de.westnordost.streetcomplete.data.osm.edits.upload.changesets

import de.westnordost.streetcomplete.data.osm.mapdata.LatLon

/** A row in the OpenChangeset table */
data class OpenChangeset(val questType: String, val source: String, val changesetId: Long)
data class OpenChangeset(
val questType: String,
val source: String,
val changesetId: Long,
val lastPosition: LatLon,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package de.westnordost.streetcomplete.data.osm.edits.upload.changesets
import de.westnordost.streetcomplete.data.CursorPosition
import de.westnordost.streetcomplete.data.Database
import de.westnordost.streetcomplete.data.osm.edits.upload.changesets.OpenChangesetsTable.Columns.CHANGESET_ID
import de.westnordost.streetcomplete.data.osm.edits.upload.changesets.OpenChangesetsTable.Columns.LAST_POSITION_LATITUDE
import de.westnordost.streetcomplete.data.osm.edits.upload.changesets.OpenChangesetsTable.Columns.LAST_POSITION_LONGITUDE
import de.westnordost.streetcomplete.data.osm.edits.upload.changesets.OpenChangesetsTable.Columns.QUEST_TYPE
import de.westnordost.streetcomplete.data.osm.edits.upload.changesets.OpenChangesetsTable.Columns.SOURCE
import de.westnordost.streetcomplete.data.osm.edits.upload.changesets.OpenChangesetsTable.NAME
import de.westnordost.streetcomplete.data.osm.mapdata.LatLon

/** Keep track of changesets and the date of the last change that has been made to them */
class OpenChangesetsDao(private val db: Database) {
Expand Down Expand Up @@ -33,11 +36,14 @@ class OpenChangesetsDao(private val db: Database) {
private fun OpenChangeset.toPairs() = listOf(
QUEST_TYPE to questType,
SOURCE to source,
CHANGESET_ID to changesetId
CHANGESET_ID to changesetId,
LAST_POSITION_LATITUDE to lastPosition.latitude,
LAST_POSITION_LONGITUDE to lastPosition.longitude
)

private fun CursorPosition.toOpenChangeset() = OpenChangeset(
getString(QUEST_TYPE),
getString(SOURCE),
getLong(CHANGESET_ID)
getLong(CHANGESET_ID),
LatLon(getDouble(LAST_POSITION_LATITUDE), getDouble(LAST_POSITION_LONGITUDE))
)
Loading