2024-11-25 23:44:26 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import type { Feature } from "geojson"
|
|
|
|
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
|
|
|
import OsmObjectDownloader from "../../Logic/Osm/OsmObjectDownloader"
|
|
|
|
import { OsmObject } from "../../Logic/Osm/OsmObject"
|
|
|
|
import Loading from "../Base/Loading.svelte"
|
|
|
|
import { HistoryUtils } from "./HistoryUtils"
|
2024-12-01 01:39:13 +01:00
|
|
|
import * as shared_questions from "../../assets/generated/layers/questions.json"
|
|
|
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
|
|
|
|
import Tr from "../Base/Tr.svelte"
|
|
|
|
import AccordionSingle from "../Flowbite/AccordionSingle.svelte"
|
2024-12-04 18:48:05 +01:00
|
|
|
import Translations from "../i18n/Translations"
|
2024-11-25 23:44:26 +01:00
|
|
|
|
2024-12-04 18:48:05 +01:00
|
|
|
export let onlyShowUsername: string[]
|
2024-11-25 23:44:26 +01:00
|
|
|
export let features: Feature[]
|
|
|
|
|
2024-12-04 18:48:05 +01:00
|
|
|
let usernames = new Set(onlyShowUsername)
|
|
|
|
|
2024-11-25 23:44:26 +01:00
|
|
|
const downloader = new OsmObjectDownloader()
|
|
|
|
let allHistories: UIEventSource<OsmObject[][]> = UIEventSource.FromPromise(
|
|
|
|
Promise.all(features.map(f => downloader.downloadHistory(f.properties.id)))
|
|
|
|
)
|
2024-12-01 01:39:13 +01:00
|
|
|
let allDiffs: Store<{
|
|
|
|
key: string;
|
|
|
|
value?: string;
|
|
|
|
oldValue?: string
|
2024-12-04 18:48:05 +01:00
|
|
|
}[]> = allHistories.mapD(histories => HistoryUtils.fullHistoryDiff(histories, usernames))
|
2024-12-01 01:39:13 +01:00
|
|
|
|
|
|
|
const trs = shared_questions.tagRenderings.map(tr => new TagRenderingConfig(tr))
|
2024-11-25 23:44:26 +01:00
|
|
|
|
2024-12-01 01:39:13 +01:00
|
|
|
function detectQuestion(key: string): TagRenderingConfig {
|
|
|
|
return trs.find(tr => tr.freeform?.key === key)
|
|
|
|
}
|
|
|
|
|
|
|
|
const mergedCount: Store<{
|
|
|
|
key: string;
|
|
|
|
tr: TagRenderingConfig;
|
|
|
|
count: number;
|
|
|
|
values: { value: string; count: number }[]
|
|
|
|
}[]> = allDiffs.mapD(allDiffs => {
|
2024-11-25 23:44:26 +01:00
|
|
|
const keyCounts = new Map<string, Map<string, number>>()
|
|
|
|
for (const diff of allDiffs) {
|
|
|
|
const k = diff.key
|
2024-12-01 01:39:13 +01:00
|
|
|
if (!keyCounts.has(k)) {
|
2024-11-25 23:44:26 +01:00
|
|
|
keyCounts.set(k, new Map<string, number>())
|
|
|
|
}
|
|
|
|
const valueCounts = keyCounts.get(k)
|
|
|
|
const v = diff.value ?? ""
|
|
|
|
valueCounts.set(v, 1 + (valueCounts.get(v) ?? 0))
|
|
|
|
}
|
|
|
|
|
2024-12-01 01:39:13 +01:00
|
|
|
const perKey: {
|
|
|
|
key: string, tr: TagRenderingConfig, count: number, values:
|
|
|
|
{ value: string, count: number }[]
|
2024-11-25 23:44:26 +01:00
|
|
|
}[] = []
|
|
|
|
keyCounts.forEach((values, key) => {
|
2024-12-01 01:39:13 +01:00
|
|
|
const keyTotal: { value: string, count: number }[] = []
|
2024-11-25 23:44:26 +01:00
|
|
|
values.forEach((count, value) => {
|
2024-12-01 01:39:13 +01:00
|
|
|
keyTotal.push({ value, count })
|
2024-11-25 23:44:26 +01:00
|
|
|
})
|
|
|
|
let countForKey = 0
|
2024-12-01 01:39:13 +01:00
|
|
|
for (const { count } of keyTotal) {
|
2024-11-25 23:44:26 +01:00
|
|
|
countForKey += count
|
|
|
|
}
|
|
|
|
keyTotal.sort((a, b) => b.count - a.count)
|
2024-12-01 01:39:13 +01:00
|
|
|
const tr = detectQuestion(key)
|
|
|
|
perKey.push({ count: countForKey, tr, key, values: keyTotal })
|
2024-11-25 23:44:26 +01:00
|
|
|
})
|
|
|
|
perKey.sort((a, b) => b.count - a.count)
|
|
|
|
|
|
|
|
return perKey
|
|
|
|
})
|
|
|
|
|
2024-12-04 18:48:05 +01:00
|
|
|
const t = Translations.t.inspector
|
2024-12-01 01:39:13 +01:00
|
|
|
|
2024-11-25 23:44:26 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if allHistories === undefined}
|
|
|
|
<Loading />
|
|
|
|
{:else if $allDiffs !== undefined}
|
|
|
|
{#each $mergedCount as diff}
|
2024-12-01 01:39:13 +01:00
|
|
|
<h3>
|
|
|
|
{#if diff.tr}
|
|
|
|
<Tr t={diff.tr.question} />
|
|
|
|
{:else}
|
|
|
|
{diff.key}
|
|
|
|
{/if}
|
|
|
|
</h3>
|
|
|
|
<AccordionSingle>
|
|
|
|
<span slot="header">
|
2024-12-04 18:48:05 +01:00
|
|
|
<Tr t={t.answeredCountTimes.Subs(diff)} />
|
2024-12-01 01:39:13 +01:00
|
|
|
</span>
|
|
|
|
<ul>
|
|
|
|
{#each diff.values as value}
|
|
|
|
<li>
|
|
|
|
<b>{value.value}</b>
|
|
|
|
{#if value.count > 1}
|
|
|
|
- {value.count}
|
|
|
|
{/if}
|
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
</AccordionSingle>
|
2024-11-25 23:44:26 +01:00
|
|
|
{/each}
|
|
|
|
{/if}
|