retest-audit

    Offline MoonBit library and CLI for auditing transcription of repeated quality-control measurements against a reviewed reference.

    Download zip
    Version
    0.1.0
    License
    MIT
    Last updated
    4 hours ago
    Downloads
    2

    No dependencies

    #复测对账

    用 MoonBit 核对质检复测记录的转录答卷。准备原文和人工核准表,工具按零件、检验员和复测编号对账,指出错配及原文位置。这里的原文、核准表和答卷都是合成样例。

    项目的原创代码、文档和自创合成样例均采用 MIT 许可证。

    从源码或解包后的模块根目录运行。下列命令使用 Bash、MoonBit 1.0.0-rc1+3c0520448 和 Node.js 24.21.0,可离线执行。

    #已有一份转录,核对差异

    moon run --frozen --target js cmd/audit -- fixtures/main.txt fixtures/main-reference.tsv fixtures/swapped.tsv

    八个读数都出现在答卷中,其中四条归到了错误的检验员。报告指向原文第 6–9 行,交互均方从核准表的 8 变为答卷的 32 mm²。完成对账的状态为 0,差异写在报告中。预期输出

    #准备比较两版提示词

    先冻结试验、核准表和两版提示词,再导出各自的原文、提示和答卷契约。以下例子用一个独立试验模拟三次检查,依次为缺答、收到一份有效答卷和一份无效答卷、补全两份。导出和评分全程离线。

    f=fixtures/blind run=$(mktemp -d) mkdir "$run/empty" cp "$f"/{splits.tsv,quick-set.tsv,plan.tsv,source.txt,reference.tsv,prompt-a.txt,prompt-b.txt} "$run/empty/" moon run --frozen --target js cmd/audit -- --freeze-blind-set "$run/empty/splits.tsv" "$run/empty/quick-set.tsv" --require-empty-slots > "$run/freeze.json" for variant in a b; do moon run --frozen --target js cmd/audit -- --export-blind-request "$run/empty/splits.tsv" "$run/empty/quick-set.tsv" "$run/freeze.json" trial-005 "$variant" > "$run/request-$variant.json" done review() { local stage=$1 expected=$2 status=0 moon run --frozen --target js cmd/audit -- --score-blind-set "$run/$stage/splits.tsv" "$run/$stage/quick-set.tsv" "$run/freeze.json" > "$run/$stage.report.json" || status=$? test "$status" -eq "$expected" } review empty 2 cp -R "$run/empty" "$run/partial" cp "$f/response-a.json" "$run/partial/a.json" cp "$f/response-invalid.json" "$run/partial/b.json" review partial 2 cp -R "$run/empty" "$run/complete" cp "$run/partial/a.json" "$run/complete/a.json" cp "$f/response-b.json" "$run/complete/b.json" review complete 0 printf '%s\n' "$run"

    阶段保存的报告预期
    缺答empty.report.json计划 1 项、4 个核准键,两版均缺答
    部分完成partial.report.jsonA 为 2/4,B 格式无效,整批差值为空
    完成complete.report.jsonA 为 2/4,B 为 4/4,整批差值为 +2

    状态 2 表示配对尚未完整,标准输出仍有报告和缺答或无效的原因。状态 1 表示输入或冻结校验失败。更正答卷时,用新目录保存修订件与新报告。旧目录保留原始收到的字节和当时的报告,以便分别用同一冻结文件重放。转录侧只需对应的 request-a.json 或 request-b.json。

    命令参考包括输入格式、旧样例、库消费、批量评分、证据回看、重放、配对差异和用量台账。终端可运行 moon run --frozen --target js cmd/audit -- --help 查看全部入口。

    AuditError

    pub suberror AuditError {
    InvalidInput(String)
    }

    Evaluation

    pub struct Evaluation {
    score : Score
    bad_keys : Array[String]
    findings : Array[Finding]
    candidate_rows : Int
    interaction : (Double, Double)?
    report : String
    }

    Evaluation::as_json

    Evaluation::pair_key_changes_json

    fn Evaluation::pair_key_changes_json(a : Evaluation, b : Evaluation) ->
    Json

    Compare two evaluations of the same reference. Report changes to reference keys separately from extra keys, with the original finding evidence.

    Finding

    pub struct Finding {
    code : String
    key : String
    expected : Row?
    actual : Row?
    source_text : String?
    candidate_count : Int
    }

    Row

    pub struct Row {
    part : String
    operator : String
    repeat : String
    value : Double?
    unit : String
    mm : Double?
    source_line : Int
    source_quote : String?
    // private fields
    }

    Score

    pub struct Score {
    reference_keys : Int
    correct_keys : Int
    issue_count : Int
    bad_reference_keys : Int
    extra_keys : Int
    correct_unmeasured : Int
    correct_true_zero : Int
    unit_equivalent : Int
    }

    keys, including explicit unmeasured records.

    Trial

    pub(all) struct Trial {
    id : String
    source : String
    reference : Array[Row]
    first : Array[Row]
    second : Array[Row]
    }

    check_split_source_text

    fn check_split_source_text(text : String, normalized_sha256 : (String) -> String?) -> String raise AuditError

    Check normalized UTF-8 sources across splits. The reader supplies a digest after removing one leading BOM and replacing CRLF with LF.

    check_split_sources

    fn check_split_sources(text : String, source_sha256 : (String) -> String?) -> String raise AuditError

    Also check for byte-identical sources crossing splits. The reader supplies a raw source SHA-256, or None if the source cannot be read.

    check_splits

    fn check_splits(text : String) -> String raise AuditError

    Check declared provenance without opening source documents.

    compare

    fn compare(source : String, reference : Array[Row], candidate : Array[Row]) -> String raise AuditError

    compare_batch

    fn compare_batch(trials : Array[Trial]) -> String raise AuditError

    compare_batch_json

    fn compare_batch_json(trials : Array[Trial]) ->
    Json
    raise AuditError

    compare_versions

    fn compare_versions(source : String, reference : Array[Row], first : Array[Row], second : Array[Row]) -> String raise AuditError

    evaluate

    fn evaluate(source : String, reference : Array[Row], candidate : Array[Row]) -> Evaluation raise AuditError

    explain_interaction

    fn explain_interaction(source : String, reference : Array[Row], candidate : Array[Row]) ->
    Json
    raise AuditError

    Explain why a pair can or cannot be compared, with each side's first design or numeric blocker and any key mismatches from normal scoring.

    interaction_ms

    fn interaction_ms(rows : Array[Row]) -> Double?

    Two-way crossed interaction mean square in mm² for balanced designs.

    parse_json_answer

    fn parse_json_answer(text : String) -> Array[Row] raise AuditError

    Read the project's version 1 raw JSON answer without deduplicating or rewriting records. JSON null denotes an explicitly unmeasured value.

    parse_table

    fn parse_table(text : String, reference~ : Bool) -> Array[Row] raise AuditError

    show_evidence

    fn show_evidence(source : String, reference : Array[Row], key : String) -> String raise AuditError

    validate_batch_trial_id

    fn validate_batch_trial_id(id : String) -> Unit raise AuditError

    Check the trial identifier used in batches and their manifests.

    validate_reference

    fn validate_reference(source : String, reference : Array[Row]) -> Unit raise AuditError