MUSA Graderv0.1.0

API reference · grader/utils.py · 116 lines

grader.utils

Small shared helpers for the grading engine.

Summary

NameKindDescription
utc_now_iso()function
slugify()functionFilesystem-safe identifier.
json_default()functionBest-effort JSON encoder for numpy / pandas / arbitrary objects.
dump_json()function
load_json()function
is_close()function
as_float()function
normalize_zips()functionCoerce mixed zip representations (int, float, str, padded) to 5-char strings.
jaccard()function
truncate()function
pluralize()function

Constants

NameValueNotes
ZIP_REre.compile('^\\d{5}$')

Functions

utc_now_iso() -> str #[source]

No description.

slugify(value: str) -> str #[source]

Filesystem-safe identifier.

json_default(obj: Any) -> Any #[source]

Best-effort JSON encoder for numpy / pandas / arbitrary objects.

dump_json(path: Path, payload: Any, indent: int = 2) -> None #[source]

No description.

load_json(path: Path) -> Any #[source]

No description.

is_close(actual: Any, expected: Any, rel_tol: float = 0.0001, abs_tol: float = 0.0001) -> bool #[source]

No description.

as_float(value: Any) -> float | None #[source]

No description.

normalize_zips(values: Iterable[Any]) -> set[str] #[source]

Coerce mixed zip representations (int, float, str, padded) to 5-char strings.

jaccard(a: set, b: set) -> float #[source]

No description.

truncate(text: str, limit: int = 4000) -> str #[source]

No description.

pluralize(count: int, singular: str, plural: str | None = None) -> str #[source]

No description.