1010# 챌린지 설정 (매달 투표 결과로 정해진 유형과 목표 문제 수)
1111CHALLENGE_TYPES = {
1212 "그래프" : 5 ,
13- "구현 " : 5
13+ "DP " : 5
1414}
1515
1616def initialize_user ():
@@ -20,11 +20,10 @@ def initialize_user():
2020 "achieved" : {ctype : False for ctype in CHALLENGE_TYPES .keys ()}
2121 }
2222
23- def get_month_from_date (date_str ):
24- # ISO 형식의 날짜 문자열에서 YYYY-MM 형식의 월 문자열 추출
25- return datetime .fromisoformat (date_str .replace ('Z' , '+00:00' )).strftime ('%Y-%m' )
26-
2723def main ():
24+ # 현재 달 문자열
25+ current_month = datetime .now ().strftime ("%Y-%m" )
26+
2827 # 1. 기존 스코어보드 로드 (없으면 빈 dict로 초기화)
2928 print ("[Step 1] Loading scoreboard file..." )
3029 if os .path .exists (SCOREBOARD_FILE ):
@@ -42,17 +41,19 @@ def main():
4241 print ("[Step 2.1] Verifying scoreboard structure..." )
4342 if "users" not in scoreboard or "month" not in scoreboard :
4443 scoreboard = {
45- "month" : None , # PR 데이터에서 첫 번째 항목의 월을 사용할 것이므로 None으로 초기화
44+ "month" : current_month ,
4645 "users" : scoreboard # 기존 scoreboard의 내용(사용자 데이터)이 있다면 여기에 넣음
4746 }
4847 else :
4948 # 2-2. month 값이 다르면 현재 달로 덮어쓰기
5049 print ("[Step 2.2] Checking month field..." )
51- if scoreboard ["month" ] is not None : # month가 None이 아닌 경우에만 아카이브
52- print (f"[Step 2.2] Archiving previous month data: { scoreboard ['month' ]} " )
50+ if scoreboard ["month" ] != current_month :
51+ print (f"[Step 2.2] Month mismatch detected (previous: { scoreboard ['month' ]} , current: { current_month } ); archiving..." )
52+
5353 archive_current_month ()
5454 print ("[Step 2.2] Archived previous month data to HISTORY.md" )
55- scoreboard ["month" ] = None # PR 데이터에서 첫 번째 항목의 월을 사용할 것이므로 None으로 초기화
55+
56+ scoreboard ["month" ] = current_month
5657 scoreboard ["users" ] = {} # 매달 유저값도 초기화
5758 print (f"[Step 2.2] Reset scoreboard for new month: { scoreboard !r} " )
5859
@@ -75,22 +76,10 @@ def main():
7576 username = entry ["username" ]
7677 algorithm = entry ["algorithm" ]
7778 problem_id = entry ["problem_id" ]
78- created_at = entry ["created_at" ]
7979
8080 if not username or not algorithm or problem_id is None :
8181 continue
8282
83- # PR 생성 날짜에서 월 추출
84- entry_month = get_month_from_date (created_at )
85-
86- # scoreboard의 month가 None이면 첫 번째 항목의 월로 설정
87- if scoreboard ["month" ] is None :
88- scoreboard ["month" ] = entry_month
89- # 월이 다르면 해당 항목은 건너뛰기
90- elif scoreboard ["month" ] != entry_month :
91- print (f"[Step 4] Skipping entry from different month: { entry_month } " )
92- continue
93-
9483 print (f"[Step 4] Entry details -> user: { username } , algorithm: { algorithm } , problem_id: { problem_id } " )
9584 print (f"[Step 4] Current users state: { users !r} " )
9685 # 챌린지 유형에 포함되어 있는지 확인 (예: "그래프", "DP")
0 commit comments