import json

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

items = data[100:150]

GOOD = 'GOOD'
REV = 'NEEDS_REVISION'

# ---- detailed per-item verdicts ----
verdicts = {}

# idx 100-103: shape pattern MCQs (image-based, no text answers)
for idx in range(100, 104):
    it = data[idx]
    verdicts[idx] = (GOOD, 'Shape pattern: options embedded in image. Pattern identification requires image viewing.')

# idx 104 (id=1860): 2046
verdicts[104] = (GOOD, '2000 + 40 + 6 = 2046. Answer correct.')

# idx 105 (id=1863): 800
verdicts[105] = (GOOD, '8 is the hundreds digit in 839, so it stands for 800. Answer correct.')

# idx 106 (id=1895): 10
verdicts[106] = (GOOD, '8000+500+10+2 = 8512. Answer correct.')

# idx 107 (id=1899): 1000
verdicts[107] = (GOOD, '1000+500+90 = 1590. Answer correct.')

# idx 108 (id=1919): number pattern, answers correct but CI is value not index
verdicts[108] = (REV, 'Answers [3999,4000,4001] are correct (+1 each step). BUT correct_index=3999 is the answer VALUE, not an index position. Should be 0. DATA INTEGRITY: correct_index field stores the value rather than the array index.')

# idx 109 (id=1920): same CI bug
verdicts[109] = (REV, 'Answers [4292,4302,4312] are correct (+10 each step). BUT correct_index=4292 is the answer VALUE, not an index. Should be 0.')

# idx 110 (id=1921): same CI bug
verdicts[110] = (REV, 'Answers [2954,3054,3154] are correct (+100 each step). BUT correct_index=2954 is the answer VALUE, not an index. Should be 0.')

# idx 111 (id=1922): same CI bug
verdicts[111] = (REV, 'Answers [7302,8302,9302] are correct (+1000 each step). BUT correct_index=7302 is the answer VALUE, not an index. Should be 0.')

# idx 112 (id=1924): 6541
verdicts[112] = (GOOD, 'Digits 5,1,6,4 sorted descending: 6,5,4,1 = 6541. Answer correct.')

# idx 113 (id=1932): same CI bug
verdicts[113] = (REV, 'Answers [3805,4805,5805] are correct (+1000 each step). BUT correct_index=3805 is the answer VALUE, not an index. Should be 0.')

# idx 114 (id=1933): same CI bug
verdicts[114] = (REV, 'Answers [3740,3940,4140] are correct (+200 each step). BUT correct_index=3740 is the answer VALUE, not an index. Should be 0.')

# idx 115 (id=1937): 99
verdicts[115] = (GOOD, '9900 / 100 = 99 hundreds. Answer correct.')

# idx 116 (id=1954): 714
verdicts[116] = (GOOD, 'Digits 4,1,7. Greatest=741, second greatest=714. Answer correct.')

# idx 117 (id=1955): 9634
verdicts[117] = (GOOD, 'Digits 9,4,6,3. Greatest=9643, second greatest=9634 (swap last two). Answer correct.')

# idx 118 (id=1956): 365
verdicts[118] = (GOOD, 'Digits 6,5,3. Smallest=356, second smallest=365. Answer correct.')

# idx 119 (id=1957): 1284
verdicts[119] = (GOOD, 'Digits 8,1,4,2. Smallest=1248, second smallest=1284. Answer correct.')

# idx 120 (id=1958): 865
verdicts[120] = (GOOD, 'Pick 3 largest digits from {4,8,5,3,6}: 8,6,5. Arrange descending = 865. Answer correct.')

# idx 121 (id=1959): 125
verdicts[121] = (GOOD, 'Pick 3 smallest digits from {5,1,7,9,2}: 1,2,5. Arrange ascending = 125. Answer correct.')

# idx 122 (id=1960): 876
verdicts[122] = (GOOD, 'Pick 3 largest digits from {2,7,0,4,8,6}: 8,7,6. Arrange descending = 876. Answer correct.')

# idx 123 (id=1961): 134
verdicts[123] = (GOOD, 'Pick 3 smallest digits from {3,5,1,9,4}: 1,3,4. Arrange ascending = 134. Answer correct.')

# idx 124 (id=1995): 3085
verdicts[124] = (GOOD, '6018 - 2933 = 3085. Answer correct.')

# idx 125 (id=2018): 9
verdicts[125] = (GOOD, '1877 - 929 = 948. Hundreds digit of 948 is 9. Answer correct (index 2).')

# idx 126 (id=2040): 9
verdicts[126] = (GOOD, '1811 + 1599 = 3410. Missing digit is 9. Answer correct.')

# idx 127 (id=2043): answer 8 is correct, but CI=1 points to None
verdicts[127] = (REV, '4123 - 3888 = 235. Missing digit is 8 (answer correct). BUT correct_index=1 while answers[1]=None. correct_index should be 0 to point to the answer at index 0.')

# idx 128 (id=2045): 19
verdicts[128] = (GOOD, '28 - 9 = 19. Answer correct.')

# idx 129 (id=2046): 205
verdicts[129] = (GOOD, '300 - 95 = 205. Answer correct.')

# idx 130 (id=2047): 33
verdicts[130] = (GOOD, '15 + 18 = 33. Answer correct.')

# idx 131 (id=2048): 74
verdicts[131] = (GOOD, '160 - 86 = 74. Answer correct.')

# idx 132 (id=2049): 105
verdicts[132] = (GOOD, '30 + 75 = 105. Answer correct.')

# idx 133 (id=2051): 80
verdicts[133] = (GOOD, '550 - 470 = 80. Answer correct.')

# idx 134 (id=2055): 6
verdicts[134] = (GOOD, '35 - 29 = 6 kg. Answer correct.')

# idx 135 (id=2056): 16
verdicts[135] = (GOOD, '61 - 45 = 16. Answer correct.')

# idx 136 (id=2060): 325
verdicts[136] = (GOOD, '415 - 90 = 325 children. Answer correct.')

# idx 137 (id=2077): model 4, image-based
verdicts[137] = (GOOD, 'Bar model: book=12, CD=12+7=19. Model 4 should show two bars. Visual verification required.')

# idx 138 (id=2079): model 2, image-based
verdicts[138] = (GOOD, 'Bar model: goats=27, ducks=27+23=50. Model 2 should show two bars. Visual verification required.')

# idx 139 (id=2093): 6500
verdicts[139] = (GOOD, 'Sunday = 2980+540 = 3520. Total = 2980+3520 = 6500. Answer correct.')

# idx 140 (id=2094): 5230
verdicts[140] = (GOOD, 'Betty = 2300+630 = 2930. Total = 2300+2930 = 5230. Answer correct.')

# idx 141 (id=2095): 450
verdicts[141] = (GOOD, 'Derrick = 3260-1405 = 1855. Diff = 1855-1405 = 450. Answer correct.')

# idx 142 (id=2096): 1100
verdicts[142] = (GOOD, 'Sun = 5000-1950 = 3050. Diff = 3050-1950 = 1100. Answer correct.')

# idx 143 (id=2101): 54
verdicts[143] = (GOOD, 'Tom = 35+8 = 43. Fred = 43+11 = 54. Answer correct.')

# idx 144 (id=2102): 29
verdicts[144] = (GOOD, 'Second = 43-5 = 38. Third = 38-9 = 29. Answer correct.')

# idx 145 (id=2104): 1051
verdicts[145] = (GOOD, 'Computer = 2000-650-299 = 1051. Answer correct.')

# idx 146 (id=2105): 900
verdicts[146] = (GOOD, 'Spent = 1250+950 = 2200. Left = 3100-2200 = 900. Answer correct.')

# idx 147 (id=2122): 63
verdicts[147] = (GOOD, '9 x 7 = 63. Answer correct.')

# idx 148 (id=2123): 72
verdicts[148] = (GOOD, '8 x 9 = 72. Answer correct.')

# idx 149 (id=2125): 72
verdicts[149] = (GOOD, '9 x 8 = 72. Answer correct.')

# ---- Build output ----
items_output = []
for idx in range(100, 150):
    it = data[idx]
    v, note = verdicts[idx]
    img = it.get('question_image', '') or ''
    items_output.append({
        'index': idx,
        'id': it['id'],
        'type': it['type'],
        'image': img,
        'question': it['question'],
        'answers': it['answers'],
        'correct_index': it['correct_index'],
        'verdict': v,
        'notes': note
    })

good_count = sum(1 for i in items_output if i['verdict'] == GOOD)
rev_count = sum(1 for i in items_output if i['verdict'] == REV)

output = {
    'range': '100-149',
    'total': len(items_output),
    'good': good_count,
    'needs_revision': rev_count,
    'items': items_output
}

outpath = '_work_barmodels/audit_r7/r7_g100.json'
with open(outpath, 'w', encoding='utf-8') as f:
    json.dump(output, f, indent=2, ensure_ascii=False)

print(f'Written: {good_count} GOOD, {rev_count} NEEDS_REVISION, {len(items_output)} total')
print(f'GOOD IDs: {[i["id"] for i in items_output if i["verdict"]==GOOD]}')
print(f'NEEDS_REVISION IDs: {[i["id"] for i in items_output if i["verdict"]==REV]}')
