summaryrefslogtreecommitdiff
path: root/test2.py
blob: 08b5e7fb6ec212f7167e17a1b6ad88e839170dfd (plain)
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
# Example usage and testing
def demo_state_management():
    """Demonstrate the enhanced state management functionality"""
    from calendar_manager import CalendarManager
    from prediction_controller import PredictionController
    from date_calculator import DateCalculator
    
    # Create components
    calendar_manager = CalendarManager()
    date_calculator = DateCalculator()
    prediction_controller = PredictionController(calendar_manager, date_calculator)
    
    # Add some sample entries
    calendar_manager.add_entry("2024-01-01", "2024-06-30", "EZ 100%", "Sample project")
    calendar_manager.add_entry("2024-07-01", "2024-12-31", "EZ 50%", "Part-time work")
    calendar_manager.add_entry("2024-03-15", "2024-03-20", "Sonstige", "Conference")
    
    # Make a prediction
    success = prediction_controller.make_prediction("2023-01-01", 2)
    if success:
        print("Prediction calculated successfully")
        
        # Save complete state
        state_filename = "example_prediction_state.prediction.json"
        if prediction_controller.save_complete_state(state_filename):
            print(f"State saved to {state_filename}")
            
            # Load state into new components
            new_calendar = CalendarManager()
            new_controller = PredictionController(new_calendar, date_calculator)
            
            if new_controller.load_complete_state(state_filename):
                print("State loaded successfully")
                print(f"Loaded {len(new_calendar.entries)} entries")
                print(f"Launch date: {new_controller.get_launch_date()}")
                print(f"Prediction: {new_controller.get_prediction()}")
                
                # Display entries with their metadata
                for entry in new_calendar.entries:
                    print(f"Entry: {entry.keyword} ({entry.start_date.date()} to {entry.end_date.date()})")
                    if hasattr(entry, 'time_period') and entry.time_period:
                        print(f"  Time period: {entry.time_period}")
                    if entry.corrected_start_date:
                        print(f"  Corrected: {entry.corrected_start_date.date()} to {entry.corrected_end_date.date()}")

if __name__ == "__main__":
    demo_state_management()