forked from MapComplete/MapComplete
		
	Chore: formatting
This commit is contained in:
		
							parent
							
								
									35eff07c80
								
							
						
					
					
						commit
						c08fe03ed0
					
				
					 422 changed files with 31594 additions and 43019 deletions
				
			
		|  | @ -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) | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue