forked from MapComplete/MapComplete
Refactoring: update conflate script
This commit is contained in:
parent
b37061fddf
commit
239cb8f63d
1 changed files with 12 additions and 7 deletions
|
@ -4,9 +4,11 @@ import {Feature} from "geojson"
|
||||||
import {GeoOperations} from "../Logic/GeoOperations"
|
import {GeoOperations} from "../Logic/GeoOperations"
|
||||||
import {Utils} from "../Utils"
|
import {Utils} from "../Utils"
|
||||||
import {OsmObject} from "../Logic/Osm/OsmObject"
|
import {OsmObject} from "../Logic/Osm/OsmObject"
|
||||||
import {PhoneTextField, UrlTextfieldDef} from "../UI/Input/ValidatedTextField"
|
|
||||||
import {OsmId} from "../Models/OsmFeature"
|
import {OsmId} from "../Models/OsmFeature"
|
||||||
import ScriptUtils from "./ScriptUtils"
|
import ScriptUtils from "./ScriptUtils"
|
||||||
|
import OsmObjectDownloader from "../Logic/Osm/OsmObjectDownloader";
|
||||||
|
import PhoneValidator from "../UI/InputElement/Validators/PhoneValidator";
|
||||||
|
import UrlValidator from "../UI/InputElement/Validators/UrlValidator";
|
||||||
|
|
||||||
interface PossibleMatch {
|
interface PossibleMatch {
|
||||||
/**
|
/**
|
||||||
|
@ -122,7 +124,10 @@ export class Conflate extends Script {
|
||||||
JSON.stringify(resting_properties),
|
JSON.stringify(resting_properties),
|
||||||
])
|
])
|
||||||
|
|
||||||
const osmObj = await OsmObject.DownloadObjectAsync(id)
|
const osmObj = await new OsmObjectDownloader().DownloadObjectAsync(id)
|
||||||
|
if(osmObj === "deleted"){
|
||||||
|
return
|
||||||
|
}
|
||||||
for (const key in resting_properties) {
|
for (const key in resting_properties) {
|
||||||
osmObj.tags[key] = resting_properties[key]
|
osmObj.tags[key] = resting_properties[key]
|
||||||
}
|
}
|
||||||
|
@ -161,7 +166,7 @@ export class Conflate extends Script {
|
||||||
osmName: string,
|
osmName: string,
|
||||||
osmId: OsmId
|
osmId: OsmId
|
||||||
): Promise<{ earliestDateOfImport; latestDateOfImport }> {
|
): Promise<{ earliestDateOfImport; latestDateOfImport }> {
|
||||||
const history = await OsmObject.DownloadHistory(osmId).AsPromise((h) => h.length > 0)
|
const history = await new OsmObjectDownloader().DownloadHistory(osmId).AsPromise((h) => h.length > 0)
|
||||||
let earliest: Date = undefined
|
let earliest: Date = undefined
|
||||||
let latest: Date = undefined
|
let latest: Date = undefined
|
||||||
for (const historyElement of history) {
|
for (const historyElement of history) {
|
||||||
|
@ -277,14 +282,14 @@ export class Conflate extends Script {
|
||||||
if (fs.existsSync(cachePath)) {
|
if (fs.existsSync(cachePath)) {
|
||||||
return JSON.parse(fs.readFileSync(cachePath, {encoding: "utf-8"}))
|
return JSON.parse(fs.readFileSync(cachePath, {encoding: "utf-8"}))
|
||||||
}
|
}
|
||||||
const history = await OsmObject.DownloadHistory(id).AsPromise((l) => l.length > 0)
|
const history = await new OsmObjectDownloader().DownloadHistory(id).AsPromise((l) => l.length > 0)
|
||||||
fs.writeFileSync(cachePath, JSON.stringify(history, null, " "), {encoding: "utf-8"})
|
fs.writeFileSync(cachePath, JSON.stringify(history, null, " "), {encoding: "utf-8"})
|
||||||
return history
|
return history
|
||||||
}
|
}
|
||||||
|
|
||||||
private async normalize(properties: Record<string, string>) {
|
private async normalize(properties: Record<string, string>) {
|
||||||
if (properties["phone"]) {
|
if (properties["phone"]) {
|
||||||
properties["phone"] = new PhoneTextField().reformat(properties["phone"], () => "be")
|
properties["phone"] = new PhoneValidator().reformat(properties["phone"], () => "be")
|
||||||
}
|
}
|
||||||
if (properties["website"]) {
|
if (properties["website"]) {
|
||||||
let website = properties.website.toLowerCase()
|
let website = properties.website.toLowerCase()
|
||||||
|
@ -296,9 +301,9 @@ export class Conflate extends Script {
|
||||||
if (website.startsWith("https://")) {
|
if (website.startsWith("https://")) {
|
||||||
website = "https://" + website
|
website = "https://" + website
|
||||||
}
|
}
|
||||||
const validator = new UrlTextfieldDef()
|
const validator = new UrlValidator()
|
||||||
if (validator.isValid(website)) {
|
if (validator.isValid(website)) {
|
||||||
properties.website = new UrlTextfieldDef().reformat(website)
|
properties.website = validator.reformat(website)
|
||||||
const stillOnline = await this.stillOnline(website)
|
const stillOnline = await this.stillOnline(website)
|
||||||
if (stillOnline === false) {
|
if (stillOnline === false) {
|
||||||
delete properties.website
|
delete properties.website
|
||||||
|
|
Loading…
Add table
Reference in a new issue