Beispiel #1
0
    def test_exactly_overlapping_ranges(self):
        range_1 = DateRange.for_month(2019, 2)
        range_2 = DateRange.for_month(2019, 2)

        time_range_diff = DateRangeDiff(range_1, range_2)

        self.assertEqual(range_1, time_range_diff.overlapping_range)
        self.assertEqual([], time_range_diff.range_1_non_overlapping_parts)
        self.assertEqual([], time_range_diff.range_2_non_overlapping_parts)
Beispiel #2
0
    def test_non_overlapping_ranges(self) -> None:
        range_1 = DateRange.for_month(2019, 2)
        range_2 = DateRange.for_month(2019, 3)

        time_range_diff = DateRangeDiff(range_1, range_2)

        self.assertEqual(None, time_range_diff.overlapping_range)
        self.assertEqual([range_1], time_range_diff.range_1_non_overlapping_parts)
        self.assertEqual([range_2], time_range_diff.range_2_non_overlapping_parts)
Beispiel #3
0
    def _months_excluded_from_supervision_population(
            self) -> Set[Tuple[int, int]]:
        """For each StateIncarcerationPeriod, identifies months where the person was incarcerated for every day during
        that month. Returns a set of months in the format (year, month) for which the person spent the entire month in a
        prison, where the incarceration prevents the person from being counted simultaneously in the supervision
        population.
        """
        months_excluded_from_supervision_population: Set[Tuple[int,
                                                               int]] = set()

        for (incarceration_period
             ) in self.incarceration_periods_not_under_supervision_authority:
            months_overlaps_at_all = (incarceration_period.duration.
                                      get_months_range_overlaps_at_all())

            for year, month in months_overlaps_at_all:
                overlapping_periods = (
                    self.
                    month_to_overlapping_ips_not_under_supervision_authority[
                        year][month])

                remaining_ranges_to_cover = (
                    self._get_portions_of_range_not_covered_by_periods_subset(
                        DateRange.for_month(year, month), overlapping_periods))
                if not remaining_ranges_to_cover:
                    months_excluded_from_supervision_population.add(
                        (year, month))

        return months_excluded_from_supervision_population
Beispiel #4
0
    def _months_fully_incarcerated(self) -> Set[Tuple[int, int]]:
        """For each StateIncarcerationPeriod, identifies months where the person was incarcerated for every day during
        that month. Returns a set of months in the format (year, month) for which the person spent the entire month in a
        prison.
        """
        months_fully_incarcerated: Set[Tuple[int, int]] = set()

        for incarceration_period in self.incarceration_periods:
            months_overlaps_at_all = incarceration_period.duration.get_months_range_overlaps_at_all(
            )

            for year, month in months_overlaps_at_all:
                overlapping_periods = self.month_to_overlapping_incarceration_periods[
                    year][month]

                remaining_ranges_to_cover = self._get_portions_of_range_not_covered_by_periods_subset(
                    DateRange.for_month(year, month), overlapping_periods)
                if not remaining_ranges_to_cover:
                    months_fully_incarcerated.add((year, month))

        return months_fully_incarcerated