From 7d5457b8326cbf3b166fc8afb2f0a0bf03d13524 Mon Sep 17 00:00:00 2001 From: Marvin Kastner Date: Mon, 2 Oct 2023 20:23:22 +0200 Subject: [PATCH] Allow half-hourly truck arrival distributions --- ...ntainer_dwell_time_distribution_manager.py | 3 +- .../api/truck_arrival_distribution_manager.py | 4 +- .../truck_arrival_distribution.py | 4 +- .../domain_models/distribution_validators.py | 4 +- .../truck_gate_throughput_preview_report.py | 4 +- ...test_truck_arrival_distribution_manager.py | 349 +++++++++++++++++- ...t_truck_arrival_distribution_repository.py | 348 +++++++++++++++++ 7 files changed, 706 insertions(+), 10 deletions(-) diff --git a/conflowgen/api/container_dwell_time_distribution_manager.py b/conflowgen/api/container_dwell_time_distribution_manager.py index 8c60d54d..7fa65bc2 100644 --- a/conflowgen/api/container_dwell_time_distribution_manager.py +++ b/conflowgen/api/container_dwell_time_distribution_manager.py @@ -62,7 +62,8 @@ def set_container_dwell_time_distribution( ) DataSummariesCache.reset_cache() - def get_average_container_dwell_time(self, start_date: datetime.date, end_date: datetime.date) -> float: + @staticmethod + def get_average_container_dwell_time(start_date: datetime.date, end_date: datetime.date) -> float: """ Uses :class:`.ModeOfTransportDistributionManager` to calculate the expected average container dwell time based on the scheduled container flow. diff --git a/conflowgen/api/truck_arrival_distribution_manager.py b/conflowgen/api/truck_arrival_distribution_manager.py index 7c1ac4b0..8be94772 100644 --- a/conflowgen/api/truck_arrival_distribution_manager.py +++ b/conflowgen/api/truck_arrival_distribution_manager.py @@ -29,7 +29,7 @@ def get_truck_arrival_distribution(self) -> typing.Dict[int, float]: """ return self.truck_arrival_distribution_repository.get_distribution() - def set_truck_arrival_distribution(self, distribution: typing.Dict[int, float]) -> None: + def set_truck_arrival_distribution(self, distribution: typing.Dict[float, float]) -> None: """ Args: @@ -40,7 +40,7 @@ def set_truck_arrival_distribution(self, distribution: typing.Dict[int, float]) """ sanitized_distribution = self._normalize_and_validate_distribution_without_dependent_variables( distribution, - int, + float, values_are_frequencies=True ) self.truck_arrival_distribution_repository.set_distribution(sanitized_distribution) diff --git a/conflowgen/domain_models/distribution_models/truck_arrival_distribution.py b/conflowgen/domain_models/distribution_models/truck_arrival_distribution.py index 955ba18a..048540fb 100644 --- a/conflowgen/domain_models/distribution_models/truck_arrival_distribution.py +++ b/conflowgen/domain_models/distribution_models/truck_arrival_distribution.py @@ -1,11 +1,11 @@ -from peewee import FloatField, IntegerField +from peewee import FloatField from conflowgen.domain_models.base_model import BaseModel class TruckArrivalDistribution(BaseModel): """The truck arrival distribution (both inbound and outbound journeys)""" - hour_in_the_week = IntegerField(null=False, primary_key=True, unique=True) + hour_in_the_week = FloatField(null=False, primary_key=True, unique=True) fraction = FloatField(null=False) def __repr__(self): diff --git a/conflowgen/domain_models/distribution_validators.py b/conflowgen/domain_models/distribution_validators.py index 4dc50c66..dfe9a527 100644 --- a/conflowgen/domain_models/distribution_validators.py +++ b/conflowgen/domain_models/distribution_validators.py @@ -135,7 +135,7 @@ def _check_all_keys_are_of_intended_primitive_type( return sanitized_distribution -SUPPORTED_PRIMITIVE_KEY_TYPES = (int, ) +SUPPORTED_PRIMITIVE_KEY_TYPES = (int, float) def _check_all_required_keys_are_set_in_distribution( @@ -194,7 +194,7 @@ def _check_value_range_of_frequencies_in_distribution( def validate_distribution_with_no_dependent_variables( distribution: Dict[enum.Enum | int, Any], - key_type: Type[enum.Enum] | Type[int], + key_type: Type[enum.Enum] | Type[float], values_are_frequencies: bool ) -> Dict[enum.Enum | int, float]: sanitized_distribution = _check_all_required_keys_are_set_in_distribution(distribution, key_type) diff --git a/conflowgen/previews/truck_gate_throughput_preview_report.py b/conflowgen/previews/truck_gate_throughput_preview_report.py index 0fe1ed2f..16b1aa88 100644 --- a/conflowgen/previews/truck_gate_throughput_preview_report.py +++ b/conflowgen/previews/truck_gate_throughput_preview_report.py @@ -3,6 +3,8 @@ import pandas as pd import matplotlib +import matplotlib.ticker +import matplotlib.axes from matplotlib import pyplot as plt from conflowgen.domain_models.data_types.mode_of_transport import ModeOfTransport @@ -63,7 +65,7 @@ def get_report_as_text(self, inbound: bool = True, outbound: bool = True, **kwar count = 0 # Find min, max, and average for each day of the week for time in sorted(truck_distribution): - day = time // 24 + day = int(time // 24) if day == 0: count += 1 # Count the number of data points in a single day data[day]['minimum'] = min(data[day]['minimum'], truck_distribution[time]) diff --git a/conflowgen/tests/api/test_truck_arrival_distribution_manager.py b/conflowgen/tests/api/test_truck_arrival_distribution_manager.py index 2ed2ae5b..8fd0b868 100644 --- a/conflowgen/tests/api/test_truck_arrival_distribution_manager.py +++ b/conflowgen/tests/api/test_truck_arrival_distribution_manager.py @@ -5,7 +5,6 @@ class TestTruckArrivalDistributionManager(unittest.TestCase): - ARRIVAL_DISTRIBUTION = { 3: .2, 4: .8 @@ -24,10 +23,356 @@ def test_get_truck_arrival_distributions(self): self.assertEqual(distribution, self.ARRIVAL_DISTRIBUTION) def test_set_truck_arrival_distributions(self): - with unittest.mock.patch.object( self.truck_arrival_distribution_manager.truck_arrival_distribution_repository, 'set_distribution', return_value=None) as mock_method: self.truck_arrival_distribution_manager.set_truck_arrival_distribution(self.ARRIVAL_DISTRIBUTION) mock_method.assert_called_once_with(self.ARRIVAL_DISTRIBUTION) + + def test_set_truck_arrival_distribution_with_half_hour_windows(self): + tad = { + 0.0: 0.0, + 0.5: 0.0, + 1.0: 0.0, + 1.5: 0.0, + 2.0: 0.0, + 2.5: 0.0, + 3.0: 0.0, + 3.5: 0.0, + 4.0: 0.0, + 4.5: 0.0, + 5.0: 0.0, + 5.5: 0.0, + 6.0: 0.0, + 6.5: 0.0, + 7.0: 0.0, + 7.5: 0.0, + 8.0: 0.005847356259863457, + 8.5: 0.005847356259863457, + 9.0: 0.006884424813828916, + 9.5: 0.006884424813828916, + 10.0: 0.008240784915529742, + 10.5: 0.008240784915529742, + 11.0: 0.010754542541876863, + 11.5: 0.010754542541876863, + 12.0: 0.009065614385411223, + 12.5: 0.009065614385411223, + 13.0: 0.00956682661232754, + 13.5: 0.00956682661232754, + 14.0: 0.009676877930280697, + 14.5: 0.009676877930280697, + 15.0: 0.007198538886305298, + 15.5: 0.007198538886305298, + 16.0: 0.008977906910623057, + 16.5: 0.008977906910623057, + 17.0: 0.0069943804588238085, + 17.5: 0.0069943804588238085, + 18.0: 0.005381820143341635, + 18.5: 0.005381820143341635, + 19.0: 0.004515467462119917, + 19.5: 0.004515467462119917, + 20.0: 0.003327233560870352, + 20.5: 0.0, + 21.0: 0.0, + 21.5: 0.0, + 22.0: 0.0, + 22.5: 0.0, + 23.0: 0.0, + 23.5: 0.0, + 24.0: 0.0, + 24.5: 0.0, + 25.0: 0.0, + 25.5: 0.0, + 26.0: 0.0, + 26.5: 0.0, + 27.0: 0.0, + 27.5: 0.0, + 28.0: 0.0, + 28.5: 0.0, + 29.0: 0.0, + 29.5: 0.0, + 30.0: 0.0, + 30.5: 0.0, + 31.0: 0.0, + 31.5: 0.0, + 32.0: 0.006041312488159616, + 32.5: 0.006041312488159616, + 33.0: 0.007328821183642256, + 33.5: 0.007328821183642256, + 34.0: 0.008852314535559925, + 34.5: 0.008852314535559925, + 35.0: 0.00838027636330664, + 35.5: 0.00838027636330664, + 36.0: 0.009907439316224021, + 36.5: 0.009907439316224021, + 37.0: 0.009169313456252479, + 37.5: 0.009169313456252479, + 38.0: 0.009614722815201775, + 38.5: 0.009614722815201775, + 39.0: 0.00787503623358249, + 39.5: 0.00787503623358249, + 40.0: 0.007824251062007128, + 40.5: 0.007824251062007128, + 41.0: 0.00705486596186395, + 41.5: 0.00705486596186395, + 42.0: 0.004398697886964745, + 42.5: 0.004398697886964745, + 43.0: 0.003750005820315642, + 43.5: 0.003750005820315642, + 44.0: 0.0034171233780298876, + 44.5: 0.0, + 45.0: 0.0, + 45.5: 0.0, + 46.0: 0.0, + 46.5: 0.0, + 47.0: 0.0, + 47.5: 0.0, + 48.0: 0.0, + 48.5: 0.0, + 49.0: 0.0, + 49.5: 0.0, + 50.0: 0.0, + 50.5: 0.0, + 51.0: 0.0, + 51.5: 0.0, + 52.0: 0.0, + 52.5: 0.0, + 53.0: 0.0, + 53.5: 0.0, + 54.0: 0.0, + 54.5: 0.0, + 55.0: 0.0, + 55.5: 0.0, + 56.0: 0.006745061258333995, + 56.5: 0.006745061258333995, + 57.0: 0.007679410701646271, + 57.5: 0.007679410701646271, + 58.0: 0.008482538433133749, + 58.5: 0.008482538433133749, + 59.0: 0.009062186684434759, + 59.5: 0.009062186684434759, + 60.0: 0.00909081220731496, + 60.5: 0.00909081220731496, + 61.0: 0.011583665479640732, + 61.5: 0.011583665479640732, + 62.0: 0.009624665427407022, + 62.5: 0.009624665427407022, + 63.0: 0.008408359880097303, + 63.5: 0.008408359880097303, + 64.0: 0.007806016845642667, + 64.5: 0.007806016845642667, + 65.0: 0.006535274260445081, + 65.5: 0.006535274260445081, + 66.0: 0.0057751620805421774, + 66.5: 0.0057751620805421774, + 67.0: 0.004285593715597633, + 67.5: 0.004285593715597633, + 68.0: 0.002796016187253771, + 68.5: 0.0, + 69.0: 0.0, + 69.5: 0.0, + 70.0: 0.0, + 70.5: 0.0, + 71.0: 0.0, + 71.5: 0.0, + 72.0: 0.0, + 72.5: 0.0, + 73.0: 0.0, + 73.5: 0.0, + 74.0: 0.0, + 74.5: 0.0, + 75.0: 0.0, + 75.5: 0.0, + 76.0: 0.0, + 76.5: 0.0, + 77.0: 0.0, + 77.5: 0.0, + 78.0: 0.0, + 78.5: 0.0, + 79.0: 0.0, + 79.5: 0.0, + 80.0: 0.00668500119579781, + 80.5: 0.00668500119579781, + 81.0: 0.008059864990389558, + 81.5: 0.008059864990389558, + 82.0: 0.009857405383896607, + 82.5: 0.009857405383896607, + 83.0: 0.00989603470422583, + 83.5: 0.00989603470422583, + 84.0: 0.012743096638284358, + 84.5: 0.012743096638284358, + 85.0: 0.010655364933628404, + 85.5: 0.010655364933628404, + 86.0: 0.010917545311219544, + 86.5: 0.010917545311219544, + 87.0: 0.010015960025975905, + 87.5: 0.010015960025975905, + 88.0: 0.00955277551986375, + 88.5: 0.00955277551986375, + 89.0: 0.007851974044966025, + 89.5: 0.007851974044966025, + 90.0: 0.005257200592342844, + 90.5: 0.005257200592342844, + 91.0: 0.004092778923079977, + 91.5: 0.004092778923079977, + 92.0: 0.003939305601388119, + 92.5: 0.0, + 93.0: 0.0, + 93.5: 0.0, + 94.0: 0.0, + 94.5: 0.0, + 95.0: 0.0, + 95.5: 0.0, + 96.0: 0.0, + 96.5: 0.0, + 97.0: 0.0, + 97.5: 0.0, + 98.0: 0.0, + 98.5: 0.0, + 99.0: 0.0, + 99.5: 0.0, + 100.0: 0.0, + 100.5: 0.0, + 101.0: 0.0, + 101.5: 0.0, + 102.0: 0.0, + 102.5: 0.0, + 103.0: 0.0, + 103.5: 0.0, + 104.0: 0.006851392669705531, + 104.5: 0.006851392669705531, + 105.0: 0.010274798552864527, + 105.5: 0.010274798552864527, + 106.0: 0.011685874595427376, + 106.5: 0.011685874595427376, + 107.0: 0.01058627130541297, + 107.5: 0.01058627130541297, + 108.0: 0.010527093567814597, + 108.5: 0.010527093567814597, + 109.0: 0.012387483771322302, + 109.5: 0.012387483771322302, + 110.0: 0.010640715187610906, + 110.5: 0.010640715187610906, + 111.0: 0.00882546777802846, + 111.5: 0.00882546777802846, + 112.0: 0.008153561979994874, + 112.5: 0.008153561979994874, + 113.0: 0.006259105707922169, + 113.5: 0.006259105707922169, + 114.0: 0.005860855283263588, + 114.5: 0.005860855283263588, + 115.0: 0.0028579368743328936, + 115.5: 0.0028579368743328936, + 116.0: 0.002756732334354128, + 116.5: 0.0, + 117.0: 0.0, + 117.5: 0.0, + 118.0: 0.0, + 118.5: 0.0, + 119.0: 0.0, + 119.5: 0.0, + 120.0: 0.0, + 120.5: 0.0, + 121.0: 0.0, + 121.5: 0.0, + 122.0: 0.0, + 122.5: 0.0, + 123.0: 0.0, + 123.5: 0.0, + 124.0: 0.0, + 124.5: 0.0, + 125.0: 0.0, + 125.5: 0.0, + 126.0: 0.0, + 126.5: 0.0, + 127.0: 0.0, + 127.5: 0.0, + 128.0: 0.0009936554715091123, + 128.5: 0.0009936554715091123, + 129.0: 0.0009210861041335698, + 129.5: 0.0009210861041335698, + 130.0: 0.0004654632814999111, + 130.5: 0.0004654632814999111, + 131.0: 0.0003279024939137455, + 131.5: 0.0003279024939137455, + 132.0: 0.00029778216297555397, + 132.5: 0.00029778216297555397, + 133.0: 0.0, + 133.5: 0.0, + 134.0: 0.0, + 134.5: 0.0, + 135.0: 0.0, + 135.5: 0.0, + 136.0: 0.0, + 136.5: 0.0, + 137.0: 0.0, + 137.5: 0.0, + 138.0: 0.0, + 138.5: 0.0, + 139.0: 0.0, + 139.5: 0.0, + 140.0: 0.0, + 140.5: 0.0, + 141.0: 0.0, + 141.5: 0.0, + 142.0: 0.0, + 142.5: 0.0, + 143.0: 0.0, + 143.5: 0.0, + 144.0: 0.0, + 144.5: 0.0, + 145.0: 0.0, + 145.5: 0.0, + 146.0: 0.0, + 146.5: 0.0, + 147.0: 0.0, + 147.5: 0.0, + 148.0: 0.0, + 148.5: 0.0, + 149.0: 0.0, + 149.5: 0.0, + 150.0: 0.0, + 150.5: 0.0, + 151.0: 0.0, + 151.5: 0.0, + 152.0: 0.0, + 152.5: 0.0, + 153.0: 0.0, + 153.5: 0.0, + 154.0: 0.0, + 154.5: 0.0, + 155.0: 0.0, + 155.5: 0.0, + 156.0: 0.0, + 156.5: 0.0, + 157.0: 0.0, + 157.5: 0.0, + 158.0: 0.0, + 158.5: 0.0, + 159.0: 0.0, + 159.5: 0.0, + 160.0: 0.0, + 160.5: 0.0, + 161.0: 0.0, + 161.5: 0.0, + 162.0: 0.0, + 162.5: 0.0, + 163.0: 0.0, + 163.5: 0.0, + 164.0: 0.0, + 164.5: 0.0, + 165.0: 0.0, + 165.5: 0.0, + 166.0: 0.0, + 166.5: 0.0, + 167.0: 0.0, + 167.5: 0.0 + } + + with unittest.mock.patch.object( + self.truck_arrival_distribution_manager.truck_arrival_distribution_repository, + 'set_distribution', + return_value=None) as mock_method: + self.truck_arrival_distribution_manager.set_truck_arrival_distribution(tad) + mock_method.assert_called_once_with(tad) diff --git a/conflowgen/tests/domain_models/distribution_repositories/test_truck_arrival_distribution_repository.py b/conflowgen/tests/domain_models/distribution_repositories/test_truck_arrival_distribution_repository.py index 363c5932..f1aeb495 100644 --- a/conflowgen/tests/domain_models/distribution_repositories/test_truck_arrival_distribution_repository.py +++ b/conflowgen/tests/domain_models/distribution_repositories/test_truck_arrival_distribution_repository.py @@ -178,6 +178,345 @@ class TestTruckArrivalDistributionRepository(unittest.TestCase): 166: 0.0, 167: 0.0} + half_hourly_data = { + 0.0: 0.0, + 0.5: 0.0, + 1.0: 0.0, + 1.5: 0.0, + 2.0: 0.0, + 2.5: 0.0, + 3.0: 0.0, + 3.5: 0.0, + 4.0: 0.0, + 4.5: 0.0, + 5.0: 0.0, + 5.5: 0.0, + 6.0: 0.0, + 6.5: 0.0, + 7.0: 0.0, + 7.5: 0.0, + 8.0: 0.005847356259863457, + 8.5: 0.005847356259863457, + 9.0: 0.006884424813828916, + 9.5: 0.006884424813828916, + 10.0: 0.008240784915529742, + 10.5: 0.008240784915529742, + 11.0: 0.010754542541876863, + 11.5: 0.010754542541876863, + 12.0: 0.009065614385411223, + 12.5: 0.009065614385411223, + 13.0: 0.00956682661232754, + 13.5: 0.00956682661232754, + 14.0: 0.009676877930280697, + 14.5: 0.009676877930280697, + 15.0: 0.007198538886305298, + 15.5: 0.007198538886305298, + 16.0: 0.008977906910623057, + 16.5: 0.008977906910623057, + 17.0: 0.0069943804588238085, + 17.5: 0.0069943804588238085, + 18.0: 0.005381820143341635, + 18.5: 0.005381820143341635, + 19.0: 0.004515467462119917, + 19.5: 0.004515467462119917, + 20.0: 0.003327233560870352, + 20.5: 0.0, + 21.0: 0.0, + 21.5: 0.0, + 22.0: 0.0, + 22.5: 0.0, + 23.0: 0.0, + 23.5: 0.0, + 24.0: 0.0, + 24.5: 0.0, + 25.0: 0.0, + 25.5: 0.0, + 26.0: 0.0, + 26.5: 0.0, + 27.0: 0.0, + 27.5: 0.0, + 28.0: 0.0, + 28.5: 0.0, + 29.0: 0.0, + 29.5: 0.0, + 30.0: 0.0, + 30.5: 0.0, + 31.0: 0.0, + 31.5: 0.0, + 32.0: 0.006041312488159616, + 32.5: 0.006041312488159616, + 33.0: 0.007328821183642256, + 33.5: 0.007328821183642256, + 34.0: 0.008852314535559925, + 34.5: 0.008852314535559925, + 35.0: 0.00838027636330664, + 35.5: 0.00838027636330664, + 36.0: 0.009907439316224021, + 36.5: 0.009907439316224021, + 37.0: 0.009169313456252479, + 37.5: 0.009169313456252479, + 38.0: 0.009614722815201775, + 38.5: 0.009614722815201775, + 39.0: 0.00787503623358249, + 39.5: 0.00787503623358249, + 40.0: 0.007824251062007128, + 40.5: 0.007824251062007128, + 41.0: 0.00705486596186395, + 41.5: 0.00705486596186395, + 42.0: 0.004398697886964745, + 42.5: 0.004398697886964745, + 43.0: 0.003750005820315642, + 43.5: 0.003750005820315642, + 44.0: 0.0034171233780298876, + 44.5: 0.0, + 45.0: 0.0, + 45.5: 0.0, + 46.0: 0.0, + 46.5: 0.0, + 47.0: 0.0, + 47.5: 0.0, + 48.0: 0.0, + 48.5: 0.0, + 49.0: 0.0, + 49.5: 0.0, + 50.0: 0.0, + 50.5: 0.0, + 51.0: 0.0, + 51.5: 0.0, + 52.0: 0.0, + 52.5: 0.0, + 53.0: 0.0, + 53.5: 0.0, + 54.0: 0.0, + 54.5: 0.0, + 55.0: 0.0, + 55.5: 0.0, + 56.0: 0.006745061258333995, + 56.5: 0.006745061258333995, + 57.0: 0.007679410701646271, + 57.5: 0.007679410701646271, + 58.0: 0.008482538433133749, + 58.5: 0.008482538433133749, + 59.0: 0.009062186684434759, + 59.5: 0.009062186684434759, + 60.0: 0.00909081220731496, + 60.5: 0.00909081220731496, + 61.0: 0.011583665479640732, + 61.5: 0.011583665479640732, + 62.0: 0.009624665427407022, + 62.5: 0.009624665427407022, + 63.0: 0.008408359880097303, + 63.5: 0.008408359880097303, + 64.0: 0.007806016845642667, + 64.5: 0.007806016845642667, + 65.0: 0.006535274260445081, + 65.5: 0.006535274260445081, + 66.0: 0.0057751620805421774, + 66.5: 0.0057751620805421774, + 67.0: 0.004285593715597633, + 67.5: 0.004285593715597633, + 68.0: 0.002796016187253771, + 68.5: 0.0, + 69.0: 0.0, + 69.5: 0.0, + 70.0: 0.0, + 70.5: 0.0, + 71.0: 0.0, + 71.5: 0.0, + 72.0: 0.0, + 72.5: 0.0, + 73.0: 0.0, + 73.5: 0.0, + 74.0: 0.0, + 74.5: 0.0, + 75.0: 0.0, + 75.5: 0.0, + 76.0: 0.0, + 76.5: 0.0, + 77.0: 0.0, + 77.5: 0.0, + 78.0: 0.0, + 78.5: 0.0, + 79.0: 0.0, + 79.5: 0.0, + 80.0: 0.00668500119579781, + 80.5: 0.00668500119579781, + 81.0: 0.008059864990389558, + 81.5: 0.008059864990389558, + 82.0: 0.009857405383896607, + 82.5: 0.009857405383896607, + 83.0: 0.00989603470422583, + 83.5: 0.00989603470422583, + 84.0: 0.012743096638284358, + 84.5: 0.012743096638284358, + 85.0: 0.010655364933628404, + 85.5: 0.010655364933628404, + 86.0: 0.010917545311219544, + 86.5: 0.010917545311219544, + 87.0: 0.010015960025975905, + 87.5: 0.010015960025975905, + 88.0: 0.00955277551986375, + 88.5: 0.00955277551986375, + 89.0: 0.007851974044966025, + 89.5: 0.007851974044966025, + 90.0: 0.005257200592342844, + 90.5: 0.005257200592342844, + 91.0: 0.004092778923079977, + 91.5: 0.004092778923079977, + 92.0: 0.003939305601388119, + 92.5: 0.0, + 93.0: 0.0, + 93.5: 0.0, + 94.0: 0.0, + 94.5: 0.0, + 95.0: 0.0, + 95.5: 0.0, + 96.0: 0.0, + 96.5: 0.0, + 97.0: 0.0, + 97.5: 0.0, + 98.0: 0.0, + 98.5: 0.0, + 99.0: 0.0, + 99.5: 0.0, + 100.0: 0.0, + 100.5: 0.0, + 101.0: 0.0, + 101.5: 0.0, + 102.0: 0.0, + 102.5: 0.0, + 103.0: 0.0, + 103.5: 0.0, + 104.0: 0.006851392669705531, + 104.5: 0.006851392669705531, + 105.0: 0.010274798552864527, + 105.5: 0.010274798552864527, + 106.0: 0.011685874595427376, + 106.5: 0.011685874595427376, + 107.0: 0.01058627130541297, + 107.5: 0.01058627130541297, + 108.0: 0.010527093567814597, + 108.5: 0.010527093567814597, + 109.0: 0.012387483771322302, + 109.5: 0.012387483771322302, + 110.0: 0.010640715187610906, + 110.5: 0.010640715187610906, + 111.0: 0.00882546777802846, + 111.5: 0.00882546777802846, + 112.0: 0.008153561979994874, + 112.5: 0.008153561979994874, + 113.0: 0.006259105707922169, + 113.5: 0.006259105707922169, + 114.0: 0.005860855283263588, + 114.5: 0.005860855283263588, + 115.0: 0.0028579368743328936, + 115.5: 0.0028579368743328936, + 116.0: 0.002756732334354128, + 116.5: 0.0, + 117.0: 0.0, + 117.5: 0.0, + 118.0: 0.0, + 118.5: 0.0, + 119.0: 0.0, + 119.5: 0.0, + 120.0: 0.0, + 120.5: 0.0, + 121.0: 0.0, + 121.5: 0.0, + 122.0: 0.0, + 122.5: 0.0, + 123.0: 0.0, + 123.5: 0.0, + 124.0: 0.0, + 124.5: 0.0, + 125.0: 0.0, + 125.5: 0.0, + 126.0: 0.0, + 126.5: 0.0, + 127.0: 0.0, + 127.5: 0.0, + 128.0: 0.0009936554715091123, + 128.5: 0.0009936554715091123, + 129.0: 0.0009210861041335698, + 129.5: 0.0009210861041335698, + 130.0: 0.0004654632814999111, + 130.5: 0.0004654632814999111, + 131.0: 0.0003279024939137455, + 131.5: 0.0003279024939137455, + 132.0: 0.00029778216297555397, + 132.5: 0.00029778216297555397, + 133.0: 0.0, + 133.5: 0.0, + 134.0: 0.0, + 134.5: 0.0, + 135.0: 0.0, + 135.5: 0.0, + 136.0: 0.0, + 136.5: 0.0, + 137.0: 0.0, + 137.5: 0.0, + 138.0: 0.0, + 138.5: 0.0, + 139.0: 0.0, + 139.5: 0.0, + 140.0: 0.0, + 140.5: 0.0, + 141.0: 0.0, + 141.5: 0.0, + 142.0: 0.0, + 142.5: 0.0, + 143.0: 0.0, + 143.5: 0.0, + 144.0: 0.0, + 144.5: 0.0, + 145.0: 0.0, + 145.5: 0.0, + 146.0: 0.0, + 146.5: 0.0, + 147.0: 0.0, + 147.5: 0.0, + 148.0: 0.0, + 148.5: 0.0, + 149.0: 0.0, + 149.5: 0.0, + 150.0: 0.0, + 150.5: 0.0, + 151.0: 0.0, + 151.5: 0.0, + 152.0: 0.0, + 152.5: 0.0, + 153.0: 0.0, + 153.5: 0.0, + 154.0: 0.0, + 154.5: 0.0, + 155.0: 0.0, + 155.5: 0.0, + 156.0: 0.0, + 156.5: 0.0, + 157.0: 0.0, + 157.5: 0.0, + 158.0: 0.0, + 158.5: 0.0, + 159.0: 0.0, + 159.5: 0.0, + 160.0: 0.0, + 160.5: 0.0, + 161.0: 0.0, + 161.5: 0.0, + 162.0: 0.0, + 162.5: 0.0, + 163.0: 0.0, + 163.5: 0.0, + 164.0: 0.0, + 164.5: 0.0, + 165.0: 0.0, + 165.5: 0.0, + 166.0: 0.0, + 166.5: 0.0, + 167.0: 0.0, + 167.5: 0.0 + } + def setUp(self) -> None: """Create container database in memory""" sqlite_db = setup_sqlite_in_memory_db() @@ -205,6 +544,15 @@ def test_happy_path(self): self.repository.get_distribution() ) + def test_happy_path_with_half_hourly_data(self): + self.repository.set_distribution( + self.half_hourly_data + ) + self.assertDictEqual( + self.half_hourly_data, + self.repository.get_distribution() + ) + def test_set_twice(self): """e.g., no exception is thrown while refreshing the data in the database. """