From 283e1d313bdf4ac1fbe8193d6f018a4cb49e8cf4 Mon Sep 17 00:00:00 2001 From: matin Date: Sun, 5 Oct 2025 15:39:15 +0200 Subject: removed unnecessary functions; selective imports --- calendar_gui.py | 10 ++++----- date_service.py | 38 -------------------------------- event_type_handler.py | 52 ++++++++------------------------------------ prediction_report_service.py | 3 ++- 4 files changed, 16 insertions(+), 87 deletions(-) diff --git a/calendar_gui.py b/calendar_gui.py index 5705e7a..1c9efe7 100644 --- a/calendar_gui.py +++ b/calendar_gui.py @@ -1,14 +1,12 @@ import sys from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, - QLabel, QLineEdit, QPushButton, QDateEdit, QTableWidget, + QLabel, QPushButton, QDateEdit, QTableWidget, QTableWidgetItem, QHeaderView, QDialog, QFormLayout, QComboBox, - QMessageBox, QSpinBox, QAction, QFileDialog, QMenuBar, QTextEdit, + QMessageBox, QSpinBox, QAction, QFileDialog, QTextEdit, QAbstractItemView, QToolButton) from PyQt5.QtWidgets import QStyle from PyQt5.QtCore import Qt, QDate, QLocale from PyQt5.QtGui import QFont, QFontDatabase -from datetime import datetime, timedelta -from dateutil.relativedelta import relativedelta from calendar_manager import CalendarManager from date_calculator import DateCalculator @@ -16,7 +14,7 @@ from prediction_controller import PredictionController from event_type_handler import EventTypeHandler from date_service import DateService from config import EventConfig -from prediction_report_service import PredictionReportService +# Note: PDF export dependency is imported lazily inside export_pdf to reduce startup size class EventDialog(QDialog): def __init__(self, entry=None, parent=None): @@ -662,6 +660,8 @@ class CalendarManagerGUI(QMainWindow): ) if not out_path: return + # Lazy import to avoid heavy PDF dependencies at startup + from prediction_report_service import PredictionReportService success = PredictionReportService.export_pdf( self.calendar_manager, self.prediction_controller, diff --git a/date_service.py b/date_service.py index 4a0706a..3c93546 100644 --- a/date_service.py +++ b/date_service.py @@ -32,30 +32,6 @@ class DateService: raise ValueError(f"Unable to parse date string: {date_string}") @staticmethod - def qdate_to_datetime(qdate): - """Convert QDate to datetime""" - if isinstance(qdate, QDate): - return datetime(qdate.year(), qdate.month(), qdate.day()) - return qdate - - @staticmethod - def datetime_to_qdate(dt): - """Convert datetime to QDate""" - if isinstance(dt, datetime): - return QDate(dt.year, dt.month, dt.day) - return dt - - @staticmethod - def validate_date_range(start_date, end_date): - """Validate that start_date is not after end_date""" - if isinstance(start_date, str): - start_date = DateService.parse_date_from_string(start_date) - if isinstance(end_date, str): - end_date = DateService.parse_date_from_string(end_date) - - return start_date <= end_date - - @staticmethod def calculate_days_between(start_date, end_date): """Calculate number of days between two dates""" if isinstance(start_date, str): @@ -89,17 +65,3 @@ class DateService: def get_current_date(): """Get current date as datetime""" return datetime.now() - - @staticmethod - def add_days_to_date(date, days): - """Add days to a date""" - if isinstance(date, str): - date = DateService.parse_date_from_string(date) - return date + timedelta(days=days) - - @staticmethod - def add_months_to_date(date, months): - """Add months to a date using relativedelta""" - if isinstance(date, str): - date = DateService.parse_date_from_string(date) - return date + relativedelta(months=months) diff --git a/event_type_handler.py b/event_type_handler.py index ef11f91..ee2b6b7 100644 --- a/event_type_handler.py +++ b/event_type_handler.py @@ -1,6 +1,5 @@ # event_type_handler.py from datetime import datetime -from dateutil.relativedelta import relativedelta from typing import List, Dict, Tuple from calendar_entry import CalendarEntry from config import EventConfig @@ -43,39 +42,12 @@ class EventTypeHandler: @staticmethod def get_event_type_display_name(event_type: str) -> str: """Get display name for event type""" - display_names = { - "EZ 100%": "Erziehungszeit 100%", - "EZ 50%": "Erziehungszeit 50%", - "EZ pauschal": "Erziehungszeit pauschal", - "Sonstige": "Sonstige Ausfallzeiten" - } - return display_names.get(event_type, event_type) + return event_type @staticmethod def calculate_accounted_time(entry: CalendarEntry) -> str: - """Calculate the accounted time for an entry based on its type and corrected dates""" - if not entry.corrected_start_date or not entry.corrected_end_date: - return "" - - start_dt = entry.corrected_start_date - end_dt = entry.corrected_end_date - - if end_dt < start_dt: - return "" - - if entry.keyword == "Sonstige": - # For "Sonstige", show days - delta_days = DateService.calculate_days_between(start_dt, end_dt) - return f"{delta_days} Tage" - else: - # For EZ types, show months - total_months = DateService.calculate_months_between(start_dt, end_dt) - - if entry.keyword == "EZ 50%": - # Half-time projects count as half months - total_months = (total_months + 1) // 2 # Round up - - return f"{total_months} Monate" + """Deprecated: accounted time is computed and stored elsewhere.""" + return "" @staticmethod def should_hide_end_date_input(event_type: str) -> bool: @@ -84,31 +56,25 @@ class EventTypeHandler: @staticmethod def get_event_type_description(event_type: str) -> str: - """Get description for event type""" - descriptions = { - "EZ 100%": "Vollzeit Erziehungszeit - vollständige Unterbrechung der Arbeit", - "EZ 50%": "Teilzeit Erziehungszeit - 50% Arbeitszeit", - "EZ pauschal": "Pauschale Erziehungszeit - automatisch 2 Jahre", - "Sonstige": "Andere Ausfallzeiten wie Krankheit, Weiterbildung, etc." - } - return descriptions.get(event_type, "") + """Deprecated: display descriptions removed for lean runtime.""" + return "" @staticmethod def get_processing_order() -> List[str]: - """Get the order in which event types should be processed""" + """Deprecated: processing order is defined inline where needed.""" return ["EZ 100%", "EZ 50%", "EZ pauschal", "Sonstige"] @staticmethod def is_full_time_event(event_type: str) -> bool: - """Check if event type represents full-time absence""" + """Deprecated helper kept for compatibility.""" return event_type in ["EZ 100%", "EZ pauschal"] @staticmethod def is_part_time_event(event_type: str) -> bool: - """Check if event type represents part-time absence""" + """Deprecated helper kept for compatibility.""" return event_type == "EZ 50%" @staticmethod def is_other_event(event_type: str) -> bool: - """Check if event type represents other absence""" + """Deprecated helper kept for compatibility.""" return event_type == "Sonstige" diff --git a/prediction_report_service.py b/prediction_report_service.py index 4b2e521..7017ac6 100644 --- a/prediction_report_service.py +++ b/prediction_report_service.py @@ -2,7 +2,7 @@ from datetime import datetime from typing import List from io import BytesIO -from xhtml2pdf import pisa +# Import xhtml2pdf lazily in export to avoid heavy import at module load from calendar_manager import CalendarManager from prediction_controller import PredictionController @@ -18,6 +18,7 @@ class PredictionReportService: out_path: str, dateformat: str = "dd.MM.yyyy") -> bool: try: + from xhtml2pdf import pisa # Gather data launch_dt = prediction_controller.get_launch_date() duration = prediction_controller.get_duration() -- cgit v1.1