Themes(benches): improve openBenches import

This commit is contained in:
Pieter Vander Vennet 2025-10-04 02:21:38 +02:00
parent 3ebef308d6
commit cf6a012a07
6 changed files with 197 additions and 20 deletions

View file

@ -1045,6 +1045,49 @@
} }
] ]
}, },
{
"id": "bench-view",
"render": {
"special": {
"type": "group",
"header": "bench-view-title",
"labels": "bench-view-content"
}
}
},
{
"id": "bench-view-title",
"labels": [
"hidden"
],
"render": {
"en": "View from the bench",
"nl": "Zicht vanop de bank"
}
},
{
"id": "bench-view-carousel",
"labels": [
"hidden",
"bench-view-content"
],
"render": {
"special": {
"type": "image_carousel",
"image_key": "image:view;panoramax:view;mapillary:view"
}
},
"render": {
"special": {
"type": "image_upload",
"image_key": "panoramax:view",
"label": {
"en": "Add a picture of the view when sitting on the bench",
"nl": "Voeg een afbeelding van het zicht vanaf de bank toe"
}
}
}
},
{ {
"id": "bench-artwork", "id": "bench-artwork",
"question": { "question": {

View file

@ -278,6 +278,21 @@
"image": "./assets/svg/not_found.svg" "image": "./assets/svg/not_found.svg"
} }
} }
},
{
"id": "mark_not_too_hard",
"labels": [
"controls"
],
"render": {
"special": {
"type": "maproulette_set_status",
"message": {
"en": "This challenge was marked as too hard. Try anyway?"
},
"status": "0"
}
}
} }
], ],
"filter": [ "filter": [

View file

@ -98,8 +98,8 @@
"calculatedTags": [ "calculatedTags": [
"_id:=''+get(feat)('tags')['openbenches:id']", "_id:=''+get(feat)('tags')['openbenches:id']",
"image:=get(feat)('tags')['image']", "image:=get(feat)('tags')['image']",
"_osm_poi_with_this_ref=closestn(feat)('bench',25, undefined, 50).filter(f => f.feat.properties['openbenches:id'] === feat.properties['_id']).map(f => f.feat.properties.id).join(';')", "_osm_poi_with_this_ref=closestn(feat)('bench',5, undefined, 500).filter(f => f.feat.properties['openbenches:id'] === feat.properties['_id']).map(f => f.feat.properties)",
"_nearby_osm_poi=closestn(feat)('bench', 5, undefined, 15)", "_nearby_osm_poi=closestn(feat)('bench', 5, undefined, 50)",
"_nearby_osm_poi:count=get(feat)('_nearby_osm_poi')?.length", "_nearby_osm_poi:count=get(feat)('_nearby_osm_poi')?.length",
"_nearby_osm_poi:props=get(feat)('_nearby_osm_poi')?.map(f => ({_distance: Math.round(f.distance), _mr_id: feat.properties.id, ...f.feat.properties}))" "_nearby_osm_poi:props=get(feat)('_nearby_osm_poi')?.map(f => ({_distance: Math.round(f.distance), _mr_id: feat.properties.id, ...f.feat.properties}))"
], ],
@ -115,6 +115,17 @@
"en": "OpenStreetMap knows about <a href='#{_closest_osm_poi}'>a bench which is {_closest_osm_poi_distance} meter away.</a> " "en": "OpenStreetMap knows about <a href='#{_closest_osm_poi}'>a bench which is {_closest_osm_poi_distance} meter away.</a> "
} }
}, },
{
"id": "already_linked",
"condition": "_osm_poi_with_this_ref!=[]",
"render": {
"special": {
"type": "multi",
"key": "_osm_poi_with_this_ref",
"tagrendering": "The OSM-bench <a href='#{id}'>{id}</a> is linked to this OpenBenches-datapoint"
}
}
},
{ {
"id": "list_nearby_pois", "id": "list_nearby_pois",
"condition": { "condition": {
@ -138,7 +149,17 @@
}, },
{ {
"id": "import_point", "id": "import_point",
"condition": "mr_taskStatus=Created", "condition": {
"or": [
{
"or": [
"mr_taskStatus=Created",
"mr_taskStatus=Open"
]
},
"mr_taskStatus=Open"
]
},
"render": { "render": {
"special": { "special": {
"type": "import_button", "type": "import_button",
@ -153,8 +174,8 @@
} }
} }
}, },
"maproulette.controls", "maproulette.controls",
"{nearby_images()}",
"all_tags" "all_tags"
] ]
} }

View file

