Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow half-hourly truck arrival distributions #200

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading