chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2024-08-09 16:55:08 +02:00
parent a8fd550b72
commit 6a0b77eb99
180 changed files with 16812 additions and 2509 deletions

View file

@ -29,9 +29,7 @@ class HandleErrors extends Script {
super("Inspects the errors made on a given day. Argument: path to errors")
}
parseLine() {
}
parseLine() {}
async main(args: string[]): Promise<void> {
const osmConnection = new OsmConnection()
@ -44,10 +42,14 @@ class HandleErrors extends Script {
const refusedFiles: Set<string> = new Set<string>()
refusedFiles.add("[]")
const changesObj = new Changes({
dryRun: new ImmutableStore(true),
osmConnection,
}, false, err => console.error(err))
const changesObj = new Changes(
{
dryRun: new ImmutableStore(true),
osmConnection,
},
false,
(err) => console.error(err)
)
const all: ErrorMessage[] = []
for (const line of lines) {
@ -66,11 +68,10 @@ class HandleErrors extends Script {
console.log(
"\t https://osm.org/" + pendingChange.type + "/" + pendingChange.id,
pendingChange.meta.changeType,
pendingChange.doDelete ? "DELETE" : "",
pendingChange.doDelete ? "DELETE" : ""
)
}
all.push(parsed)
} catch (e) {
console.log("Parsing line failed:", e)
}
@ -80,16 +81,15 @@ class HandleErrors extends Script {
const e = parsed.message
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")
@ -110,19 +110,16 @@ class HandleErrors extends Script {
const path =
"error_changeset_" + parsed.index + "_" + e.layout + "_" + e.username + ".osc"
if (
changeset ===
"<osmChange version='0.6' generator='Mapcomplete 0.44.7'></osmChange>"
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",
"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",
parsed.index +
" is identical to previously seen changeset, not writing to file"
)
} else {
writeFileSync(path, changeset, "utf8")
@ -132,21 +129,16 @@ class HandleErrors extends Script {
if (refusedFiles.has(refusedContent)) {
console.log(
"Refused changes for " +
parsed.index +
" is identical to previously seen changeset, not writing to file",
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")
}
}
}
new
HandleErrors()
.run()
new HandleErrors().run()