@ -1,11 +1,19 @@
import Script from "../Script" import Script from "../Script"
import { promises as fs, writeFileSync } from "fs" import { existsSync, promises as fs, readFileSync, writeFile, writeFileSync } from "fs"
import { Feature, Point } from "geojson" import { Feature, FeatureCollection, Point } from "geojson"
import { join } from "path" import { join } from "path"
import sqlite3, { Database } from "sqlite3" import sqlite3, { Database } from "sqlite3"
import { open } from "sqlite" import { open } from "sqlite"
import ScriptUtils from "../ScriptUtils"
import { Lists } from "../../src/Utils/Lists" import { Lists } from "../../src/Utils/Lists"
import { Overpass } from "../../src/Logic/Osm/Overpass"
import { TagUtils } from "../../src/Logic/Tags/TagUtils"
import Constants from "../../src/Models/Constants"
import { BBox } from "../../src/Logic/BBox"
import LinkImageAction from "../../src/Logic/Osm/Actions/LinkImageAction"
import OsmChangeAction from "../../src/Logic/Osm/Actions/OsmChangeAction"
import ChangeTagAction from "../../src/Logic/Osm/Actions/ChangeTagAction"
import { Tag as OsmTag } from "../../src/Logic/Tags/Tag"
import { Changes } from "../../src/Logic/Osm/Changes"
/** /**
* Note: * Note:
@ -23,6 +31,7 @@ interface Bench {
description: string, description: string,
present: 0 | 1, present: 0 | 1,
published: 0 | 1, published: 0 | 1,
/* time of creation (or possibly last edit?) */
added: string, added: string,
userID: number userID: number
} }
@ -97,8 +106,6 @@ class Openbenches extends Script {
filename: dbFile, filename: dbFile,
driver: sqlite3.Database, driver: sqlite3.Database,
}) })
console.log(db)
console.dir(db)
return <any>db.db return <any>db.db
} }
@ -114,11 +121,11 @@ class Openbenches extends Script {
const mediaView = media.filter(m => m.media_type === "view") const mediaView = media.filter(m => m.media_type === "view")
const properties = { const properties = {
// added: benchWithUser.added, lastModifiedTime: benchWithUser.added,
"openbenches:id": id, "openbenches:id": id,
inscription: benchWithUser.inscription.replaceAll("\\r\\n", "\n"), inscription: benchWithUser.inscription.replaceAll("\\r\\n", "\n"),
amenity: "bench", amenity: "bench",
// lastModifiedBy: benchWithUser.name, lastModifiedBy: benchWithUser.name,
} }
let mediaMerged = Lists.dedup(mediaBench.concat(mediaInscr).map(m => mediaUrl(m))) let mediaMerged = Lists.dedup(mediaBench.concat(mediaInscr).map(m => mediaUrl(m)))
@ -171,7 +178,7 @@ class Openbenches extends Script {
return { return {
type: "Feature", type: "Feature",
properties: { tags: JSON.stringify(properties) }, properties,
geometry: { geometry: {
type: "Point", type: "Point",
coordinates: [benchWithUser.longitude, benchWithUser.latitude], coordinates: [benchWithUser.longitude, benchWithUser.latitude],
@ -179,13 +186,93 @@ class Openbenches extends Script {
} }
} }
async getAlreadyImported(): Promise<FeatureCollection> {
const alreadyImportedPath = "openbenches_linked_in_osm.geojson"
if (!existsSync(alreadyImportedPath)) {
const overpass = new Overpass(Constants.defaultOverpassUrls[0], TagUtils.Tag("openbenches:id~*"))
const dataAndDate = await overpass.queryGeoJson(BBox.global)
const data = dataAndDate[0]
writeFileSync(alreadyImportedPath, JSON.stringify(data), "utf-8")
return data
}
return JSON.parse(readFileSync(alreadyImportedPath, "utf-8"))
}
async conflate(osmData: FeatureCollection, openBenchesData: FeatureCollection) {
const dict: Map<string, Feature> = new Map()
for (const bench of openBenchesData.features) {
const obid = bench.properties["openbenches:id"]
dict.set("" + obid, bench)
}
const changes: OsmChangeAction[] = []
for (const bench of osmData.features) {
const obid = bench.properties["openbenches:id"]
const ob = dict.get(obid)
if (!ob) {
console.log("No match found for", obid, "https://osm.org/" + bench.properties.id)
continue
}
// console.log(`https://osm.org/${bench.properties.id} = https://openbenches.org/bench/${obid}`)
for (const key in ob.properties) {
if (key.startsWith("lastModified")) {
continue
}
if (key.startsWith("image")) {
const imgValue = ob.properties[key]
if (Object.values(bench.properties).some(v => v === imgValue || (v + ".jpg") === imgValue)) {
continue
}
let ikey = "image"
let i = -1
while (bench.properties[ikey]) {
i++
ikey = "image:" + i
}
const li = new ChangeTagAction(bench.properties.id, new OsmTag(ikey, imgValue), bench.properties, {
theme: "openbenches",
changeType: "link-image",
})
changes.push(li)
bench.properties[ikey] = imgValue
console.log(` + ${ikey}=${imgValue}`)
} else if (!bench.properties[key]) {
const v = ob.properties[key]
if(v.length >= 255){
console.log("Text too long:", v.replaceAll("\n"," "))
continue
}
changes.push(new ChangeTagAction(
bench.properties.id,
new OsmTag(key, v),
bench.properties,
{
theme: "openbenches",
changeType: "answer",
},
))
console.log(` - ${key}=${ob.properties[key].replaceAll("\n", " ")}`)
}
}
}
const xml = await Changes.createChangesetXMLForJosm(changes)
writeFileSync("attributes_import.osc",xml, "utf-8")
}
async main(args: string[]): Promise<void> { async main(args: string[]): Promise<void> {
const dbFile = "openbenches.sqlite" const dbFile = "openbenches.sqlite"
let createTest = false let createTest = false
const osmData = await this.getAlreadyImported()
const openBenches = JSON.parse(readFileSync("openbenches_export_josm_.geojson", "utf-8"))
await this.conflate(osmData, openBenches)
// rmSync(dbFile) // rmSync(dbFile)
// await this.buildDatabase("/home/pietervdvn/git/openbenches.org/database", dbFile) /*
if(!existsSync(dbFile)){
console.log("No database file found at "+dbFile+", recreating the database")
await this.buildDatabase("/home/pietervdvn/git/openbenches.org/database", dbFile)
}
this.db = await this.loadDb(dbFile) this.db = await this.loadDb(dbFile)
const tags = new Map<number, string>() const tags = new Map<number, string>()
@ -220,10 +307,19 @@ class Openbenches extends Script {
} }
} }
writeFileSync(`openbenches_export${createTest ? "_test" : ""}.geojson`, JSON.stringify({ writeFileSync(`openbenches_export_josm_${createTest ? "_test" : ""}.geojson`, JSON.stringify({
type: "FeatureCollection", features, type: "FeatureCollection", features,
}, null, " "), "utf-8") }, null, " "), "utf-8")
//console.log(r)
const maproulette = features.map(f => {
f.properties = {tags: JSON.stringify(f.properties)}
})
writeFileSync(`openbenches_export_maproulette_${createTest ? "_test" : ""}.geojson`, JSON.stringify({
type: "FeatureCollection", features: maproulette,
}, null, " "), "utf-8")
*/
} }
} }

