핵심 기능: - 단축근무·표준·반일 등 다양한 근무 패턴 (5개 프리셋 + 사용자 정의) - Windows 이벤트 뷰어 자동 출퇴근 감지 - 30분 단위 연장근무 적립/사용 시스템 - 1.0/0.5/0.25일 연차·반차·반반차 - 자동 점심·저녁·외출·자동 백업·화면 잠금 자동 외출 - 한국 공휴일 자동 등록 (음력 포함, holidays 패키지) - matplotlib 차트 기반 주간/월간/패턴 통계 - 미니 위젯 + 시스템 트레이 통합 - 한국어/English i18n - 자가 업데이트 (updater.exe + Gitea Releases) 아키텍처: - core/ (db, time_calculator, notifier, i18n, version, settings_keys) - ui/ (main_window + 9 dialogs + 3 controllers) - utils/ (backup, lock_detector, debug_log, updater_client, time_format) - tests/ (66 pytest 단위) + 통합/i18n GUI 검증 CI/CD: - .gitea/workflows/ci.yml: push 시 pytest + 통합 테스트 - .gitea/workflows/release.yml: v* 태그 push 시 두 .exe 자동 빌드 + Releases 첨부 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
자동 점심시간 적용 컨트롤러.
|
||||
|
||||
조건: auto_lunch=true, 출근 후 4시간 이상, 점심 미적용, 오늘 미적용.
|
||||
주말/공휴일은 스킵. 1Hz hot path에서 호출되므로 캐시 사용.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
from datetime import datetime
|
||||
|
||||
from core.settings_keys import AUTO_LUNCH
|
||||
|
||||
|
||||
class AutoLunchManager:
|
||||
"""update_display() 1Hz tick에서 호출."""
|
||||
|
||||
def __init__(self, window):
|
||||
self.window = window
|
||||
self.db = window.db
|
||||
self._enabled_cache = None # None=미로딩, True/False=캐시값
|
||||
self._non_working_cache = None
|
||||
self._non_working_date = None
|
||||
|
||||
def invalidate(self) -> None:
|
||||
"""설정 변경 시 캐시 무효화 (reload_settings에서 호출)."""
|
||||
self._enabled_cache = None
|
||||
|
||||
def maybe_apply(self, now: datetime) -> None:
|
||||
w = self.window
|
||||
if w.auto_lunch_applied_today or w.lunch_break_enabled:
|
||||
return
|
||||
|
||||
if self._enabled_cache is None:
|
||||
self._enabled_cache = (
|
||||
self.db.get_setting(AUTO_LUNCH, 'false').lower() == 'true'
|
||||
)
|
||||
if not self._enabled_cache:
|
||||
return
|
||||
|
||||
today = now.date()
|
||||
if self._non_working_date != today:
|
||||
self._non_working_cache = w.time_calc.is_non_working_day(now, self.db)
|
||||
self._non_working_date = today
|
||||
if self._non_working_cache:
|
||||
return
|
||||
|
||||
elapsed = now - w.clock_in_time
|
||||
if elapsed.total_seconds() < 4 * 3600:
|
||||
return
|
||||
|
||||
w.auto_lunch_applied_today = True
|
||||
w.lunch_break_enabled = True
|
||||
w.lunch_button.setChecked(True)
|
||||
w.update_lunch_status()
|
||||
if w.is_clocked_in:
|
||||
self.db.update_lunch_break(today.isoformat(), True)
|
||||
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
화면 잠금 감지 컨트롤러.
|
||||
|
||||
- AUTO_BREAK_ON_LOCK: 출근 후 잠금→외출, 해제→복귀
|
||||
- CLOCK_IN_ON_UNLOCK: 미출근 상태에서 잠금 해제 시 출근 자동 기록
|
||||
"""
|
||||
from __future__ import annotations
|
||||
from datetime import datetime
|
||||
|
||||
from core.settings_keys import AUTO_BREAK_ON_LOCK, CLOCK_IN_ON_UNLOCK
|
||||
|
||||
|
||||
class LockMonitor:
|
||||
"""MainWindow에서 5초마다 호출되는 잠금 상태 감시자."""
|
||||
|
||||
def __init__(self, window):
|
||||
self.window = window
|
||||
self.db = window.db
|
||||
self.last_locked: bool = False
|
||||
|
||||
def tick(self) -> None:
|
||||
try:
|
||||
from utils.lock_detector import is_screen_locked
|
||||
locked = is_screen_locked()
|
||||
except Exception:
|
||||
return
|
||||
|
||||
was_locked = self.last_locked
|
||||
self.last_locked = locked
|
||||
|
||||
# 출근 후 자동 외출/복귀
|
||||
if (self.db.get_setting(AUTO_BREAK_ON_LOCK, 'false').lower() == 'true'
|
||||
and self.window.is_clocked_in):
|
||||
if locked and not was_locked and not self.window.is_on_break:
|
||||
self.window.break_out(silent=True)
|
||||
elif not locked and was_locked and self.window.is_on_break:
|
||||
self.window.break_in(silent=True)
|
||||
|
||||
# 미출근 상태에서 잠금 해제 시 출근
|
||||
if (not locked and was_locked
|
||||
and not self.window.is_clocked_in
|
||||
and self.db.get_setting(CLOCK_IN_ON_UNLOCK, 'false').lower() == 'true'):
|
||||
now = datetime.now()
|
||||
today_record = self.db.get_today_record()
|
||||
if not today_record or not today_record.get('clock_in'):
|
||||
self._auto_clock_in_at(now)
|
||||
|
||||
def _auto_clock_in_at(self, when: datetime) -> None:
|
||||
w = self.window
|
||||
w.clock_in_time = when
|
||||
w.is_clocked_in = True
|
||||
w.midnight_rollover_handled = False
|
||||
w.auto_lunch_applied_today = False
|
||||
|
||||
today = when.date().isoformat()
|
||||
clock_in_str = when.strftime("%H:%M:%S")
|
||||
existing = self.db.get_today_record()
|
||||
if existing:
|
||||
conn = self.db.get_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"UPDATE work_records SET clock_in = ?, is_manual = 0 WHERE date = ?",
|
||||
(clock_in_str, today),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
else:
|
||||
self.db.add_work_record(today, clock_in_str)
|
||||
w.update_display()
|
||||
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
알림 오케스트레이션.
|
||||
|
||||
5분 가드로 건강/주간/누적 임계 알림을 throttle.
|
||||
notifier.py의 6개 알림 메서드를 적절한 시점에 호출.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class NotificationOrchestrator:
|
||||
"""update_display() 1Hz tick에서 호출."""
|
||||
|
||||
def __init__(self, window):
|
||||
self.window = window
|
||||
self.db = window.db
|
||||
self.notifier = window.notifier
|
||||
self._last_5min_bucket: int | None = None # now.minute (5의 배수일 때만)
|
||||
|
||||
def tick(self, now: datetime, expected_clock_out: datetime, remaining_seconds: float) -> None:
|
||||
n = self.notifier
|
||||
# 1초마다 체크: 30분 전, 점심 미등록, 연장 적립
|
||||
n.check_clock_out_soon(expected_clock_out, now)
|
||||
n.check_lunch_reminder(self.window.clock_in_time,
|
||||
self.window.lunch_break_enabled, now)
|
||||
if remaining_seconds < 0:
|
||||
n.check_overtime_earning(abs(int(remaining_seconds / 60)))
|
||||
|
||||
# 5분 간격 throttle: 건강/주간/누적
|
||||
if now.minute % 5 == 0 and self._last_5min_bucket != now.minute:
|
||||
self._last_5min_bucket = now.minute
|
||||
consecutive = self.db.get_consecutive_overtime_days()
|
||||
if consecutive >= 3:
|
||||
n.notify_health_warning(consecutive)
|
||||
weekly_hours = self.db.get_weekly_stats().get('total_hours', 0)
|
||||
if weekly_hours > 52:
|
||||
n.notify_weekly_hours(weekly_hours)
|
||||
balance_minutes = self.db.get_total_overtime_balance()
|
||||
if balance_minutes >= 1200:
|
||||
n.notify_overtime_threshold(balance_minutes / 60.0)
|
||||
Reference in New Issue
Block a user