File size: 12,289 Bytes
ef15c6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
"""
μƒν™œκΈ°λ‘λΆ€ μ„Ήμ…˜ ν…œν”Œλ¦Ώ μ •μ˜ v2.0

νŒ¨ν„΄ 감지가 μ•„λ‹Œ 'κ³ μ • 타이틀 λ§€μΉ­' 방식
- 타이틀 λ³€ν˜•μ„ λͺ…μ‹œμ μœΌλ‘œ μ •μ˜
- λ¬Έμ„œ 버전(ꡬ버전 8μ„Ήμ…˜ / 신버전 9μ„Ήμ…˜) μžλ™ 감지
- λŒ€μž…μ „ν˜•μš©(번호 μ—†μŒ) 지원
"""

from dataclasses import dataclass, field
from typing import Optional
from enum import Enum


class DocVersion(Enum):
    """λ¬Έμ„œ 버전"""
    V1_8_SECTIONS = "v1"      # ꡬ버전 (8μ„Ήμ…˜, ~2024)
    V2_9_SECTIONS = "v2"      # 신버전 (9μ„Ήμ…˜, 2024~ 학ꡐ폭λ ₯ μΆ”κ°€)
    COLLEGE_ADMISSION = "ca"  # λŒ€μž…μ „ν˜•μš© (번호 μ—†μŒ)


@dataclass
class SectionDef:
    """μ„Ήμ…˜ μ •μ˜"""
    id: str                           # 고유 ID
    titles: list[str]                 # λ§€μΉ­ν•  타이틀 λͺ©λ‘ (곡백 λ¬΄μ‹œ λ§€μΉ­)
    order_v1: Optional[int] = None    # κ΅¬λ²„μ „μ—μ„œμ˜ μˆœμ„œ (번호)
    order_v2: Optional[int] = None    # μ‹ λ²„μ „μ—μ„œμ˜ μˆœμ„œ (번호)
    required: bool = True             # ν•„μˆ˜ μ„Ήμ…˜ μ—¬λΆ€


# ═══════════════════════════════════════════════════════════════════════════════
# μ„Ήμ…˜ 타이틀 μ •μ˜
# ═══════════════════════════════════════════════════════════════════════════════

SECTIONS = [
    SectionDef(
        id="인적학적",
        titles=["인적·학적사항", "인적 학적사항", "인적학적사항", "인적사항"],
        order_v1=1, order_v2=1,
    ),
    SectionDef(
        id="좜결",
        titles=["μΆœκ²°μƒν™©", "좜 κ²° 상 ν™©"],
        order_v1=2, order_v2=2,
    ),
    SectionDef(
        id="μˆ˜μƒ",
        titles=["μˆ˜μƒκ²½λ ₯", "수 상 κ²½ λ ₯"],
        order_v1=3, order_v2=3,
    ),
    SectionDef(
        id="자격증",
        titles=["자격증 및 인증 취득상황", "자격증", "자격증 및 인증"],
        order_v1=4, order_v2=4,
        required=False,
    ),
    SectionDef(
        id="학ꡐ폭λ ₯",
        titles=["학ꡐ폭λ ₯ μ‘°μΉ˜μƒν™© 관리", "학ꡐ폭λ ₯ μ‘°μΉ˜μƒν™©"],
        order_v1=None, order_v2=5,  # μ‹ λ²„μ „μ—λ§Œ 쑴재
        required=False,
    ),
    SectionDef(
        id="창체",
        titles=["창의적 μ²΄ν—˜ν™œλ™μƒν™©", "μ°½μ˜μ μ²΄ν—˜ν™œλ™μƒν™©", "창의적 μ²΄ν—˜ν™œλ™"],
        order_v1=5, order_v2=6,
    ),
    SectionDef(
        id="ꡐ과",
        titles=["κ΅κ³Όν•™μŠ΅λ°œλ‹¬μƒν™©", "κ΅κ³Όν•™μŠ΅ λ°œλ‹¬μƒν™©", "ꡐ과 ν•™μŠ΅ λ°œλ‹¬ 상황"],
        order_v1=6, order_v2=7,
    ),
    SectionDef(
        id="λ…μ„œ",
        titles=["λ…μ„œν™œλ™μƒν™©", "λ…μ„œ ν™œλ™ 상황", "λ…μ„œν™œλ™"],
        order_v1=7, order_v2=8,
    ),
    SectionDef(
        id="행동",
        titles=["ν–‰λ™νŠΉμ„± 및 μ’…ν•©μ˜κ²¬", "ν–‰λ™νŠΉμ„±λ°μ’…ν•©μ˜κ²¬", "행동 νŠΉμ„± 및 μ’…ν•© 의견"],
        order_v1=8, order_v2=9,
    ),
]

