@@ -20,10 +20,11 @@ def initialize_user():
2020 "achieved" : {ctype : False for ctype in CHALLENGE_TYPES .keys ()}
2121 }
2222
23- def main ( ):
24- # 현재 달 문자열
25- current_month = datetime .now () .strftime (" %Y-%m" )
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' )
2626
27+ def main ():
2728 # 1. 기존 스코어보드 로드 (없으면 빈 dict로 초기화)
2829 print ("[Step 1] Loading scoreboard file..." )
2930 if os .path .exists (SCOREBOARD_FILE ):
@@ -41,7 +42,7 @@ def main():
4142 print ("[Step 2.1] Verifying scoreboard structure..." )
4243 if "users" not in scoreboard or "month" not in scoreboard :
4344 scoreboard = {
44- "month" : current_month ,
45+ "month" : None , # PR 데이터에서 첫 번째 항목의 월을 사용할 것이므로 None으로 초기화
4546 "users" : scoreboard # 기존 scoreboard의 내용(사용자 데이터)이 있다면 여기에 넣음
4647 }
4748 else :
@@ -53,7 +54,7 @@ def main():
5354 archive_current_month ()
5455 print ("[Step 2.2] Archived previous month data to HISTORY.md" )
5556
56- scoreboard ["month" ] = current_month
57+ scoreboard ["month" ] = None # PR 데이터에서 첫 번째 항목의 월을 사용할 것이므로 None으로 초기화
5758 scoreboard ["users" ] = {} # 매달 유저값도 초기화
5859 print (f"[Step 2.2] Reset scoreboard for new month: { scoreboard !r} " )
5960
@@ -76,10 +77,22 @@ def main():
7677 username = entry ["username" ]
7778 algorithm = entry ["algorithm" ]
7879 problem_id = entry ["problem_id" ]
80+ created_at = entry ["created_at" ]
7981
8082 if not username or not algorithm or problem_id is None :
8183 continue
8284
85+ # PR 생성 날짜에서 월 추출
86+ entry_month = get_month_from_date (created_at )
87+
88+ # scoreboard의 month가 None이면 첫 번째 항목의 월로 설정
89+ if scoreboard ["month" ] is None :
90+ scoreboard ["month" ] = entry_month
91+ # 월이 다르면 해당 항목은 건너뛰기
92+ elif scoreboard ["month" ] != entry_month :
93+ print (f"[Step 4] Skipping entry from different month: { entry_month } " )
94+ continue
95+
8396 print (f"[Step 4] Entry details -> user: { username } , algorithm: { algorithm } , problem_id: { problem_id } " )
8497 print (f"[Step 4] Current users state: { users !r} " )
8598 # 챌린지 유형에 포함되어 있는지 확인 (예: "그래프", "DP")
0 commit comments