View file

@ -8,7 +8,7 @@ export interface MaprouletteTask {
instruction: string instruction: string
} }
export const maprouletteStatus = [ export const maprouletteStatus = [
"Open", "Created",
"Fixed", "Fixed",
"False_positive", "False_positive",
"Skipped", "Skipped",

View file

@ -39,9 +39,11 @@
const maproulette_id = tags.data[maproulette_id_key] ?? tags.data.mr_taskId ?? tags.data.id const maproulette_id = tags.data[maproulette_id_key] ?? tags.data.mr_taskId ?? tags.data.id
try { try {
const statusIndex = Maproulette.codeToIndex(statusToSet) ?? Number(statusToSet) const statusIndex = Maproulette.codeToIndex(statusToSet) ?? Number(statusToSet)
if(statusIndex !== 0){
await Maproulette.singleton.closeTask(Number(maproulette_id), statusIndex, state, { await Maproulette.singleton.closeTask(Number(maproulette_id), statusIndex, state, {
comment: feedback, comment: feedback,
}) })
}
tags.data["mr_taskStatus"] = maprouletteStatus[statusIndex] tags.data["mr_taskStatus"] = maprouletteStatus[statusIndex]
tags.data.status = statusToSet tags.data.status = statusToSet
tags.ping() tags.ping()
@ -59,7 +61,7 @@
<Loading> <Loading>
<Tr t={Translations.t.general.loading} /> <Tr t={Translations.t.general.loading} />
</Loading> </Loading>
{:else if $status === Maproulette.STATUS_OPEN} {:else if $status === Maproulette.STATUS_OPEN || (statusToSet === ""+Maproulette.STATUS_OPEN && $status !== Maproulette.STATUS_OPEN)}
{#if askFeedback !== "" && askFeedback !== undefined} {#if askFeedback !== "" && askFeedback !== undefined}
<div class="interactive flex flex-col gap-y-1 border border-dashed border-gray-500 p-1"> <div class="interactive flex flex-col gap-y-1 border border-dashed border-gray-500 p-1">
<h3>{askFeedback}</h3> <h3>{askFeedback}</h3>