"""a seedling pickup report for the volunteer coordinator

Generated from src/content/docs/reference/render-html.md.
Run with the documented Fieldwork release in a writable directory.
Exports are saved there using the filenames shown in the walkthrough.
"""

from pathlib import Path

import pandas as pd
import fieldwork as fw

orders = pd.DataFrame(
    [
        ("G01", "tomato", "T1", "Saturday"),
        ("G01", "basil", "T2", "Saturday"),
        ("G01", "lettuce", None, "Saturday"),
        ("G02", "tomato", "T1", None),
        ("G02", "basil", "T2", None),
        ("G03", "lettuce", "T3", "Sunday"),
        ("G03", "basil", "T2", "Sunday"),
        ("G04", "tomato", None, None),
    ],
    columns=["order", "crop", "tray", "pickup_day"],
)

result = fw.explore(
    orders,
    features=["crop", "tray", "pickup_day"],
    table_id="seedling_orders",
)
availability = result.section("missingness").to_frame("availability")
print(
    availability[["feature", "populated", "denominator"]].to_string(
        index=False
    )
)

html = fw.render_html(result, section="missingness", max_findings=20)
report_file = Path("render_html.html")
report_file.write_text(html, encoding="utf-8")

short_html = fw.render_html(
    result, section="missingness", max_findings=2
)
Path("pickup-summary.html").write_text(short_html, encoding="utf-8")

topology_html = fw.render_html(
    result, section="missingness", detail="topology"
)
Path("pickup-structure.html").write_text(
    topology_html, encoding="utf-8"
)

import json

evidence_json = json.dumps(result.to_dict(), indent=2, allow_nan=False)
Path("pickup-evidence.json").write_text(evidence_json, encoding="utf-8")