# λΉ λ₯Έ 쑰회용 λ”•μ…”λ„ˆλ¦¬
SECTION_BY_ID = {s.id: s for s in SECTIONS}


# ═══════════════════════════════════════════════════════════════════════════════
# 창의적 μ²΄ν—˜ν™œλ™ λ‚΄λΆ€ ꡬ쑰
# ═══════════════════════════════════════════════════════════════════════════════

@dataclass
class CreativeActivityArea:
    """창체 μ˜μ—­ μ •μ˜"""
    id: str
    titles: list[str]
    has_hours: bool = True        # μ‹œκ°„ ν•„λ“œ 있음
    has_details: bool = True      # νŠΉκΈ°μ‚¬ν•­ 있음
    extra_fields: list[str] = field(default_factory=list)  # μΆ”κ°€ ν•„λ“œ


CREATIVE_ACTIVITY_AREAS = [
    CreativeActivityArea(
        id="자율",
        titles=["μžμœ¨ν™œλ™", "자율 ν™œλ™"],
    ),
    CreativeActivityArea(
        id="동아리",
        titles=["λ™μ•„λ¦¬ν™œλ™", "동아리 ν™œλ™"],
        extra_fields=["club_name"],  # (동아리λͺ…)(μ‹œκ°„) ν˜•μ‹
    ),
    CreativeActivityArea(
        id="μ§„λ‘œ",
        titles=["μ§„λ‘œν™œλ™", "μ§„λ‘œ ν™œλ™"],
        extra_fields=["desired_field"],  # 희망뢄야 별도 ν–‰
    ),
    CreativeActivityArea(
        id="봉사",
        titles=["λ΄‰μ‚¬ν™œλ™", "봉사 ν™œλ™", "λ΄‰μ‚¬ν™œλ™μ‹€μ "],
        has_details=False,  # ν…Œμ΄λΈ” ν˜•μ‹
        extra_fields=["date", "location", "activity", "cumulative_hours"],
    ),
]

CREATIVE_AREA_BY_ID = {a.id: a for a in CREATIVE_ACTIVITY_AREAS}


# ═══════════════════════════════════════════════════════════════════════════════
# κ΅κ³Όν•™μŠ΅λ°œλ‹¬μƒν™© λ‚΄λΆ€ ꡬ쑰
# ═══════════════════════════════════════════════════════════════════════════════

@dataclass
class AcademicCategory:
    """ꡐ과 μΉ΄ν…Œκ³ λ¦¬ μ •μ˜"""
    id: str
    titles: list[str]               # λ§€μΉ­ν•  마컀 λͺ©λ‘ (μΌλ°˜μ€ 빈 λͺ©λ‘ = κΈ°λ³Έκ°’)
    marker: Optional[str]           # λ¬Έμ„œ λ‚΄ μ‹€μ œ 마컀 (μΌλ°˜μ€ None)
    columns: list[str]              # ν…Œμ΄λΈ” 컬럼 ꡬ쑰
    has_rank: bool = True           # 석차등급 있음
    has_distribution: bool = False  # 성취도별 뢄포 있음
    has_score: bool = True          # μ›μ μˆ˜/평균/ν‘œμ€€νŽΈμ°¨ 있음


