Chore: formatting
This commit is contained in:
parent
35eff07c80
commit
c08fe03ed0
422 changed files with 31594 additions and 43019 deletions
|
@ -65,8 +65,10 @@ class Compare extends Script {
|
|||
|
||||
async main(args: string[]): Promise<void> {
|
||||
let [velopark, osm, key] = args
|
||||
if(velopark === undefined || osm === undefined){
|
||||
console.log("Needed argument: velopark.geojson osm.geojson [key]\nThe key is optional and will be `ref:velopark` by default\nUse overpass to get a geojson with ref:velopark")
|
||||
if (velopark === undefined || osm === undefined) {
|
||||
console.log(
|
||||
"Needed argument: velopark.geojson osm.geojson [key]\nThe key is optional and will be `ref:velopark` by default\nUse overpass to get a geojson with ref:velopark"
|
||||
)
|
||||
return
|
||||
}
|
||||
key ??= "ref:velopark"
|
||||
|
|
|
@ -7,32 +7,42 @@ interface DiffItem {
|
|||
/**
|
||||
* Velopark-id
|
||||
*/
|
||||
"ref": string,
|
||||
"osmid": OsmId,
|
||||
"distance": number,
|
||||
"diffs": {
|
||||
key: string,
|
||||
ref: string
|
||||
osmid: OsmId
|
||||
distance: number
|
||||
diffs: {
|
||||
key: string
|
||||
/**
|
||||
* The value in OpenStreetMap
|
||||
* Might be undefined if OSM doesn't have an appropriate value
|
||||
*/
|
||||
osm?: string,
|
||||
velopark: string | number } []
|
||||
osm?: string
|
||||
velopark: string | number
|
||||
}[]
|
||||
}
|
||||
|
||||
export class DiffToCsv extends Script {
|
||||
constructor() {
|
||||
super("Converts a 'report.diff' to a CSV file for people who prefer LibreOffice Calc (or other Spreadsheet Software)")
|
||||
super(
|
||||
"Converts a 'report.diff' to a CSV file for people who prefer LibreOffice Calc (or other Spreadsheet Software)"
|
||||
)
|
||||
}
|
||||
|
||||
async main(args: string[]): Promise<void> {
|
||||
const file = args[0] ?? "report_diff.json"
|
||||
const json = <{diffs:DiffItem[], distanceBinds: number[]}> JSON.parse(readFileSync(file, "utf8"))
|
||||
const json = <{ diffs: DiffItem[]; distanceBinds: number[] }>(
|
||||
JSON.parse(readFileSync(file, "utf8"))
|
||||
)
|
||||
const diffs = json.diffs
|
||||
const allKeys = Utils.Dedup(diffs.flatMap(item => item.diffs.map(d => d.key)))
|
||||
const allKeys = Utils.Dedup(diffs.flatMap((item) => item.diffs.map((d) => d.key)))
|
||||
allKeys.sort()
|
||||
|
||||
const header = ["osm_id","velopark_id", "distance",...allKeys.flatMap(k => ["osm:"+k, "velopark:"+k])]
|
||||
const header = [
|
||||
"osm_id",
|
||||
"velopark_id",
|
||||
"distance",
|
||||
...allKeys.flatMap((k) => ["osm:" + k, "velopark:" + k]),
|
||||
]
|
||||
const lines = [header]
|
||||
for (const diffItem of diffs) {
|
||||
const line = []
|
||||
|
@ -43,19 +53,16 @@ export class DiffToCsv extends Script {
|
|||
|
||||
const d = diffItem.diffs
|
||||
for (const k of allKeys) {
|
||||
const found = d.find(i => i.key === k)
|
||||
if(!found){
|
||||
line.push("","")
|
||||
const found = d.find((i) => i.key === k)
|
||||
if (!found) {
|
||||
line.push("", "")
|
||||
continue
|
||||
}
|
||||
line.push(found.osm, found.velopark)
|
||||
}
|
||||
|
||||
}
|
||||
const path = "report_diff.csv"
|
||||
writeFileSync(path,
|
||||
lines.map(l => l.join(",")).join("\n")
|
||||
,"utf8")
|
||||
writeFileSync(path, lines.map((l) => l.join(",")).join("\n"), "utf8")
|
||||
console.log("Written", path)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ class VeloParkToGeojson extends Script {
|
|||
JSON.stringify(
|
||||
extension === ".geojson"
|
||||
? {
|
||||
type: "FeatureCollection",
|
||||
features
|
||||
}
|
||||
type: "FeatureCollection",
|
||||
features,
|
||||
}
|
||||
: features,
|
||||
null,
|
||||
" "
|
||||
|
@ -34,10 +34,9 @@ class VeloParkToGeojson extends Script {
|
|||
console.log("Written", file, "(" + features.length, " features)")
|
||||
}
|
||||
|
||||
private static async downloadDataFor(
|
||||
url: string
|
||||
): Promise<Feature[]> {
|
||||
const cachePath = "/home/pietervdvn/data/velopark_cache_refined/" + url.replace(/[/:.]/g, "_")
|
||||
private static async downloadDataFor(url: string): Promise<Feature[]> {
|
||||
const cachePath =
|
||||
"/home/pietervdvn/data/velopark_cache_refined/" + url.replace(/[/:.]/g, "_")
|
||||
if (fs.existsSync(cachePath)) {
|
||||
return JSON.parse(fs.readFileSync(cachePath, "utf8"))
|
||||
}
|
||||
|
@ -50,7 +49,7 @@ class VeloParkToGeojson extends Script {
|
|||
if (Object.keys(sectionInfo).length === 0) {
|
||||
console.warn("No result for", url)
|
||||
}
|
||||
if(!sectionInfo.geometry?.coordinates){
|
||||
if (!sectionInfo.geometry?.coordinates) {
|
||||
throw "Invalid properties!"
|
||||
}
|
||||
allVelopark.push(sectionInfo)
|
||||
|
@ -70,8 +69,8 @@ class VeloParkToGeojson extends Script {
|
|||
const allVelopark: Feature[] = []
|
||||
const batchSize = 50
|
||||
for (let i = 0; i < allVeloparkRaw.length; i += batchSize) {
|
||||
await Promise.all(Utils.TimesT(batchSize, j => j).map(
|
||||
async j => {
|
||||
await Promise.all(
|
||||
Utils.TimesT(batchSize, (j) => j).map(async (j) => {
|
||||
const f = allVeloparkRaw[i + j]
|
||||
if (!f) {
|
||||
return
|
||||
|
@ -83,9 +82,8 @@ class VeloParkToGeojson extends Script {
|
|||
console.error("Loading ", f.url, " failed due to", e)
|
||||
failed++
|
||||
}
|
||||
}
|
||||
))
|
||||
|
||||
})
|
||||
)
|
||||
}
|
||||
console.log(
|
||||
"Fetching data done, got ",
|
||||
|
@ -140,7 +138,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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue