import json,glob,os,re
KW=re.compile(r"crack|damag|broke|broken|chip|lump|knock|gouge|scrape|scratch|dent|smash|clip|defect|ncr|rectif|repair|patch|make good|snag",re.I)
KERB=re.compile(r"kerb|curb",re.I)

def rows():
    for f in sorted(glob.glob("/root/.hermes/wa-bridge/days/*.jsonl")):
        b=os.path.basename(f)
        for l in open(f,encoding="utf-8"):
            try: r=json.loads(l)
            except: continue
            blob=" ".join(str(r.get(k) or "") for k in ("text","desc","caption"))
            yield b,r,blob

print("=== DAMAGE-ISH ROWS, ALL JOBS, ALL DAYS ===")
n=0
for b,r,blob in rows():
    if KW.search(blob):
        n+=1
        print("  %-26s %-6s who=%-10s %s" % (b, r.get("t"), r.get("who"), blob.strip()[:140]))
print("  TOTAL:",n)

print()
print("=== KERB/CURB MENTIONS (any) ===")
n=0
for b,r,blob in rows():
    if KERB.search(blob):
        n+=1
        print("  %-26s %-6s who=%-10s %s" % (b, r.get("t"), r.get("who"), blob.strip()[:140]))
print("  TOTAL:",n)

print()
print("=== POSITIVE CONTROL: rows mentioning 'footpath' (must be non-zero) ===")
n=sum(1 for b,r,blob in rows() if re.search("footpath",blob,re.I))
print("  TOTAL:",n)
print("=== CORPUS SIZE ===")
files=glob.glob("/root/.hermes/wa-bridge/days/*.jsonl")
tot=sum(1 for _ in rows())
print("  day-log files:",len(files)," rows:",tot)
print("  2636 files:",len([f for f in files if os.path.basename(f).startswith("2636")]))