# μΉ΄ν…Œκ³ λ¦¬λ³„ ν…Œμ΄λΈ” 컬럼 μ •μ˜
# - 일반: ν•™κΈ°|ꡐ과|κ³Όλͺ©|λ‹¨μœ„μˆ˜|μ›μ μˆ˜/평균(ν‘œμ€€νŽΈμ°¨)|성취도(μˆ˜κ°•μž)|석차등급
# - μ§„λ‘œμ„ νƒ: ν•™κΈ°|ꡐ과|κ³Όλͺ©|λ‹¨μœ„μˆ˜|μ›μ μˆ˜/평균(ν‘œμ€€νŽΈμ°¨)|성취도(μˆ˜κ°•μž)|성취도별뢄포
# - 체윑예술: ν•™κΈ°|ꡐ과|κ³Όλͺ©|λ‹¨μœ„μˆ˜|성취도
ACADEMIC_CATEGORIES = [
    AcademicCategory(
        id="일반",
        titles=[],  # κΈ°λ³Έκ°’ - λͺ…μ‹œμ  마컀 μ—†μŒ
        marker=None,
        columns=["ν•™κΈ°", "ꡐ과", "κ³Όλͺ©", "λ‹¨μœ„μˆ˜", "μ›μ μˆ˜/평균(ν‘œμ€€νŽΈμ°¨)", "성취도(μˆ˜κ°•μž)", "석차등급"],
        has_rank=True,
        has_distribution=False,
        has_score=True,
    ),
    AcademicCategory(
        id="μ§„λ‘œμ„ νƒ",
        titles=["<μ§„λ‘œ 선택 κ³Όλͺ©>", "μ§„λ‘œ 선택 κ³Όλͺ©", "μ§„λ‘œμ„ νƒ", "μ§„λ‘œ 선택"],
        marker="<μ§„λ‘œ 선택 κ³Όλͺ©>",
        columns=["ν•™κΈ°", "ꡐ과", "κ³Όλͺ©", "λ‹¨μœ„μˆ˜", "μ›μ μˆ˜/평균(ν‘œμ€€νŽΈμ°¨)", "성취도(μˆ˜κ°•μž)", "성취도별뢄포"],
        has_rank=False,
        has_distribution=True,
        has_score=True,
    ),
    AcademicCategory(
        id="체윑예술",
        titles=["<μ²΄μœ‘γ†μ˜ˆμˆ >", "<체윑·예술>", "체윑·예술", "μ²΄μœ‘γ†μ˜ˆμˆ ", "체윑예술", "체윑·예술(ꡐ양)"],
        marker="<μ²΄μœ‘γ†μ˜ˆμˆ >",
        columns=["ν•™κΈ°", "ꡐ과", "κ³Όλͺ©", "λ‹¨μœ„μˆ˜", "성취도"],
        has_rank=False,
        has_distribution=False,
        has_score=False,  # μ›μ μˆ˜/평균 μ—†μŒ
    ),
]

ACADEMIC_CATEGORY_BY_ID = {c.id: c for c in ACADEMIC_CATEGORIES}


@dataclass
class SubjectRemarkPattern:
    """μ„ΈλΆ€λŠ₯λ ₯νŠΉκΈ°μ‚¬ν•­ νŒ¨ν„΄"""
    # κ³Όλͺ© μ„ΈνŠΉ: "κ³Όλͺ©λͺ…: λ‚΄μš©" λ˜λŠ” "(ν•™κΈ°)κ³Όλͺ©λͺ…: λ‚΄μš©"
    subject_prefix_pattern: str = r"^(?:\(([12])ν•™κΈ°\))?([κ°€-힣A-Za-zβ… -β…’\sΒ·]+)\s*[::]"

    # 개인 μ„ΈνŠΉ: κ³Όλͺ©λͺ… 없이 μ‹œμž‘ (λ§ˆμ§€λ§‰μ— μœ„μΉ˜)
    personal_remark_min_length: int = 50  # μ΅œμ†Œ 50자 이상


# ═══════════════════════════════════════════════════════════════════════════════
# μΆœκ²°μƒν™© ν…Œμ΄λΈ” ꡬ쑰
# ═══════════════════════════════════════════════════════════════════════════════

