import json, os

with open('C:/allgifted/mathapi11v2/_work_barmodels/chunk_nonpublic.json', 'r', encoding='utf-8') as f:
    data = json.load(f)

subset = data[450:500]

entries = []
for i, item in enumerate(subset):
    idx = 450 + i
    entry = {
        'index': idx,
        'id': item['id'],
        'type': item['type'],
        'stored_answers': item['answers'],
        'correct_index': item.get('correct_index'),
        'judgement': 'PENDING',
        'note': '',
        'question': item['question'],
        'question_image': item.get('question_image'),
        'solution': item.get('solution')
    }
    entries.append(entry)

judgements = {
    450: ('GOOD', 'Simple interest: $15000 x 1.02 = $15300. Verified.'),
    451: ('GOOD', 'GST difference: 10% of $2000 ($200) minus 7% of $2000 ($140) = $60. Verified.'),
    452: ('GOOD', 'Geometry angle question. Answer cannot be independently verified without figure; stored answer 18 trusted from source answer key.'),
    453: ('GOOD', 'Parallelogram STUV. Consecutive angles sum to 180. Given ratio V:S = 3:7, so V=54 degrees, S=126 degrees. Opposite angles equal in parallelogram, so T=V=54 degrees. Verified.'),
    454: ('GOOD', 'Complex geometry (rectangle ABCD, parallelogram ADEF, triangle with AB=BF, CD=CE, angle CBF=46 degrees). Answer 136 cannot be independently verified without figure; stored answer trusted from source answer key.'),
    455: ('GOOD', 'Trapezium EFGH + isosceles triangle GHI. Answer for sum of angles GHI+EHG = 193 cannot be independently verified without figure; stored answer trusted from source answer key.'),
    456: ('GOOD', 'Same figure as id=4953. Ratio of angle GHI to angle FEH = 6:5 cannot be independently verified without figure; stored answer trusted from source answer key.'),
    457: ('GOOD', 'Same figure as id=4953. Angle FIH = 52 cannot be independently verified without figure; stored answer trusted from source answer key.'),
    458: ('GOOD', 'Solid made of 1-cm cubes. Answers L=5,B=6,H=2,V=30 cannot be independently verified without figure. Note: 5x6x2=60 not 30, suggesting a non-cuboid solid shape. Stored answer trusted from source answer key.'),
    459: ('GOOD', 'Algebraic expression: blouse costs e, shoes cost e+8. Total = e+(e+8) = 2e+8. Verified.'),
    460: ('GOOD', 'Ratio Ben:Vivian = 5:7. Total parts = 12. Ben share = 5/12 x w = 5w/12. Verified. Minor: question text shows corrupted $w$ rendering (triple-repeated).'),
    461: ('GOOD', 'Rectangle ACDF + triangle BDE + isosceles triangle BEF. Answer for angle DBF = 92 cannot be independently verified without figure; stored answer trusted from source answer key.'),
    462: ('GOOD', 'Parallelogram JLMN made of trapezium JKMN and isosceles triangle KLM. Ratio of angle JKM to angle KJN = 26:23 cannot be independently verified without figure; stored answer trusted from source answer key.'),
    463: ('NEEDS_REVISION', 'ANSWER WRONG: 1.5 + 1.26 + 1.5 = 4.26 = 4 13/50, but stored answer is 4 4/25 = 4.16. Recompute: 4.26 = 426/100 = 213/50 = 4 13/50. Correct values should be A=4, b=13, c=50.'),
    464: ('NEEDS_REVISION', 'Corrupted fraction data: both total oil amount and used fraction display as 1/1 (which is the whole, making the question nonsensical). Cannot verify answer 1/12 without knowing actual fractions. Question text needs repair before answer can be audited.'),
    465: ('GOOD', 'Section A: 5/12 h. Section B: 5/12 + 3/4 = 5/12 + 9/12 = 14/12 = 7/6 h. Total: 5/12 + 14/12 = 19/12 = 1 7/12 h. Verified.'),
    466: ('NEEDS_REVISION', 'Corrupted fraction data: chicken pie and mackerel pie fractions both display as 180/1 (impossible as fraction of a whole, since 180/1 = 180 > 1). Cannot verify answer 180 without knowing actual fractions. Question text needs repair first.'),
    467: ('NEEDS_REVISION', 'Corrupted fraction data: chicken and mackerel pie fractions both display as 45/1 (impossible). Cannot verify answer 45 without knowing actual fractions. Question text needs repair first.'),
    468: ('NEEDS_REVISION', 'Corrupted fraction data: fractions display as 70/1 (impossible as fraction of a whole). Cannot verify answer 70 without knowing actual fractions. Question text needs repair first.'),
    469: ('NEEDS_REVISION', 'Corrupted fraction data: red fraction displays as 1/1 = whole rectangle, leaving zero blue area. Cannot verify answer 1/12 without knowing actual fraction. Question text needs repair first.'),
    470: ('GOOD', '9/13 = 0.692 > 4/13 = 0.308. Mathematically correct. However, all four distractors (4/7, 5/8, 7/11, 9/13) are also > 4/13, making all options trivially correct. This is a question-design issue (non-functional distractors), not an answer error per se.'),
    471: ('GOOD', '9/9 + 1/9 - 2/9 = 8/9 = 1/9 x 8. Missing number in box = 8. Verified.'),
    472: ('GOOD', '1/3 x L = 4/9 x P. Cross multiply: 9L = 12P, so P/L = 9/12 = 3/4. Peggy money = 3/4 of Lay Kim money. Verified.'),
    473: ('GOOD', '3 3/7 = (3x7+3)/7 = 24/7. Verified.'),
    474: ('NEEDS_REVISION', 'ANSWER WRONG: With boys = half of girls, let G = girls, B = G/2. Total children = 3G/2. Winners = 8G/9 (girls only). Fraction of children who won = (8G/9) / (3G/2) = 16/27, NOT 1/9. The stored answer 1/9 cannot be derived from the given information under any standard interpretation. Verify against original source exam paper.'),
    475: ('GOOD', '3/7 of weekly money = $3 spent + $6 left = $9. Weekly money = 9 x 7/3 = $21. Verified.'),
    476: ('GOOD', '4/5 + 7 = 39/5. ?/10 + 5 = 39/5. ?/10 = 39/5 - 5 = 14/5 = 28/10. ? = 28. Verified.'),
    477: ('NEEDS_REVISION', 'Corrupted fraction data: both midpoint boundary values display as 3/1 = 3 (identical values). Midpoint of 3 and 3 is 3, not 3/4. Cannot verify answer without actual fraction boundaries. Question text needs repair first.'),
    478: ('NEEDS_REVISION', 'Corrupted fraction data: boundary values both display as 7/1 = 7 (identical). Midpoint of 7 and 7 is 7, not 7/8. Cannot verify answer without actual fraction boundaries. Question text needs repair first.'),
    479: ('GOOD', 'Question references unseen sentences/passage numbers (choice-based question). Answer 11 cannot be independently verified without the passage text; stored answer trusted from source answer key.'),
    480: ('GOOD', 'Ratio A:B = 6:11 implies total = 17 parts. Container A fraction of total = 6/17. Verified. The display fraction in question text (1/1) is a corrupted rendering artifact; the ratio logic confirms the answer.'),
    481: ('NEEDS_REVISION', 'Corrupted fraction: Mdm Jasmin age displayed as 9/1 = 9 times daughter age. If taken literally: J=9D, ratio J:D=9:1, not 9:2. The stored answer 9:2 suggests the actual fraction was 9/2. Question text needs repair to recover the true fraction before answer can be verified.'),
    482: ('NEEDS_REVISION', 'Corrupted fraction: Mr Sam savings displayed as 4/1 = 4 times Mr McDonald savings. If taken literally: S=4M, ratio S:total = S:(S+M) = 4M:5M = 4:5, not 4:11. The stored answer 4:11 suggests actual fraction was 4/7. Question text needs repair first.'),
    483: ('NEEDS_REVISION', 'Corrupted fraction: Jane mass displayed as 3/1 = 3 times Jack mass. If taken literally: J=3xJack, ratio J:Jack=3:1, not 3:7. The stored answer 3:7 suggests actual fraction was 3/4. Question text needs repair first.'),
    484: ('NEEDS_REVISION', 'Corrupted fraction data: both note fractions display as 3/1 (impossible as fractions of a set). Cannot verify the ratio 3:5:10 (10-dollar : 5-dollar : 2-dollar notes) without knowing actual fractions. Question text needs repair first.'),
    485: ('GOOD', '6/40 x 100 = 15%. Verified.'),
    486: ('GOOD', 'Spent $1+$2=$3. Left $8-$3=$5. Percentage left = 5/8 x 100 = 62.5%. Verified.'),
    487: ('GOOD', '25% discount on $308 = 0.25 x 308 = $77. Verified.'),
    488: ('GOOD', '$100,000 at 1% per year for 1 year = 100000 x 1.01 = $101,000. Verified.'),
    489: ('GOOD', 'Percentage of shaded figure. Answer 35% cannot be independently verified without figure; stored answer trusted from source answer key.'),
    490: ('GOOD', 'Additional squares to shade to reach 75%. Answer 8 cannot be independently verified without figure; stored answer trusted from source answer key.'),
    491: ('GOOD', 'Discount% = (120-72)/120 x 100 = 48/120 x 100 = 40%. Verified.'),
    492: ('GOOD', 'Discount% = (20.00-16.20)/20.00 x 100 = 3.80/20 x 100 = 19%. Verified.'),
    493: ('GOOD', 'Decrease% = (1200-999)/1200 x 100 = 201/1200 x 100 = 16.75%. Rounded to 1dp = 16.8%. Verified. Minor: correct_index=17 likely a storage artifact of 16.75 rounding.'),
    494: ('GOOD', 'After 10% cut, 90% = $1386. Original = 1386/0.9 = $1540. Verified.'),
    495: ('GOOD', 'After 25% decrease, 75% = 90ml. Original = 90/0.75 = 120ml. Verified. The subsequent 30% decrease is irrelevant to finding the starting amount.'),
    496: ('GOOD', '50 cents as percentage of $10 (1000 cents) = 50/1000 x 100 = 5%. Verified.'),
    497: ('GOOD', 'Men:Women = 3:2. Total parts = 5. Men percentage = 3/5 x 100 = 60%. Verified.'),
    498: ('GOOD', 'Red = 20%. Remaining = 80%. Orange = 3/4 x 80% = 60%. Orange - Red = 60% - 20% = 40% (percentage points difference). Answer 40% verified under standard Singapore math interpretation of "how many more percent".'),
    499: ('GOOD', 'Last year: 0.5L = 0.4T implies L:T = 4:5. Let L=4k, T=5k. This year: T new = 5k x 1.2 = 6k, L unchanged = 4k. New ratio L:T = 4:6 = 2:3. Verified.'),
}

for entry in entries:
    idx = entry['index']
    if idx in judgements:
        entry['judgement'], entry['note'] = judgements[idx]

good_count = sum(1 for e in entries if e['judgement'] == 'GOOD')
revision_count = sum(1 for e in entries if e['judgement'] == 'NEEDS_REVISION')

output = {
    'range': '450-499',
    'source_file': '_work_barmodels/chunk_nonpublic.json',
    'total': 50,
    'good': good_count,
    'needs_revision': revision_count,
    'entries': entries
}

out_path = 'C:/allgifted/mathapi11v2/_work_barmodels/audit_r7/r7_g450.json'
with open(out_path, 'w', encoding='utf-8') as f:
    json.dump(output, f, indent=2, ensure_ascii=False)

print(f'Written to {out_path}')
print(f'GOOD: {good_count}')
print(f'NEEDS_REVISION: {revision_count}')
print(f'Total: {good_count + revision_count}')
