# 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()