#!/usr/bin/env python3
"""Build the 50-row third-coder adjudication file from the frozen assignment."""

import csv
import json
from pathlib import Path


ROOT = Path(__file__).resolve().parent
ASSIGNMENT = ROOT / "university-manual-adjudication-assignment.jsonl"
OUTPUT = ROOT / "university-manual-adjudicated.csv"

COLUMNS = [
    "article_id", "url", "manual_reviewer", "eligible_news", "article_type",
    "admin_present", "challenger_present", "admin_tone", "challenger_tone",
    "admin_headline_frame", "challenger_headline_frame", "admin_lede_frame",
    "challenger_lede_frame", "admin_skepticism", "challenger_skepticism",
    "official_assertion_tested", "challenger_assertion_tested", "release_reliance",
    "documents_records_data", "affected_people_consulted",
    "power_history_consequences_context", "follow_up_orientation", "first_actor",
    "first_quoted_actor", "vulnerable_identification", "evidence_excerpt",
    "manual_notes",
]

# Values below supersede coder A after review of the full text, coder B, and the
# disagreement map. Fields absent from a row preserve coder A's value.
DECISIONS = {
    "spec-04ce4908533f9571": {
        "manual_notes": "Faculty-committee statement relay; University access restrictions are contextual, not a speaking administrative claim; no follow-up development is reported.",
    },
    "spec-09d62df0f94b6af5": {
        "challenger_tone": "0",
        "admin_headline_frame": "conflict",
        "admin_lede_frame": "conflict",
        "admin_skepticism": "2",
        "challenger_skepticism": "3",
        "official_assertion_tested": "1",
        "release_reliance": "0",
        "evidence_excerpt": "despite the restoration, researchers told Spectator that one year later the dramatic cuts have left lingering insecurity",
        "manual_notes": "Longitudinal enterprise report uses multiple affected researchers, records, national data, contrary institutional support, and prior coverage.",
    },
    "spec-0f6191721d015cfc": {
        "challenger_headline_frame": "not_present",
        "challenger_skepticism": "1",
        "challenger_assertion_tested": "0",
        "manual_notes": "The headline centers Barnard and ICE, not a challenger; counsel and locator context do not independently test counsel's status assertion.",
    },
    "spec-12b8d5d37120dd0d": {
        "admin_present": "0",
        "admin_tone": "",
        "admin_headline_frame": "not_present",
        "admin_lede_frame": "not_present",
        "admin_skepticism": "",
        "first_actor": "other",
        "manual_notes": "Knight Institute is an event host, not a University administrator here; the recap relays expert claims with little independent testing.",
    },
    "spec-1d50906ecf1f5a25": {
        "challenger_headline_frame": "conflict",
        "challenger_lede_frame": "conflict",
        "challenger_assertion_tested": "1",
        "affected_people_consulted": "1",
        "first_actor": "government",
        "first_quoted_actor": "challenger",
        "vulnerable_identification": "1",
        "manual_notes": "Court-record report tests workers' allegations and protesters' defense; a defendant's lawyer is consulted and public-case identifications carry an evident necessity rationale.",
    },
    "spec-28a33b86ae99a1d6": {
        "admin_lede_frame": "neutral_descriptive",
        "manual_notes": "The dean's memorial statement appears in the lede but makes no material factual assertion; police facts and the continuing investigation are independently sourced.",
    },
    "spec-2cb75ddd20bf692f": {
        "manual_notes": "Student-centered follow-up describes administrators as receptive but does not independently test the University's accessibility rationale.",
    },
    "spec-310146c877ab77a0": {
        "admin_tone": "0",
        "admin_lede_frame": "neutral_descriptive",
        "admin_skepticism": "3",
        "manual_notes": "Financial statements, an original rate calculation, layoffs, and policy alternatives scrutinize Shipman's position; the 99-percent claim remains unverified.",
    },
    "spec-32f36fded5741c94": {
        "challenger_headline_frame": "adverse",
        "challenger_lede_frame": "adverse",
        "release_reliance": "2",
        "manual_notes": "Official briefing sets the event and timing; notices, governance rules, prior practice, and a material nonconfirmation provide limited independent testing.",
    },
    "spec-34426605a5293fb2": {
        "manual_notes": "Document-heavy investigation tests the University's denial; publication of a nonpublic graduate's GRE score creates foreseeable privacy and harassment risk without an express rationale.",
    },
    "spec-404e4ee732c83722": {
        "manual_notes": "Legal-filing story adds prior nonparticipation, court orders, visa actions, and enrollment context but does not independently test the brief's broad claims.",
    },
    "spec-4360adee905ab9d1": {
        "admin_skepticism": "3",
        "challenger_skepticism": "3",
        "manual_notes": "Multiple experts, comparison cases, survey data, and counterexamples explicitly resist a one-sided glass-cliff conclusion.",
    },
    "spec-499eadbee39b34f1": {
        "admin_lede_frame": "conflict",
        "manual_notes": "Hearing analysis notes Shafik's inconsistencies and steadiness while checking testimony, the website, sworn-status insinuations, and responses.",
    },
    "spec-49c164cc2b99b514": {
        "challenger_headline_frame": "neutral_descriptive",
        "challenger_lede_frame": "neutral_descriptive",
        "challenger_skepticism": "2",
        "manual_notes": "Vote totals and authority limits test the resolution's weight, but the underlying misconduct claims are not independently tested and no additional affected constituency is interviewed.",
    },
    "spec-4b2720c9c53bcd04": {
        "admin_present": "0",
        "admin_tone": "",
        "admin_headline_frame": "not_present",
        "admin_lede_frame": "not_present",
        "admin_skepticism": "",
        "challenger_skepticism": "3",
        "manual_notes": "Data-rich explainer centers affiliates, budgets, GAO findings, and an affected patient; no Columbia administrator or official statement appears.",
    },
    "spec-4febd1ad381f2140": {
        "challenger_headline_frame": "neutral_descriptive",
        "vulnerable_identification": "1",
        "manual_notes": "Strong contrary case: student, University, union, professor, data, and federal claims are tested; named witnesses spoke in a public federal session.",
    },
    "spec-56c3c790f5c7ec8e": {
        "admin_tone": "0",
        "manual_notes": "Sympathetic release feature verifies detention chronology through court proceedings; criticism of Columbia's silence is attributed, not reporter voice.",
    },
    "spec-5e3eb24d8a7cd159": {
        "release_reliance": "1",
        "manual_notes": "Archived-page verification and Columbia's earlier compliance materially scrutinize Shipman's later anti-interference stance despite the favorable announcement.",
    },
    "spec-5f2735b0a0e4f988": {
        "admin_skepticism": "2",
        "official_assertion_tested": "0",
        "challenger_assertion_tested": "1",
        "manual_notes": "On-scene reporting, policy text, court history, counterprotester challenge, and response requests test protest claims; the University's no-notice assertion remains unverified.",
    },
    "spec-5fed382c7fa0e5d6": {
        "admin_present": "0",
        "admin_tone": "",
        "admin_lede_frame": "not_present",
        "admin_skepticism": "",
        "manual_notes": "Nightline and a reform petition receive direct treatment; an administrative obstacle is mentioned but no University administrator or official claim appears.",
    },
    "spec-61e6477d08299748": {
        "admin_lede_frame": "neutral_descriptive",
        "affected_people_consulted": "0",
        "manual_notes": "The supplied body appends an access update; observations and custody figures contextualize competing statements, but no additional affected person is interviewed.",
    },
    "spec-6b18a159ddf626e3": {
        "challenger_tone": "0",
        "official_assertion_tested": "1",
        "manual_notes": "Event recap checks the access rationale against Khalil's status and record context and transparently corrects an earlier misframing.",
    },
    "spec-7aeb826eb8cae2fa": {
        "challenger_skepticism": "2",
        "challenger_assertion_tested": "1",
        "manual_notes": "Participant accounts are contextualized with military procedure and human-rights scrutiny; identified speakers discuss imprisonment voluntarily.",
    },
    "spec-85043ca4f3285ae4": {
        "official_assertion_tested": "1",
        "challenger_assertion_tested": "1",
        "manual_notes": "Congressional letters dominate, but jurisdiction, finances, incidents, institutional responses, and prior chronology test both institutional and critic claims.",
    },
    "spec-850505a2aab7c650": {
        "admin_headline_frame": "conflict",
        "challenger_headline_frame": "adverse",
        "challenger_lede_frame": "conflict",
        "admin_skepticism": "3",
        "challenger_skepticism": "2",
        "challenger_assertion_tested": "1",
        "manual_notes": "Obtained amnesty email, code gap, SGA figures, an anonymous affected student, and Barnard's withheld denominator strongly test both sides.",
    },
    "spec-89ede7c6b33c5df4": {
        "manual_notes": "The article explicitly notes the government supplied no evidence; Columbia's narrow enrollment-record assertion and counsel's status claim are relayed without independent verification.",
    },
    "spec-913f50de04f04e62": {
        "manual_notes": "Administrative email is substantially relayed; the unspecified threat information is not tested and no affected campus user appears.",
    },
    "spec-92d47812874c2e43": {
        "follow_up_orientation": "0",
        "manual_notes": "Self-contained NYPD brief; the text mentions a handcuff photo, but the supplied package does not permit assessment of whether the person is identifiable.",
    },
    "spec-9570f296d2bb9ecc": {
        "admin_skepticism": "1",
        "official_assertion_tested": "1",
        "manual_notes": "Award announcement is supplemented with substantial career and controversy context that qualifies the school's praise of its honoree.",
    },
    "spec-97218e7ea47cda28": {
        "admin_skepticism": "3",
        "manual_notes": "Policy announcement receives sustained easement, closure-history, practical-limits, notice, and correction scrutiny.",
    },
    "spec-99328be767471393": {
        "admin_skepticism": "",
        "official_assertion_tested": "",
        "manual_notes": "Positive achievement profile interviews both recipients; no University administrator makes a material assertion requiring a test.",
    },
    "spec-9a48483e03b2f087": {
        "manual_notes": "Exceptional governance reporting uses bylaws, statutes, history, competing responses, a correction, and an update to test both sides.",
    },
    "spec-9a9bfc330d466b5a": {
        "admin_headline_frame": "conflict",
        "admin_lede_frame": "conflict",
        "admin_skepticism": "",
        "release_reliance": "0",
        "manual_notes": "Reuters-led investigation brief supplies federal-process history; the University declines comment and makes no material assertion.",
    },
    "spec-acd0e80082919afb": {
        "article_type": "event_recap",
        "challenger_lede_frame": "not_present",
        "admin_skepticism": "",
        "official_assertion_tested": "",
        "vulnerable_identification": "1",
        "manual_notes": "Service-oriented event feature uses registry data and interviews a patient's father and a student donor; family participation supplies a necessity rationale for medical details.",
    },
    "spec-ad382acc17fc0b14": {
        "official_assertion_tested": "1",
        "manual_notes": "Faculty-reaction piece foregrounds critics but distinguishes speculation from known facts and tests administrative statements against chronology and records.",
    },
    "spec-b0e6c3b76637be50": {
        "manual_notes": "Breaking brief contrasts government labels with counsel's unverified account of Khalil's status; Columbia housing is a location, not an administrative actor.",
    },
    "spec-c14a7e60c4fd9cd9": {
        "admin_headline_frame": "conflict",
        "admin_lede_frame": "conflict",
        "challenger_skepticism": "",
        "manual_notes": "Email-origin story sharply tests autonomy rhetoric against prior compliance, omissions, unresolved online-study access, and peer comparisons.",
    },
    "spec-c6f6dad0891da97f": {
        "manual_notes": "Press-release-origin gift story adds debt, layoff, tuition, and aid context but does not independently verify the gift amount.",
    },
    "spec-c8deae8162656384": {
        "manual_notes": "Short social-post-driven report attributes both allegations and condemnation while independently testing neither side's material claims.",
    },
    "spec-cbb116f09ebb7d74": {
        "admin_tone": "0",
        "admin_lede_frame": "neutral_descriptive",
        "manual_notes": "Single-source student profile is favorable to the student leader; institutional critique is attributed and receives no administrative response.",
    },
    "spec-cbf87fcb7a0f9491": {
        "admin_skepticism": "",
        "manual_notes": "Routine event recap; SPS is an institutional host but makes no material assertion and reporter voice toward it is neutral.",
    },
    "spec-e259613116f2ce96": {
        "challenger_headline_frame": "adverse",
        "challenger_lede_frame": "adverse",
        "manual_notes": "Government-post roundup relays criticism and labels without University or protester responses and performs no independent testing.",
    },
    "spec-e4a549db461ef4f6": {
        "article_type": "analysis_explainer",
        "admin_skepticism": "1",
        "challenger_skepticism": "3",
        "release_reliance": "0",
        "manual_notes": "Visual evidence, medical documentation, caveats, and prior reporting test protester claims; an affected student's contradiction contextualizes the University reimbursement claim.",
    },
    "spec-e578b00fe8dc7b6a": {
        "manual_notes": "Government and University releases dominate; the investigation is labeled unresolved, serious allegations are untested, and no affected student or faculty response appears.",
    },
    "spec-e889287534566a11": {
        "official_assertion_tested": "1",
        "manual_notes": "Town-hall claims are tested with an affected student's account, court order, population data, policy history, and a substantive correction.",
    },
    "spec-eb547279c7626608": {
        "manual_notes": "Deep report summary includes criticism and peer comparisons, but the task force's testimonial allegations are not independently verified and no affected student is interviewed.",
    },
    "spec-f3536352da89cb8e": {
        "manual_notes": "Announcement-origin honors story adds interviews with three student inductees; official material sets the event, while treatment of institution and students is favorable.",
    },
}


def main() -> None:
    rows = [json.loads(line) for line in ASSIGNMENT.read_text(encoding="utf-8").splitlines() if line.strip()]
    out = []
    for source in rows:
        row = {column: str(source["coder_a"].get(column, "")) for column in COLUMNS}
        row.update(DECISIONS.get(source["article_id"], {}))
        row["article_id"] = source["article_id"]
        row["url"] = source["url"]
        row["manual_reviewer"] = "adjudicator"
        out.append(row)

    with OUTPUT.open("w", encoding="utf-8", newline="") as handle:
        writer = csv.DictWriter(handle, fieldnames=COLUMNS)
        writer.writeheader()
        writer.writerows(out)


if __name__ == "__main__":
    main()
