forked from MapComplete/MapComplete
		
	Scripts: script to inspect custom layers: add estimates
This commit is contained in:
		
							parent
							
								
									ff9f6f719e
								
							
						
					
					
						commit
						8aa06a4e5e
					
				
					 1 changed files with 12 additions and 4 deletions
				
			
		| 
						 | 
					@ -5,15 +5,16 @@ import { readFileSync, statSync } from "fs"
 | 
				
			||||||
import LayerConfig from "../src/Models/ThemeConfig/LayerConfig"
 | 
					import LayerConfig from "../src/Models/ThemeConfig/LayerConfig"
 | 
				
			||||||
import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer"
 | 
					import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer"
 | 
				
			||||||
import { TagUtils } from "../src/Logic/Tags/TagUtils"
 | 
					import { TagUtils } from "../src/Logic/Tags/TagUtils"
 | 
				
			||||||
 | 
					import TagInfo from "../src/Logic/Web/TagInfo"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CompareLayer {
 | 
					class CompareLayer {
 | 
				
			||||||
    private _knownLayers: Map<string, LayerConfigJson>
 | 
					    private _knownLayers: Map<string, LayerConfigJson>
 | 
				
			||||||
 | 
					    private static readonly tagInfo = new TagInfo()
 | 
				
			||||||
    constructor(knownLayers: Map<string, LayerConfigJson>) {
 | 
					    constructor(knownLayers: Map<string, LayerConfigJson>) {
 | 
				
			||||||
        this._knownLayers = knownLayers
 | 
					        this._knownLayers = knownLayers
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public compare(layer: LayerConfigJson, path: string) {
 | 
					    public async compare(layer: LayerConfigJson, path: string) {
 | 
				
			||||||
        const candidate = this._knownLayers.get(layer.id)
 | 
					        const candidate = this._knownLayers.get(layer.id)
 | 
				
			||||||
        if (!layer.source?.["osmTags"]) {
 | 
					        if (!layer.source?.["osmTags"]) {
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
| 
						 | 
					@ -27,7 +28,13 @@ class CompareLayer {
 | 
				
			||||||
            const info = statSync(path)
 | 
					            const info = statSync(path)
 | 
				
			||||||
            console.log(`\n[${layer.id}](${path}) Last edited ${info.mtime.toISOString()}\n\n`)
 | 
					            console.log(`\n[${layer.id}](${path}) Last edited ${info.mtime.toISOString()}\n\n`)
 | 
				
			||||||
            const source = TagUtils.Tag(layer.source?.["osmTags"])
 | 
					            const source = TagUtils.Tag(layer.source?.["osmTags"])
 | 
				
			||||||
            console.log(source.asHumanString(true, false))
 | 
					            let estimate = undefined
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                estimate = await CompareLayer.tagInfo.getCountEstimateFor(source)
 | 
				
			||||||
 | 
					            } catch (e) {
 | 
				
			||||||
 | 
					                console.log("Error trying to get an estimate", e)
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            console.log(source.asHumanString(true, false) + " (estimated " + estimate + " items)")
 | 
				
			||||||
            if (layer.tagRenderings.length === 0) {
 | 
					            if (layer.tagRenderings.length === 0) {
 | 
				
			||||||
                console.log("MINIMAL")
 | 
					                console.log("MINIMAL")
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -46,6 +53,7 @@ class InspectStudioLayers extends Script {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async main(args: string[]): Promise<void> {
 | 
					    async main(args: string[]): Promise<void> {
 | 
				
			||||||
        const path = args[0] ?? "/home/pietervdvn/data/mapcomplete-custom-themes"
 | 
					        const path = args[0] ?? "/home/pietervdvn/data/mapcomplete-custom-themes"
 | 
				
			||||||
 | 
					        ScriptUtils.erasableLog = () => {}
 | 
				
			||||||
        const files = ScriptUtils.readDirRecSync(path)
 | 
					        const files = ScriptUtils.readDirRecSync(path)
 | 
				
			||||||
            .filter(p => p.endsWith(".json"))
 | 
					            .filter(p => p.endsWith(".json"))
 | 
				
			||||||
            .filter(p => p.indexOf("/themes/") < 0)
 | 
					            .filter(p => p.indexOf("/themes/") < 0)
 | 
				
			||||||
| 
						 | 
					@ -69,7 +77,7 @@ class InspectStudioLayers extends Script {
 | 
				
			||||||
        console.log("Loaded", unofficial.length, "custom layers and ", officialFiles.size, "official layers")
 | 
					        console.log("Loaded", unofficial.length, "custom layers and ", officialFiles.size, "official layers")
 | 
				
			||||||
        const comp = new CompareLayer(officialFiles)
 | 
					        const comp = new CompareLayer(officialFiles)
 | 
				
			||||||
        for (const layerConfigJson of unofficial) {
 | 
					        for (const layerConfigJson of unofficial) {
 | 
				
			||||||
            comp.compare(layerConfigJson.layer, layerConfigJson.path)
 | 
					            await comp.compare(layerConfigJson.layer, layerConfigJson.path)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue