# -*- coding: utf-8 -*-
import sys, io, openpyxl, collections
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
wb=openpyxl.load_workbook(r'3.한국의약품안전관리원/한국의약품안전관리원.xlsx'); ws=wb.active
last=2
for r in range(3,ws.max_row+1):
    if ws.cell(r,2).value is None and all(ws.cell(r,c).value in(None,'') for c in range(4,12)): continue
    last=r
Lc=collections.Counter(); Oc=collections.Counter(); Nc=collections.Counter()
kogl=0
for r in range(3,last+1):
    L=ws.cell(r,12).value; O=ws.cell(r,15).value; N=ws.cell(r,14).value
    Lc[L]+=1
    if O and O!='미부착': kogl+=1; Oc[O]+=1
    Nc[N]+=1
print('lastrow',last,'(data rows', last-2,')')
print('L:',dict(Lc))
print('KOGL부착:',kogl,'O유형분포:',dict(Oc))
print('N:',dict(Nc))
print('--- KOGL rows (O,P,Q) ---')
for r in range(3,last+1):
    O=ws.cell(r,15).value
    if O and O!='미부착':
        leaf=ws.cell(r,6).value or ws.cell(r,5).value or ws.cell(r,4).value
        print(r,leaf,'| L=',ws.cell(r,12).value,'O=',O,'P=',ws.cell(r,16).value,'Q=',ws.cell(r,17).value)
