Chore: linting

This commit is contained in:
Pieter Vander Vennet 2024-04-13 02:40:21 +02:00
parent 4625ad9a5c
commit 097141f944
307 changed files with 5346 additions and 2147 deletions

View file

@ -30,7 +30,7 @@ class Compare extends Script {
Object.keys(osmParking.properties).concat(Object.keys(veloParking.properties))
)
for (const key of allKeys) {
if(["name","numberOfLevels"].indexOf(key) >= 0){
if (["name", "numberOfLevels"].indexOf(key) >= 0) {
continue // We don't care about these tags
}
if (osmParking.properties[key] === veloParking.properties[key]) {
@ -45,10 +45,12 @@ class Compare extends Script {
diffs.push({
key,
osm: osmParking.properties[key],
velopark: veloParking.properties[key]
velopark: veloParking.properties[key],
})
}
let osmid = osmParking.properties["@id"] ?? osmParking["id"] /*Not in the properties, that is how overpass returns it*/
let osmid =
osmParking.properties["@id"] ??
osmParking["id"] /*Not in the properties, that is how overpass returns it*/
if (!osmid.startsWith("http")) {
osmid = "https://openstreetmap.org/" + osmid
}
@ -57,7 +59,7 @@ class Compare extends Script {
ref: veloId,
osmid,
distance,
diffs
diffs,
}
}
@ -82,13 +84,16 @@ class Compare extends Script {
}
diffs.push(this.compare(veloId, parking, veloparking))
}
console.log("Found ", diffs.length, " items with differences between OSM and the provided data")
console.log(
"Found ",
diffs.length,
" items with differences between OSM and the provided data"
)
const maxDistance = Math.max(...diffs.map(d => d.distance))
const maxDistance = Math.max(...diffs.map((d) => d.distance))
const distanceBins = []
const binSize = 5
for (let i = 0; i < Math.ceil(maxDistance / binSize) ; i++) {
for (let i = 0; i < Math.ceil(maxDistance / binSize); i++) {
distanceBins.push(0)
}
for (const diff of diffs) {

View file

@ -17,13 +17,16 @@ class VeloParkToGeojson extends Script {
}
private static exportGeojsonTo(filename: string, features: Feature[], extension = ".geojson") {
const file = filename + "_" + /*new Date().toISOString() + */extension
fs.writeFileSync(file,
const file = filename + "_" + /*new Date().toISOString() + */ extension
fs.writeFileSync(
file,
JSON.stringify(
extension === ".geojson" ? {
type: "FeatureCollection",
features
} : features,
extension === ".geojson"
? {
type: "FeatureCollection",
features,
}
: features,
null,
" "
)
@ -45,10 +48,12 @@ class VeloParkToGeojson extends Script {
}
addTo[k].add(data[k])
}
}
private static async downloadDataFor(url: string, allProperties: Record<string, Set<string>>): Promise<Feature[]> {
private static async downloadDataFor(
url: string,
allProperties: Record<string, Set<string>>
): Promise<Feature[]> {
const cachePath = "/home/pietervdvn/data/velopark_cache/" + url.replace(/[/:.]/g, "_")
if (!fs.existsSync(cachePath)) {
const data = await Utils.downloadJson(url)
@ -75,7 +80,7 @@ class VeloParkToGeojson extends Script {
console.log("Downloading velopark data")
// Download data for NIS-code 1000. 1000 means: all of belgium
const url = "https://www.velopark.be/api/parkings/1000"
const allVeloparkRaw: { url: string }[] = <{url: string}[]> await Utils.downloadJson(url)
const allVeloparkRaw: { url: string }[] = <{ url: string }[]>await Utils.downloadJson(url)
let failed = 0
console.log("Got", allVeloparkRaw.length, "items")
@ -85,15 +90,22 @@ class VeloParkToGeojson extends Script {
const f = allVeloparkRaw[i]
console.log("Handling", i + "/" + allVeloparkRaw.length)
try {
const sections: Feature[] = await VeloParkToGeojson.downloadDataFor(f.url, allProperties)
const sections: Feature[] = await VeloParkToGeojson.downloadDataFor(
f.url,
allProperties
)
allVelopark.push(...sections)
} catch (e) {
console.error("Loading ", f.url, " failed due to", e)
failed++
}
}
console.log("Fetching data done, got ", allVelopark.length + "/" + allVeloparkRaw.length, "failed:", failed)
console.log(
"Fetching data done, got ",
allVelopark.length + "/" + allVeloparkRaw.length,
"failed:",
failed
)
VeloParkToGeojson.exportGeojsonTo("velopark_all", allVelopark)
for (const k in allProperties) {
allProperties[k] = Array.from(allProperties[k])
@ -104,15 +116,15 @@ class VeloParkToGeojson extends Script {
return allVelopark
}
private static loadFromFile(maxCacheAgeSeconds = 24*60*60): Feature[] | null {
private static loadFromFile(maxCacheAgeSeconds = 24 * 60 * 60): Feature[] | null {
const path = "velopark_all.geojson"
if(!fs.existsSync(path)){
if (!fs.existsSync(path)) {
return null
}
// Millis since epoch
const mtime : number = fs.statSync(path).mtime.getTime()
const mtime: number = fs.statSync(path).mtime.getTime()
const stalenessSeconds = (new Date().getTime() - mtime) / 1000
if(stalenessSeconds > maxCacheAgeSeconds){
if (stalenessSeconds > maxCacheAgeSeconds) {
return null
}
@ -146,7 +158,7 @@ class VeloParkToGeojson extends Script {
private static async createDiff(allVelopark: Feature[]) {
const bboxBelgium = new BBox([
[2.51357303225, 49.5294835476],
[6.15665815596, 51.4750237087]
[6.15665815596, 51.4750237087],
])
const alreadyLinkedQuery = new Overpass(
@ -163,7 +175,9 @@ class VeloParkToGeojson extends Script {
this.exportGeojsonTo("osm_with_velopark_link", <Feature[]>alreadyLinkedFeatures.features)
console.log("OpenStreetMap contains", seenIds.size, "bicycle parkings with a velopark ref")
const features: Feature[] = allVelopark.filter((f) => !seenIds.has(f.properties["ref:velopark"]))
const features: Feature[] = allVelopark.filter(
(f) => !seenIds.has(f.properties["ref:velopark"])
)
VeloParkToGeojson.exportGeojsonTo("velopark_nonsynced", features)
const allProperties = new Set<string>()
@ -178,16 +192,17 @@ class VeloParkToGeojson extends Script {
}
this.exportGeojsonTo("velopark_nonsynced_id_only", features)
}
async main(): Promise<void> {
const allVelopark =VeloParkToGeojson.loadFromFile() ?? await VeloParkToGeojson.downloadData()
const allVelopark =
VeloParkToGeojson.loadFromFile() ?? (await VeloParkToGeojson.downloadData())
console.log("Got", allVelopark.length, " items")
VeloParkToGeojson.exportExtraAmenities(allVelopark)
await VeloParkToGeojson.createDiff(allVelopark)
console.log("Use vite-node script/velopark/compare to compare the results and generate a diff file")
console.log(
"Use vite-node script/velopark/compare to compare the results and generate a diff file"
)
}
}