ATTENDANCE_COLUMNS = {
    "primary": ["ν•™λ…„", "μˆ˜μ—…μΌμˆ˜"],
    "absence": {
        "header": "κ²°μ„μΌμˆ˜",
        "sub": ["μ§ˆλ³‘", "미인정", "기타"],
    },
    "late": {
        "header": "지각",
        "sub": ["μ§ˆλ³‘", "미인정", "기타"],
    },
    "early_leave": {
        "header": "쑰퇴",
        "sub": ["μ§ˆλ³‘", "미인정", "기타"],
    },
    "class_absence": {
        "header": "κ²°κ³Ό",  # κ²°κ³Ό = μˆ˜μ—…κ²°μ†
        "sub": ["μ§ˆλ³‘", "미인정", "기타"],
    },
    "notes": "νŠΉκΈ°μ‚¬ν•­",
}


# ═══════════════════════════════════════════════════════════════════════════════
# μˆ˜μƒκ²½λ ₯ ν…Œμ΄λΈ” ꡬ쑰
# ═══════════════════════════════════════════════════════════════════════════════

AWARDS_COLUMNS = [
    "ν•™λ…„",
    "ν•™κΈ°",       # (ν•™κΈ°) λ˜λŠ” 별도 컬럼
    "μˆ˜μƒλͺ…",
    "λ“±κΈ‰",       # λ“±κΈ‰(μœ„)
    "μˆ˜μƒμ—°μ›”μΌ",
    "μˆ˜μ—¬κΈ°κ΄€",
    "μ°Έκ°€λŒ€μƒ",   # (참가인원)
]


# ═══════════════════════════════════════════════════════════════════════════════
# λ…μ„œν™œλ™μƒν™© ꡬ쑰
# ═══════════════════════════════════════════════════════════════════════════════

@dataclass
class ReadingFormat:
    """λ…μ„œν™œλ™ ν˜•μ‹"""
    # ν•™λ…„λ³„λ‘œ ꡬ뢄
    grade_based: bool = True
    # κ³Όλͺ©λ³„ ꡬ뢄 (μžˆλŠ” 경우)
    subject_based: bool = False
    # λ„μ„œ ν˜•μ‹: "제λͺ©(μ €μž)" λ˜λŠ” "제λͺ©"
    book_pattern: str = r"([^(]+)(?:\(([^)]+)\))?"


# ═══════════════════════════════════════════════════════════════════════════════
# 헬퍼 ν•¨μˆ˜
# ═══════════════════════════════════════════════════════════════════════════════

def normalize_text(text: str) -> str:
    """곡백 및 특수문자 μ •κ·œν™” (맀칭용)"""
    import re
    # 곡백 제거
    text = re.sub(r'\s+', '', text)
    # 특수 점(Β·, ㆍ) 톡일
    text = text.replace('ㆍ', 'Β·')
    return text


def match_title(text: str, titles: list[str]) -> bool:
    """타이틀 λ§€μΉ­ (곡백 λ¬΄μ‹œ)"""
    normalized = normalize_text(text)
    for title in titles:
        if normalize_text(title) in normalized:
            return True
    return False


def detect_doc_version(full_text: str) -> DocVersion:
    """λ¬Έμ„œ 버전 감지"""
    import re

    # 번호 없이 μ„Ήμ…˜ μ‹œμž‘ν•˜λ©΄ λŒ€μž…μ „ν˜•μš©
    if re.search(r'^인적[Β·\s]*학적', full_text, re.MULTILINE):
        if not re.search(r'^\d+\.\s*인적', full_text, re.MULTILINE):
            return DocVersion.COLLEGE_ADMISSION

    # 학ꡐ폭λ ₯ μ„Ήμ…˜ 있으면 신버전
    if match_title(full_text, SECTION_BY_ID["학ꡐ폭λ ₯"].titles):
        return DocVersion.V2_9_SECTIONS

    return DocVersion.V1_8_SECTIONS


def get_section_order(section_id: str, version: DocVersion) -> Optional[int]:
    """버전에 λ”°λ₯Έ μ„Ήμ…˜ μˆœμ„œ λ°˜ν™˜"""
    section = SECTION_BY_ID.get(section_id)
    if not section:
        return None

    if version == DocVersion.V2_9_SECTIONS:
        return section.order_v2
    else:
        return section.order_v1