Skip to content

Commit

Permalink
Allow half-hourly truck arrival distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
1kastner committed Oct 2, 2023
1 parent f9fde69 commit 7d5457b
Show file tree
Hide file tree
Showing 7 changed files with 706 additions and 10 deletions.
3 changes: 2 additions & 1 deletion conflowgen/api/container_dwell_time_distribution_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions conflowgen/api/truck_arrival_distribution_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 2 additions & 2 deletions conflowgen/domain_models/distribution_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion conflowgen/previews/truck_gate_throughput_preview_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down
Loading

0 comments on commit 7d5457b

Please sign in to comment.