DB_JOB/작업파일/_통계.py
2026-06-26 09:47:44 +09:00

67 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
"""검수완료·미제출 통계 + 공공기관3 현황판 전체표 (날짜별·프리랜서별). 읽기전용.
사용: python _통계.py
대상: 공공기관3_작업현황.xlsx
"""
import sys, os
from collections import defaultdict
import openpyxl
sys.stdout.reconfigure(encoding="utf-8")
BASE = os.path.dirname(os.path.abspath(__file__))
# 광역·공공기관2 현황판은 정리됨 → 공공기관3 현황판 기준(2026-06-23)
XLSX = os.path.join(BASE, "공공기관3", "공공기관3_작업현황.xlsx")
wb = openpyxl.load_workbook(XLSX, data_only=True)
ws = wb["현황"] if "현황" in wb.sheetnames else wb.active
hdr = [c.value for c in ws[1]]
gi = lambda n: hdr.index(n)
allrows = [] # (번호, 기관, 검수값, 행수, 담당자, 제출완료, 검수완료일)
for r in ws.iter_rows(min_row=2, values_only=True):
if not r[gi("기관")]:
continue
allrows.append((r[gi("번호")], r[gi("기관")], r[gi("검수")], r[gi("행수")] or 0,
r[gi("담당자")], r[gi("제출완료")], str(r[gi("검수완료일")] or "")[:10]))
# ── 표1: 검수완료 · 미제출 (날짜별·프리랜서별) ──
done_unsub = [(d, f, name, n) for (no, name, insp, n, f, sub, d) in allrows
if insp == "완료" and sub != "완료"]
done_unsub.sort(key=lambda x: (x[0], str(x[1])))
dates = sorted({d for d, *_ in done_unsub})
bydate = defaultdict(lambda: defaultdict(list))
byfree = defaultdict(lambda: [0, 0])
for d, f, name, n in done_unsub:
bydate[d][f].append((name, n))
byfree[f][0] += 1
byfree[f][1] += n
cell = lambda items: ", ".join(f"{nm} {n}" for nm, n in items) if items else ""
print("## 검수완료 · 미제출 통계\n")
print("### 📅 날짜별 · 프리랜서별\n")
print("| 검수일 | 프리랜서1 (충남) | 프리랜서2 (전북) | 일계 |")
print("|---|---|---|---|")
tot_cnt = tot_row = 0
for d in dates:
c1 = bydate[d].get("프리랜서1", [])
c2 = bydate[d].get("프리랜서2", [])
day_cnt = len(c1) + len(c2)
day_row = sum(n for _, n in c1) + sum(n for _, n in c2)
tot_cnt += day_cnt
tot_row += day_row
print(f"| {d} | {cell(c1)} | {cell(c2)} | {day_cnt}곳 · {day_row:,}행 |")
s1 = byfree.get("프리랜서1", [0, 0]); s2 = byfree.get("프리랜서2", [0, 0])
print(f"| **소계** | **{s1[0]}곳 · {s1[1]:,}행** | **{s2[0]}곳 · {s2[1]:,}행** | **{tot_cnt}곳 · {tot_row:,}행** |")
# ── 표2: 공공기관3 현황판 전체 (번호 1~끝, 검수/미검수) ──
n_done = sum(1 for x in allrows if x[2] == "완료")
n_todo = len(allrows) - n_done
sum_row = sum(x[3] for x in allrows)
print(f"\n## 공공기관3 현황판 (전체 {len(allrows)}곳 · 검수완료 {n_done} / 미검수 {n_todo})\n")
print("| 번호 | 기관 | 검수 | 행수 |")
print("|---|---|---|---|")
for no, name, insp, n, f, sub, d in allrows:
mark = "☑️ 검수완료" if insp == "완료" else "⬜ 미검수"
print(f"| {no} | {name} | {mark} | {n:,} |")
print(f"| **계** | **{len(allrows)}곳** | **완료 {n_done} · 미검수 {n_todo}** | **{sum_row:,}** |")