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
|
# test.py
from date_calculator import DateCalculator
from calendar_manager import CalendarManager
from prediction_controller import PredictionController
from event_type_handler import EventTypeHandler
from config import EventConfig
def test_calculate_prediction():
"""Test the refactored prediction calculation system"""
print("Testing refactored prediction calculation system...")
# Input event dates as strings
event1_str = ["2023-01-01", "2023-01-10"]
event2_str = ["2023-01-05", "2023-01-15"]
# Input full project dates as strings
project1_str = ["2025-01-02", "2025-02-11"]
# Input half project dates as strings
project2_str = ["2025-02-01", "2025-06-30"]
project3_str = ["2024-05-05", "2024-06-07"]
# Initialize components
date_calculator = DateCalculator()
calendar_manager = CalendarManager()
prediction_controller = PredictionController(calendar_manager, date_calculator)
# Add entries to calendar
print("Adding calendar entries...")
calendar_manager.add_entry(event1_str[0], event1_str[1], "Sonstige")
calendar_manager.add_entry(event2_str[0], event2_str[1], "Sonstige")
calendar_manager.add_entry(project1_str[0], project1_str[1], "EZ 100%")
calendar_manager.add_entry(project2_str[0], project2_str[1], "EZ 50%")
calendar_manager.add_entry(project3_str[0], project3_str[1], "EZ 50%")
# Test validation
print("Testing input validation...")
errors = prediction_controller.validate_prediction_inputs("2023-01-01", 2)
if errors:
print(f"Validation errors: {errors}")
else:
print("Input validation passed")
# Calculate prediction
print("Calculating prediction...")
success = prediction_controller.make_prediction("2023-01-01", 2)
if success:
prediction = prediction_controller.get_prediction()
print(f"Predicted completion date: {prediction}")
# Test event type handler
print("\nTesting EventTypeHandler...")
entries = calendar_manager.list_entries()
categorized = EventTypeHandler.categorize_events(entries)
print(f"Categorized events: {list(categorized.keys())}")
# Test accounted time calculation
for entry in entries:
accounted_time = EventTypeHandler.calculate_accounted_time(entry)
print(f"Entry {entry.id}: {accounted_time}")
print(f"\nAll calendar entries: {len(calendar_manager.list_entries())}")
else:
print("Prediction calculation failed")
def test_event_type_handler():
"""Test the EventTypeHandler functionality"""
print("\nTesting EventTypeHandler...")
# Test keyword validation
for keyword in EventConfig.KEYWORDS:
is_valid = EventTypeHandler.validate_event_type(keyword)
print(f"Keyword '{keyword}' is valid: {is_valid}")
# Test duration calculation
from datetime import datetime
start_date = datetime(2023, 1, 1)
duration = EventTypeHandler.get_duration_for_type("EZ pauschal", start_date)
print(f"EZ pauschal duration from {start_date}: {duration}")
# Test display names
for keyword in EventConfig.KEYWORDS:
display_name = EventTypeHandler.get_event_type_display_name(keyword)
print(f"'{keyword}' -> '{display_name}'")
def test_date_calculator():
"""Test the refactored DateCalculator"""
print("\nTesting DateCalculator...")
from datetime import datetime
# Test period sorting
periods = [
(datetime(2023, 3, 1), datetime(2023, 3, 10), "id1"),
(datetime(2023, 1, 1), datetime(2023, 1, 10), "id2"),
(datetime(2023, 2, 1), datetime(2023, 2, 10), "id3")
]
sorted_periods = DateCalculator.sort_periods(periods)
print(f"Sorted periods: {[(p[0].strftime('%Y-%m-%d'), p[1].strftime('%Y-%m-%d'), p[2]) for p in sorted_periods]}")
# Test truncation
launch_date = datetime(2023, 1, 15)
truncated = DateCalculator.truncate_periods(sorted_periods, launch_date)
print(f"Truncated periods: {[(p[0].strftime('%Y-%m-%d'), p[1].strftime('%Y-%m-%d'), p[2]) for p in truncated]}")
if __name__ == "__main__":
test_calculate_prediction()
test_event_type_handler()
test_date_calculator()
|