mapcomplete/scripts/translationStatistics.ts

49 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-09-08 21:40:48 +02:00
import { Utils } from "../Utils"
import { AllKnownLayouts } from "../Customizations/AllKnownLayouts"
import TranslatorsPanel from "../UI/BigComponents/TranslatorsPanel"
2022-04-01 21:35:10 +02:00
import * as languages from "../assets/generated/used_languages.json"
{
const usedLanguages = languages.languages
2022-09-08 21:40:48 +02:00
2022-04-01 21:35:10 +02:00
// Some statistics
2022-09-08 21:40:48 +02:00
console.log(
Utils.FixedLength("", 12) + " " + usedLanguages.map((l) => Utils.FixedLength(l, 6)).join("")
)
2022-04-01 21:35:10 +02:00
const all = new Map<string, number[]>()
2022-09-08 21:40:48 +02:00
usedLanguages.forEach((ln) => all.set(ln, []))
2022-04-01 21:35:10 +02:00
for (const layoutId of Array.from(AllKnownLayouts.allKnownLayouts.keys())) {
const layout = AllKnownLayouts.allKnownLayouts.get(layoutId)
2022-09-08 21:40:48 +02:00
if (layout.hideFromOverview) {
2022-04-01 21:35:10 +02:00
continue
}
2022-09-08 21:40:48 +02:00
const { completeness, total } = TranslatorsPanel.MissingTranslationsFor(layout)
2022-04-01 21:35:10 +02:00
process.stdout.write(Utils.FixedLength(layout.id, 12) + " ")
for (const language of usedLanguages) {
const compl = completeness.get(language)
all.get(language).push((compl ?? 0) / total)
if (compl === undefined) {
process.stdout.write(" ")
continue
}
2022-09-08 21:40:48 +02:00
const percentage = Math.round((100 * compl) / total)
2022-04-01 21:35:10 +02:00
process.stdout.write(Utils.FixedLength(percentage + "%", 6))
}
process.stdout.write("\n")
}
process.stdout.write(Utils.FixedLength("average", 12) + " ")
for (const language of usedLanguages) {
const ratios = all.get(language)
let sum = 0
2022-09-08 21:40:48 +02:00
ratios.forEach((x) => (sum += x))
2022-04-01 21:35:10 +02:00
const percentage = Math.round(100 * (sum / ratios.length))
process.stdout.write(Utils.FixedLength(percentage + "%", 6))
}
process.stdout.write("\n")
2022-09-08 21:40:48 +02:00
console.log(
Utils.FixedLength("", 12) + " " + usedLanguages.map((l) => Utils.FixedLength(l, 6)).join("")
)
}