forked from MapComplete/MapComplete
		
	Scripts: create script to inspect custom layers
This commit is contained in:
		
							parent
							
								
									449f674e0f
								
							
						
					
					
						commit
						ff9f6f719e
					
				
					 1 changed files with 78 additions and 0 deletions
				
			
		
							
								
								
									
										78
									
								
								scripts/inspectStudioLayers.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										78
									
								
								scripts/inspectStudioLayers.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,78 @@ | |||
| import Script from "./Script" | ||||
| import ScriptUtils from "./ScriptUtils" | ||||
| import { LayerConfigJson } from "../src/Models/ThemeConfig/Json/LayerConfigJson" | ||||
| import { readFileSync, statSync } from "fs" | ||||
| import LayerConfig from "../src/Models/ThemeConfig/LayerConfig" | ||||
| import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer" | ||||
| import { TagUtils } from "../src/Logic/Tags/TagUtils" | ||||
| 
 | ||||
| class CompareLayer { | ||||
|     private _knownLayers: Map<string, LayerConfigJson> | ||||
| 
 | ||||
|     constructor(knownLayers: Map<string, LayerConfigJson>) { | ||||
|         this._knownLayers = knownLayers | ||||
|     } | ||||
| 
 | ||||
|     public compare(layer: LayerConfigJson, path: string) { | ||||
|         const candidate = this._knownLayers.get(layer.id) | ||||
|         if (!layer.source?.["osmTags"]) { | ||||
|             return | ||||
|         } | ||||
|         layer.tagRenderings = layer.tagRenderings?.filter(tr => tr !== "images") ?? [] | ||||
|         if(layer.tagRenderings.length === 0){ | ||||
|             return | ||||
|         } | ||||
|         if (!candidate) { | ||||
|             console.log("## " + layer.id + " (unique)") | ||||
|             const info = statSync(path) | ||||
|             console.log(`\n[${layer.id}](${path}) Last edited ${info.mtime.toISOString()}\n\n`) | ||||
|             const source = TagUtils.Tag(layer.source?.["osmTags"]) | ||||
|             console.log(source.asHumanString(true, false)) | ||||
|             if (layer.tagRenderings.length === 0) { | ||||
|                 console.log("MINIMAL") | ||||
|             } | ||||
|             console.log("> "+layer.description?.["en"]) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| class InspectStudioLayers extends Script { | ||||
| 
 | ||||
|     constructor() { | ||||
|         super("Iterates over all the studio layers and tries to match it with an already existing layer and list differences") | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     async main(args: string[]): Promise<void> { | ||||
|         const path = args[0] ?? "/home/pietervdvn/data/mapcomplete-custom-themes" | ||||
|         const files = ScriptUtils.readDirRecSync(path) | ||||
|             .filter(p => p.endsWith(".json")) | ||||
|             .filter(p => p.indexOf("/themes/") < 0) | ||||
|             .filter(p => !p.endsWith("license_info.json") && p.indexOf(".stversions") < 0) | ||||
|         const officialFiles = new Map<string, LayerConfigJson>() | ||||
|         const unofficial: { layer: LayerConfigJson, path: string }[] = [] | ||||
|         for (const file of files) { | ||||
|             const rest = file.substring(path.length + 1) | ||||
|             console.log("Loading ", rest) | ||||
|             try { | ||||
|                 const config = <LayerConfigJson>JSON.parse(readFileSync(file, "utf-8")) | ||||
|                 if (rest.indexOf("layers") < 3) { | ||||
|                     officialFiles.set(config.id, config) | ||||
|                 } else { | ||||
|                     unofficial.push({ layer: config, path: file }) | ||||
|                 } | ||||
|             } catch (e) { | ||||
|                 console.error("COULD NOT READ/PARSE", file, "ignoring it") | ||||
|             } | ||||
|         } | ||||
|         console.log("Loaded", unofficial.length, "custom layers and ", officialFiles.size, "official layers") | ||||
|         const comp = new CompareLayer(officialFiles) | ||||
|         for (const layerConfigJson of unofficial) { | ||||
|             comp.compare(layerConfigJson.layer, layerConfigJson.path) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| new InspectStudioLayers().run() | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue