forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
14b2799f08
commit
4add2d1aff
151 changed files with 4561 additions and 3315 deletions
|
@ -9,7 +9,6 @@ import { ImmutableStore } from "../src/Logic/UIEventSource"
|
|||
import { Utils } from "../src/Utils"
|
||||
|
||||
class HandleErrors extends Script {
|
||||
|
||||
constructor() {
|
||||
super("Inspects the errors made on a given day. Argument: path to errors")
|
||||
}
|
||||
|
@ -29,9 +28,10 @@ class HandleErrors extends Script {
|
|||
continue
|
||||
}
|
||||
try {
|
||||
|
||||
const parsed: {
|
||||
ip: string, index: number, date: string,
|
||||
ip: string
|
||||
index: number
|
||||
date: string
|
||||
message: {
|
||||
stacktrace: string
|
||||
message: string
|
||||
|
@ -50,18 +50,25 @@ class HandleErrors extends Script {
|
|||
}
|
||||
console.log(e.username, e.layout, e.message, parsed.date)
|
||||
for (const pendingChange of e.pendingChanges) {
|
||||
console.log("\t https://osm.org/" + pendingChange.type + "/" + pendingChange.id, pendingChange.meta.changeType, pendingChange.doDelete ? "DELETE" : "")
|
||||
console.log(
|
||||
"\t https://osm.org/" + pendingChange.type + "/" + pendingChange.id,
|
||||
pendingChange.meta.changeType,
|
||||
pendingChange.doDelete ? "DELETE" : ""
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
const neededIds = Changes.GetNeededIds(e.pendingChanges)
|
||||
// We _do not_ pass in the Changes object itself - we want the data from OSM directly in order to apply the changes
|
||||
const osmObjects: { id: string, osmObj: OsmObject | "deleted" }[] = await Promise.all<{
|
||||
id: string;
|
||||
osmObj: OsmObject | "deleted"
|
||||
}>(
|
||||
neededIds.map(async id => ({ id, osmObj: await downloader.DownloadObjectAsync(id) }))
|
||||
)
|
||||
const osmObjects: { id: string; osmObj: OsmObject | "deleted" }[] =
|
||||
await Promise.all<{
|
||||
id: string
|
||||
osmObj: OsmObject | "deleted"
|
||||
}>(
|
||||
neededIds.map(async (id) => ({
|
||||
id,
|
||||
osmObj: await downloader.DownloadObjectAsync(id),
|
||||
}))
|
||||
)
|
||||
|
||||
const objects = osmObjects
|
||||
.filter((obj) => obj.osmObj !== "deleted")
|
||||
|
@ -69,40 +76,53 @@ class HandleErrors extends Script {
|
|||
|
||||
const { toUpload, refused } = Changes.fragmentChanges(e.pendingChanges, objects)
|
||||
|
||||
|
||||
const changes: {
|
||||
newObjects: OsmObject[]
|
||||
modifiedObjects: OsmObject[]
|
||||
deletedObjects: OsmObject[]
|
||||
} = new Changes({
|
||||
dryRun: new ImmutableStore(true),
|
||||
osmConnection
|
||||
osmConnection,
|
||||
}).CreateChangesetObjects(toUpload, objects)
|
||||
|
||||
const changeset = Changes.createChangesetFor("", changes)
|
||||
const path = "error_changeset_" + parsed.index + "_" + e.layout + "_" + e.username + ".osc"
|
||||
if(changeset === "<osmChange version='0.6' generator='Mapcomplete 0.44.7'></osmChange>"){
|
||||
console.log("Changes for "+parsed.index+": empty changeset, not creating a file for it")
|
||||
}else if (createdChangesets.has(changeset)) {
|
||||
console.log("Changeset " + parsed.index + " is identical to previously seen changeset, not writing to file")
|
||||
const path =
|
||||
"error_changeset_" + parsed.index + "_" + e.layout + "_" + e.username + ".osc"
|
||||
if (
|
||||
changeset ===
|
||||
"<osmChange version='0.6' generator='Mapcomplete 0.44.7'></osmChange>"
|
||||
) {
|
||||
console.log(
|
||||
"Changes for " +
|
||||
parsed.index +
|
||||
": empty changeset, not creating a file for it"
|
||||
)
|
||||
} else if (createdChangesets.has(changeset)) {
|
||||
console.log(
|
||||
"Changeset " +
|
||||
parsed.index +
|
||||
" is identical to previously seen changeset, not writing to file"
|
||||
)
|
||||
} else {
|
||||
writeFileSync(path, changeset, "utf8")
|
||||
createdChangesets.add(changeset)
|
||||
}
|
||||
const refusedContent = JSON.stringify(refused)
|
||||
if (refusedFiles.has(refusedContent)) {
|
||||
console.log("Refused changes for " + parsed.index + " is identical to previously seen changeset, not writing to file")
|
||||
console.log(
|
||||
"Refused changes for " +
|
||||
parsed.index +
|
||||
" is identical to previously seen changeset, not writing to file"
|
||||
)
|
||||
} else {
|
||||
writeFileSync(path + ".refused.json", refusedContent, "utf8")
|
||||
refusedFiles.add(refusedContent)
|
||||
}
|
||||
console.log("Written", path, "with " + e.pendingChanges.length + " changes")
|
||||
|
||||
} catch (e) {
|
||||
console.log("Parsing line failed:", e)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue