forked from MapComplete/MapComplete
		
	Fix loading of day-statistic files
This commit is contained in:
		
							parent
							
								
									5e291cda24
								
							
						
					
					
						commit
						640ff8e382
					
				
					 1 changed files with 56 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -13,9 +13,10 @@ import MapState from "../Logic/State/MapState"
 | 
			
		|||
import BaseUIElement from "./BaseUIElement"
 | 
			
		||||
import Title from "./Base/Title"
 | 
			
		||||
import { FixedUiElement } from "./Base/FixedUiElement"
 | 
			
		||||
import UserDetails from "../Logic/Osm/OsmConnection";
 | 
			
		||||
import List from "./Base/List";
 | 
			
		||||
 | 
			
		||||
class StatisticsForOverviewFile extends Combine {
 | 
			
		||||
 | 
			
		||||
    constructor(homeUrl: string, paths: string[]) {
 | 
			
		||||
        paths = paths.filter(p => !p.endsWith("file-overview.json"))
 | 
			
		||||
        const layer = AllKnownLayouts.allKnownLayouts.get("mapcomplete-changes").layers[0]
 | 
			
		||||
| 
						 | 
				
			
			@ -54,6 +55,7 @@ class StatisticsForOverviewFile extends Combine {
 | 
			
		|||
            )
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        super([
 | 
			
		||||
            filterPanel,
 | 
			
		||||
            new VariableUiElement(
 | 
			
		||||
| 
						 | 
				
			
			@ -94,7 +96,36 @@ class StatisticsForOverviewFile extends Combine {
 | 
			
		|||
                        const trs = layer.tagRenderings.filter(
 | 
			
		||||
                            (tr) => tr.mappings?.length > 0 || tr.freeform?.key !== undefined
 | 
			
		||||
                        )
 | 
			
		||||
                        const elements: BaseUIElement[] = []
 | 
			
		||||
 | 
			
		||||
                        const allKeys = new Set<string>()
 | 
			
		||||
                        for (const cs of overview._meta) {
 | 
			
		||||
                            for (const propertiesKey in cs.properties) {
 | 
			
		||||
                                allKeys.add(propertiesKey)
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        console.log("All keys:", allKeys)
 | 
			
		||||
 | 
			
		||||
                        const valuesToSum = [
 | 
			
		||||
                            "answer",
 | 
			
		||||
                            "move",
 | 
			
		||||
                            "deletion",
 | 
			
		||||
                            "add-image",
 | 
			
		||||
                            "plantnet-ai-detection",
 | 
			
		||||
                            "import",
 | 
			
		||||
                            "conflation",
 | 
			
		||||
                            "link-image",
 | 
			
		||||
                            "soft-delete"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                        const elements: BaseUIElement[] = [
 | 
			
		||||
                            new Title("General statistics"),
 | 
			
		||||
                            new Combine([
 | 
			
		||||
                                overview._meta.length + " changesets match the filters",
 | 
			
		||||
                                new List(valuesToSum.map(key => key + ": " + overview.sum(key)))
 | 
			
		||||
                            ]).SetClass("flex flex-col border rounded-xl"),
 | 
			
		||||
 | 
			
		||||
                            new Title("Breakdown")
 | 
			
		||||
                        ]
 | 
			
		||||
                        for (const tr of trs) {
 | 
			
		||||
                            let total = undefined
 | 
			
		||||
                            if (tr.freeform?.key !== undefined) {
 | 
			
		||||
| 
						 | 
				
			
			@ -197,6 +228,17 @@ class ChangesetsOverview {
 | 
			
		|||
        return new ChangesetsOverview(this._meta.filter(predicate))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public sum(key: string): number {
 | 
			
		||||
        let s = 0
 | 
			
		||||
        for (const feature of this._meta) {
 | 
			
		||||
            const parsed = Number(feature[key])
 | 
			
		||||
            if (!isNaN(parsed)) {
 | 
			
		||||
                s += parsed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return s
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static cleanChangesetData(cs: ChangeSetData): ChangeSetData {
 | 
			
		||||
        if (cs === undefined) {
 | 
			
		||||
            return undefined
 | 
			
		||||
| 
						 | 
				
			
			@ -222,7 +264,8 @@ class ChangesetsOverview {
 | 
			
		|||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            cs.properties.host = new URL(cs.properties.host).host
 | 
			
		||||
        } catch (e) {}
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
        }
 | 
			
		||||
        return cs
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue