mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-08 02:52:49 +00:00
24 lines
616 B
TypeScript
24 lines
616 B
TypeScript
import type {Chord} from "$lib/serial/chord"
|
|
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
|
|
|
interface Language {
|
|
name: string
|
|
noLazyMode?: boolean
|
|
orderedByFrequency?: boolean
|
|
words: string[]
|
|
}
|
|
|
|
export async function calculateChordCoverage(chords: Chord[]) {
|
|
const language: Language = await fetch("/languages/english.json").then(it => it.json())
|
|
|
|
const words = new Set(language.words)
|
|
for (const chord of chords) {
|
|
words.delete(chord.phrase.map(it => KEYMAP_CODES[it].id!).join(""))
|
|
}
|
|
|
|
return {
|
|
coverage: words.size / language.words.length,
|
|
missing: [...words.values()],
|
|
}
|
|
}
|