Expand description
Deterministic school grades across scales, plus the modified Bavarian formula for foreign-to-German conversion.
The scale bounds per country live as data in tables/grades.json (see
tables/README.md for the schema, the KMK sources, and the validity
rules); tests/vectors/*.json is the executable contract every
language port runs. The Typst module in typst/ derives from the same
table.
Foreign → German follows the official modified Bavarian formula (KMK
Beschluss, “es wird nicht gerundet”):
x = 1 + 3 * (Nmax - Nd) / (Nmax - Nmin), truncated to 1 decimal.
The inverse (from_de) truncates to 2 decimals. convert pivots
through the German scale and is a documented approximation.
Same input always yields the same output: no models, no I/O. No words or labels are produced; tone belongs to applications.
Structs§
- Scale
- A grading scale with its lowercase ID.
Functions§
- available_
scales - Lowercase scale IDs with a table entry, sorted.
- bavarian_
from_ de - Raw inverse Bavarian formula, German → foreign.
- bavarian_
to_ de - Raw modified Bavarian formula, foreign → German.
- convert
- Convert a grade from one system to another by pivoting through the
German scale. This is a documented approximation: the intermediate
1-decimal truncation loses information, so same-system conversion is
not the identity. Returns
Nonewhenever either leg is invalid. - format_
grade - Render a grade with an explicit decimal count, ALWAYS with a dot
decimal separator regardless of locale (Swiss correspondence rule:
"6.0", never"6,0"). Integer-exact like the formula paths: the value is quantized to thousandths (half away from zero), then the requested places round half away from zero on integers, so no port can diverge on binary-float boundaries.decimalsmust be0..=3. ReturnsNonefor non-finite values and out-of-range precision. - from_de
- Convert a German grade in
[1.0, 4.0]to a foreign scale with the inverse Bavarian formula (truncated to 2 decimals). ReturnsNonefor unknown systems and out-of-range German grades. - is_pass
- Whether a grade passes in its system:
value >= passwhere higher is better,value <= passwhere lower is better. ReturnsNonefor unknown systems, non-finite values, and grades outside the full[worst .. best]interval (grades that do not exist); existing but failing grades yieldfalse. - is_
supported - Whether a scale ID is supported (present in the supported set).
- parse_
grade - Parse a grade numeral: ASCII-trimmed digits with a single dot OR comma
decimal separator, so
"6,0"and"6.0"both yield6.0. Strict: rejects empty input, multiple or mixed separators, inner whitespace, trailing text and non-finite results. Scale-free (no range check); validity belongs tois_passand the conversion functions. - scale
- Grading scale for a (case-insensitive) ID, or
Nonewhen unknown. - to_de
- Convert a passing foreign grade to the German scale with the modified
Bavarian formula (truncated to 1 decimal). Returns
Nonefor unknown systems, non-finite values, and grades outside[pass .. best].