summaryrefslogtreecommitdiff
path: root/prediction_controller.py
diff options
context:
space:
mode:
Diffstat (limited to 'prediction_controller.py')
-rw-r--r--prediction_controller.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/prediction_controller.py b/prediction_controller.py
index 916a325..168ad62 100644
--- a/prediction_controller.py
+++ b/prediction_controller.py
@@ -102,8 +102,11 @@ class PredictionController:
sorted_projects = DateCalculator.sort_periods(full_projects)
considered_projects = DateCalculator.truncate_periods(sorted_projects, self.launch_date)
+ # Filter out any invalid periods
+ valid_projects = DateCalculator.filter_valid_periods(considered_projects)
+
# Round to month boundaries
- rounded_projects, total_months = DateCalculator.round_periods(considered_projects)
+ rounded_projects, total_months = DateCalculator.round_periods(valid_projects)
return rounded_projects
@@ -114,15 +117,20 @@ class PredictionController:
sorted_projects = DateCalculator.sort_periods(half_projects)
considered_projects = DateCalculator.truncate_periods(sorted_projects, self.launch_date)
+ # Filter out any invalid periods
+ valid_projects = DateCalculator.filter_valid_periods(considered_projects)
+
# Find non-overlapping periods with full projects
non_overlapping_projects = []
- for test_interval in considered_projects:
- non_overlapping_projects.extend(
- DateCalculator.find_non_overlapping_periods(full_projects, test_interval)
- )
+ for test_interval in valid_projects:
+ non_overlapping_results = DateCalculator.find_non_overlapping_periods(full_projects, test_interval)
+ non_overlapping_projects.extend(non_overlapping_results)
+
+ # Filter valid periods again after overlap processing
+ valid_non_overlapping = DateCalculator.filter_valid_periods(non_overlapping_projects)
# Round to month boundaries
- rounded_projects, total_months = DateCalculator.round_periods(non_overlapping_projects)
+ rounded_projects, total_months = DateCalculator.round_periods(valid_non_overlapping)
return rounded_projects
@@ -134,18 +142,26 @@ class PredictionController:
sorted_events = DateCalculator.sort_periods(other_events)
considered_events = DateCalculator.truncate_periods(sorted_events, self.launch_date)
- # Adjust overlapping periods
- adjusted_events = DateCalculator.adjust_periods(considered_events)
+ # Filter out any invalid periods
+ valid_events = DateCalculator.filter_valid_periods(considered_events)
# Find non-overlapping periods with all projects
all_projects = DateCalculator.sort_periods(full_projects + half_projects)
non_overlapping_events = []
- for test_interval in adjusted_events:
- non_overlapping_events.extend(
- DateCalculator.find_non_overlapping_periods(all_projects, test_interval)
- )
+ for test_interval in valid_events:
+ non_overlapping_results = DateCalculator.find_non_overlapping_periods(all_projects, test_interval)
+ non_overlapping_events.extend(non_overlapping_results)
- return non_overlapping_events
+ # Filter valid periods again after overlap processing
+ valid_non_overlapping = DateCalculator.filter_valid_periods(non_overlapping_events)
+
+ # Adjust overlapping periods
+ adjusted_events = DateCalculator.adjust_periods(valid_non_overlapping)
+
+ # Final validation to ensure all periods are valid
+ final_valid_events = DateCalculator.filter_valid_periods(adjusted_events)
+
+ return final_valid_events
def _calculate_final_prediction(self, prediction_start: datetime,
processed_events: Dict[str, List[Tuple[datetime, datetime, str]]]) -> datetime:
@@ -179,7 +195,7 @@ class PredictionController:
return final_prediction
def _apply_corrections_to_calendar(self):
- """Apply corrected dates to calendar entries"""
+ """Apply corrected dates to calendar entries and calculate time_period"""
# Collect all corrected events from processed results
all_corrected_events = []
@@ -225,5 +241,4 @@ class PredictionController:
if launch_dt > datetime(2100, 1, 1):
errors.append("Launch date too far in the future")
- return errors
-
+ return errors \ No newline at end of file