text
stringlengths
0
1.47k
- Scan order is by "share ÷ pages": scan small districts first, put large districts last with a page cap.
- When discriminating tests can't separate the candidates, next gives a definite next step instead of stalling.
init create board.json
add add candidates (country/province/city/district/area/point); --from bulk-imports output of poi.py / gazetteer.py / osm.py geom
children use gazetteer.py to add every subdivision of an admin area as a candidate ("list the whole category first")
clue record a clue: seen / text read / inferred / computed
evidence a clue's likelihood ratio for some candidates (>1 supports, <1 opposes)
exclude exclude a candidate (needs a computed file)
scan-bbox set a candidate's scan extent (built-up area); pages are counted from it
urban fill scan-bbox automatically with gazetteer.py urban
falsify write the falsification condition before scanning/confirming
rank current ranking (score, share, evidence, pages, share/page)
next suggested next step
check checklist before the conclusion
report generate the candidates/alternatives/excluded/unused-clues fields of result.json
apply lookup clues (calling code, driving side, territories; plates, area codes… from region packs) add candidates and evidence automatically (uses clues.py)
move put a candidate under another candidate (a point under its road) so its supporting evidence counts there
country set the country context: apply restricts region-pack lookups to it, next uses its pack's tips
log print the ledger
Examples:
board.py init --photo photo.jpg
board.py children <municipality or province name> # all 38 districts become candidates, uniform prior
board.py add --from pois.json --level area --parent <city> # fine-level candidates (same-name campuses, OSM walled compounds) all go on the board; don't hand-pick
board.py clue "bus yellow on top, green below; green rear stripe curves down" --kind livery --status observed --file bus_zoom.png
board.py evidence --clue K1 --for <district A>:5 --for <district B>:2 --why "compared bus rears one by one across both districts' bus photos" --file livery_sheet.jpg
board.py apply --kind plate --value <first two plate characters>
board.py urban <district A> --within <municipality or province name>
board.py rank
board.py next
board.py falsify <district A> --text "give up if the sports field's long axis isn't north-south"
board.py exclude <district B> --clue K4 --computed frame.json --why "by the view-angle range X should be in frame and ≥40px; it isn't in the image"
board.py check
board.py report --merge result.json
"""
from __future__ import annotations
import argparse
from _net import PROXY_HELP
import json
import math
import os
import re
import subprocess
import sys
from datetime import datetime
from pathlib import Path
import regions
HERE = Path(__file__).parent
# uv run writes its own path into the UV env var: call child scripts with it, so uv is found even when it isn't on PATH (e.g. just installed, terminal not reopened)
UV = os.environ.get("UV") or "uv"
LEVELS = ["country", "admin1", "admin2", "city", "district", "area", "road", "point"]
LEVEL_LABEL = {"country": "country", "admin1": "province/state", "admin2": "prefecture/county", "city": "city",
"district": "district", "area": "area", "road": "road", "point": "point"}
# Candidates with extent: exclusion scope must be <= evidence scope. Looking at one point on a road/area and excluding the whole of it is a mistake that recurred twice
EXTENDED_LEVELS = {"district", "area", "road"}
COVERS_MIN = 0.5 # --covers must cover at least this fraction of the candidate's extent before the whole candidate can be excluded
STATUS = ["observed", "read", "inferred", "computed"]
# Likelihood ratio caps: inferences can only rank; only text read and computed results can move the score a lot
LR_CAP = {"inferred": 3.0, "observed": 5.0, "read": 50.0, "computed": 50.0}
GLOBAL_KINDS = ("calling-code", "driving-side", "territories") # clues.py tables in data/, not region packs
CHEAP_OPS = [
("plate/area-code/calling-code", "plate, area code or calling code readable → `clues.py lookup` + `board.py apply`"),
("terrain", "flat vs hill city in the image → `terrain.py view` or z13 satellite imagery per candidate to check terrain; one call rules out a batch"),
("livery", "bus/taxi livery → image search for \"<city> <color> bus\" in the local language; read route signs from the results, compare the rear waistline stripe district by district"),
("municipal", "guardrails, street lights, bus stops, curb styles → street view of each candidate's built-up area (`gsv.py sheet --points`, or the street-view script the region pack names), one contact sheet per candidate"),
("network", "water/road network template → `tiles.py fetch --zoom 13` per candidate, compare river direction and number of bridges"),
("phenology", "vegetation + month → weak evidence only, can't exclude on its own"),
]
def _norm(s: str) -> str:
return re.sub(r"[\s()()]", "", s or "").rstrip("市省区县自治州自治县自治区特别行政区")
def _clue_kind(kind: str) -> str:
# Accept the long spelling in new clues and in boards written by older versions.
return "infra" if kind.strip().lower() in ("infra", "infrastructure") else kind
def _load(p: Path) -> dict:
if not p.exists():
sys.exit(f"No {p}: run `board.py init --photo photo.jpg` first")
return json.loads(p.read_text(encoding="utf-8"))
def _save(p: Path, b: dict) -> None:
b["updated"] = datetime.now().isoformat(timespec="seconds")
p.write_text(json.dumps(b, ensure_ascii=False, indent=1), encoding="utf-8")
def _find(b: dict, name: str) -> str:
if name in b["candidates"]:
return name
hits = [k for k in b["candidates"] if _norm(k) == _norm(name)]
if len(hits) == 1:
return hits[0]