Skip to main content

Crate cgrade

Crate cgrade 

Source
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 None whenever 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. decimals must be 0..=3. Returns None for 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). Returns None for unknown systems and out-of-range German grades.
is_pass
Whether a grade passes in its system: value >= pass where higher is better, value <= pass where lower is better. Returns None for unknown systems, non-finite values, and grades outside the full [worst .. best] interval (grades that do not exist); existing but failing grades yield false.
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 yield 6.0. Strict: rejects empty input, multiple or mixed separators, inner whitespace, trailing text and non-finite results. Scale-free (no range check); validity belongs to is_pass and the conversion functions.
scale
Grading scale for a (case-insensitive) ID, or None when unknown.
to_de
Convert a passing foreign grade to the German scale with the modified Bavarian formula (truncated to 1 decimal). Returns None for unknown systems, non-finite values, and grades outside [pass .. best].