"""which requests could carry a photo?

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

import pandas as pd
import fieldwork as fw

requests = pd.DataFrame(
    [
        ("app", "pothole", "north", "closed", "photo", None),
        ("app", "pothole", "north", "closed", "photo", None),
        ("app", "pothole", "south", "open", "photo", None),
        ("app", "lighting", "south", "open", None, None),
        ("phone", "pothole", "north", "closed", None, "callback"),
        ("phone", "pothole", "south", "open", None, "callback"),
        ("phone", "lighting", "north", "closed", None, "callback"),
        ("phone", "lighting", "south", "open", None, "callback"),
        ("web", "pothole", "north", "closed", "photo", None),
        ("web", "lighting", "north", "closed", None, None),
        ("web", "lighting", "south", "open", None, None),
        ("web", "lighting", "south", "open", None, None),
    ],
    columns=[
        "channel",
        "service",
        "district",
        "status",
        "attachment",
        "callback",
    ],
)
requests.insert(0, "request_id", range(1001, 1013))

focused = fw.profile(
    requests,
    ["channel", "service", "attachment"],
    candidate_keys=["channel"],
    pairs=False,
)
print(fw.render_plaintext(focused.section("census")))

grain = focused.section("grain")
print(
    [test["target"] for test in grain["dependencies"] if test["holds"]]
)

figure = fw.render_svg(focused, section="census")

complete = fw.profile(
    requests,
    ["channel", "service", "attachment"],
    dropna=True,
    pairs=False,
)
tree = complete.section("census")["tree"]
print("Rows counted:", tree["evaluated_rows"])
print("Rows excluded for missing values:", tree["missing_excluded_rows"])

from pathlib import Path

Path("profile.svg").write_text(figure, encoding="utf-8")
