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

Pr/209 - created from #209 #211

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ce1a3a8
algorithm modification for transshipment
May 16, 2024
c45afa0
Add flow_direction as Container property, use it exemplarily in some …
1kastner May 21, 2024
a8af159
Distinguish betwee flow_direction and journey_direction, fix tests. R…
1kastner May 21, 2024
677d93b
Improve description text
1kastner May 21, 2024
da9767c
Undo changes
1kastner May 21, 2024
309c991
fix mock_pyplot issue
1kastner May 21, 2024
36200ec
Save ConFlowGen version in SQLITE table
1kastner May 21, 2024
fcad055
Add happy path with ramp-up and ramp-down
1kastner May 21, 2024
a02e90a
Fix typing hint
1kastner May 21, 2024
1f50039
Add test case for ConFlowGen version
1kastner May 21, 2024
f8f5a74
Addtwo working tests and some todo's
1kastner May 21, 2024
e684808
drop unnecessary save statements
1kastner May 21, 2024
5f96ee5
add test placeholder for transshipment - test behavior here!
1kastner May 21, 2024
5f41256
fix free capacity modification
1kastner May 21, 2024
8f5956a
add test to check free capacity
1kastner May 21, 2024
5c58706
fix failing test
1kastner May 21, 2024
ba0a365
add mock test, drop saves
1kastner May 21, 2024
36a8ac4
fix test
1kastner May 21, 2024
253f440
Modify CTA script and add 10 days of ramp-up and ramp-down
1kastner May 21, 2024
0b9ce10
fix linting issues
1kastner May 21, 2024
d9e31f4
show difference of demo script in folder name
1kastner May 23, 2024
bff40ac
adjust last message
1kastner May 23, 2024
2440662
...again
1kastner May 23, 2024
78a558b
pass around ramp-up and ramp-down periods
1kastner May 23, 2024
30760e5
Find two nice names for the scaling factor of 0.1 / 10%, work with fa…
1kastner May 23, 2024
25c1427
Use datetime for ramp-up calculations
1kastner May 23, 2024
5dbb4bd
Add simple test
1kastner May 23, 2024
7051293
Add ContainerFlowByVehicleInstanceAnalysis and its report incl. docs,…
1kastner May 24, 2024
93027b5
Merge branch 'pr/209' of github.com:1kastner/conflowgen into pr/209
1kastner May 24, 2024
34498a2
Add test for container flow generator
1kastner May 24, 2024
fa23903
Add parameterized as dependency
1kastner May 26, 2024
53b99aa
Change API of PortCallManager
1kastner May 26, 2024
2b1ada6
Adjust demo scripts to new API
1kastner May 26, 2024
5def1d3
Create VehicleCapacityManager and VehicleContainerVolumeCalculator to…
1kastner May 26, 2024
cec7a5e
Adjust tests to new separation of tasks, avoid using "capacity" when …
1kastner May 26, 2024
200260d
Keep internal files in .tools subfolder
1kastner May 26, 2024
d8036a8
small fixes
1kastner May 26, 2024
7d5d74c
Fix asserts in brackets
1kastner May 26, 2024
f2d46e8
Add hint at the end of the demo script saying where it was from
1kastner May 26, 2024
5effb75
Add git commit to output of demo scripts
1kastner May 26, 2024
c8e9bee
Adjust OutboundToInboundVCUAR
May 26, 2024
71b9527
Use new PortCallManager API
May 26, 2024
e13c0b1
Adjust PortCallManager API usage
May 26, 2024
a44c648
Fix TKinter issue
May 26, 2024
c762a1a
Fix flake8 issues
May 26, 2024
2544d4f
Fix URL
1kastner May 26, 2024
e9b0cf2
Fix codefactor issues
1kastner May 26, 2024
1880dbe
This is not pylint but Bandit
1kastner May 26, 2024
72502ac
fix unused import
1kastner May 26, 2024
955f64d
allow restricting ContainerFlowByVehicleInstanceAnalysis
1kastner May 27, 2024
ef3a103
Highlight counting mechanism behind ModalSplitAnalysis
1kastner May 27, 2024
1a4fefb
synchronize and rectify bibtex entry in references.bib and background…
1kastner May 30, 2024
2f2bb00
PIANC Yearbook 2023 is now published
1kastner May 30, 2024
d2f0401
Merge branch 'pr/209' of github.com:1kastner/conflowgen into pr/209
1kastner May 30, 2024
54d2440
Merge branch 'main' into pr/209
1kastner Aug 7, 2024
9a7c46f
repait bibtex file
1kastner Aug 14, 2024
994628e
Update URL of DESTATIS
1kastner Aug 14, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ examples/Python_Script/databases/
# Ignore local changes as they happen with every execution. If something changes, the commit must be forced.
conflowgen/data/tools/
docs/notebooks/data/prepared_dbs/
.tools/
Empty file added .tools/.gitkeep
Empty file.
13 changes: 8 additions & 5 deletions conflowgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
InboundAndOutboundVehicleCapacityAnalysis
from conflowgen.analyses.inbound_and_outbound_vehicle_capacity_analysis_report import \
InboundAndOutboundVehicleCapacityAnalysisReport
from conflowgen.analyses.inbound_to_outbound_vehicle_capacity_utilization_analysis import \
InboundToOutboundVehicleCapacityUtilizationAnalysis
from conflowgen.analyses.inbound_to_outbound_vehicle_capacity_utilization_analysis_report import \
InboundToOutboundVehicleCapacityUtilizationAnalysisReport
from conflowgen.analyses.outbound_to_inbound_vehicle_capacity_utilization_analysis import \
OutboundToInboundVehicleCapacityUtilizationAnalysis
from conflowgen.analyses.outbound_to_inbound_vehicle_capacity_utilization_analysis_report import \
OutboundToInboundVehicleCapacityUtilizationAnalysisReport
from conflowgen.analyses.container_flow_by_vehicle_type_analysis import ContainerFlowByVehicleTypeAnalysis
from conflowgen.analyses.container_flow_by_vehicle_type_analysis_report import \
ContainerFlowByVehicleTypeAnalysisReport
Expand All @@ -64,6 +64,9 @@
ContainerFlowVehicleTypeAdjustmentPerVehicleAnalysis
from conflowgen.analyses.container_flow_vehicle_type_adjustment_per_vehicle_analysis_report import \
ContainerFlowVehicleTypeAdjustmentPerVehicleAnalysisReport
from conflowgen.analyses.container_flow_by_vehicle_instance_analysis import ContainerFlowByVehicleInstanceAnalysis
from conflowgen.analyses.container_flow_by_vehicle_instance_analysis_report import (
ContainerFlowByVehicleInstanceAnalysisReport)

# Cache for analyses and previews
from conflowgen.data_summaries.data_summaries_cache import DataSummariesCache
Expand All @@ -83,7 +86,7 @@
from conflowgen.domain_models.data_types.storage_requirement import StorageRequirement

# List of functions
from conflowgen.logging.logging import setup_logger
from conflowgen.log.log import setup_logger
from conflowgen.analyses import run_all_analyses
from conflowgen.previews import run_all_previews

Expand Down
8 changes: 5 additions & 3 deletions conflowgen/analyses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
ContainerFlowAdjustmentByVehicleTypeAnalysisReport
from .container_flow_adjustment_by_vehicle_type_analysis_summary_report import \
ContainerFlowAdjustmentByVehicleTypeAnalysisSummaryReport
from .container_flow_by_vehicle_instance_analysis_report import ContainerFlowByVehicleInstanceAnalysisReport
from .container_flow_by_vehicle_type_analysis_report import ContainerFlowByVehicleTypeAnalysisReport
from .container_flow_vehicle_type_adjustment_per_vehicle_analysis_report import \
ContainerFlowVehicleTypeAdjustmentPerVehicleAnalysisReport
from .inbound_and_outbound_vehicle_capacity_analysis_report import InboundAndOutboundVehicleCapacityAnalysisReport
from .inbound_to_outbound_vehicle_capacity_utilization_analysis_report import \
InboundToOutboundVehicleCapacityUtilizationAnalysisReport
from .outbound_to_inbound_vehicle_capacity_utilization_analysis_report import \
OutboundToInboundVehicleCapacityUtilizationAnalysisReport
from .modal_split_analysis_report import ModalSplitAnalysisReport
from .quay_side_throughput_analysis_report import QuaySideThroughputAnalysisReport
from .truck_gate_throughput_analysis_report import TruckGateThroughputAnalysisReport
Expand All @@ -26,6 +27,7 @@
reports: typing.Iterable[typing.Type[AbstractReport]] = [
InboundAndOutboundVehicleCapacityAnalysisReport,
ContainerFlowByVehicleTypeAnalysisReport,
ContainerFlowByVehicleInstanceAnalysisReport,
ContainerFlowAdjustmentByVehicleTypeAnalysisReport,
ContainerFlowAdjustmentByVehicleTypeAnalysisSummaryReport,
ContainerFlowVehicleTypeAdjustmentPerVehicleAnalysisReport,
Expand All @@ -34,7 +36,7 @@
QuaySideThroughputAnalysisReport,
TruckGateThroughputAnalysisReport,
YardCapacityAnalysisReport,
InboundToOutboundVehicleCapacityUtilizationAnalysisReport
OutboundToInboundVehicleCapacityUtilizationAnalysisReport
]


Expand Down
14 changes: 9 additions & 5 deletions conflowgen/analyses/abstract_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,39 @@ def _restrict_storage_requirement(selected_containers: ModelSelect, storage_requ
@staticmethod
def _restrict_container_delivered_by_vehicle_type(
selected_containers: ModelSelect, container_delivered_by_vehicle_type: typing.Any
) -> ModelSelect:
) -> (ModelSelect, list[ModeOfTransport]):
if hashable(container_delivered_by_vehicle_type) \
and container_delivered_by_vehicle_type in set(ModeOfTransport):
selected_containers = selected_containers.where(
Container.delivered_by == container_delivered_by_vehicle_type
)
list_of_vehicle_types = [container_delivered_by_vehicle_type]
else: # assume it is some kind of collection (list, set, ...)
selected_containers = selected_containers.where(
Container.delivered_by << container_delivered_by_vehicle_type
)
return selected_containers
list_of_vehicle_types = list(container_delivered_by_vehicle_type)
return selected_containers, list_of_vehicle_types

@staticmethod
def _restrict_container_picked_up_by_vehicle_type(
selected_containers: ModelSelect, container_picked_up_by_vehicle_type: typing.Any
) -> ModelSelect:
) -> (ModelSelect, list[ModeOfTransport]):
if container_picked_up_by_vehicle_type == "scheduled vehicles":
container_picked_up_by_vehicle_type = ModeOfTransport.get_scheduled_vehicles()

list_of_vehicle_types = container_picked_up_by_vehicle_type
if hashable(container_picked_up_by_vehicle_type) \
and container_picked_up_by_vehicle_type in set(ModeOfTransport):
selected_containers = selected_containers.where(
Container.picked_up_by == container_picked_up_by_vehicle_type
)
list_of_vehicle_types = [container_picked_up_by_vehicle_type]
else: # assume it is some kind of collection (list, set, ...)
selected_containers = selected_containers.where(
Container.picked_up_by << container_picked_up_by_vehicle_type
)
return selected_containers
list_of_vehicle_types = list(container_picked_up_by_vehicle_type)
return selected_containers, list_of_vehicle_types

@staticmethod
def _restrict_container_picked_up_by_initial_vehicle_type(
Expand Down
4 changes: 2 additions & 2 deletions conflowgen/analyses/container_dwell_time_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def get_container_dwell_times(
)

if container_delivered_by_vehicle_type != "all":
selected_containers = self._restrict_container_delivered_by_vehicle_type(
selected_containers, vehicle_types = self._restrict_container_delivered_by_vehicle_type(
selected_containers, container_delivered_by_vehicle_type
)

if container_picked_up_by_vehicle_type != "all":
selected_containers = self._restrict_container_picked_up_by_vehicle_type(
selected_containers, vehicle_types = self._restrict_container_picked_up_by_vehicle_type(
selected_containers, container_picked_up_by_vehicle_type
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self):

def get_report_as_text(self, **kwargs) -> str:
"""
The report as a text is represented as a table suitable for logging.
The report as a text is represented as a table suitable for log.
It uses a human-readable formatting style.
For the exact interpretation of the parameter, check
:meth:`.ContainerDwellTimeAnalysis.get_container_dwell_times`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_report_as_text(
self, **kwargs
) -> str:
"""
The report as a text is represented as a table suitable for logging.
The report as a text is represented as a table suitable for log.
It uses a human-readable formatting style.

Keyword Args:
Expand Down
125 changes: 125 additions & 0 deletions conflowgen/analyses/container_flow_by_vehicle_instance_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
from __future__ import annotations

import datetime
import typing

from peewee import ModelSelect

from conflowgen.data_summaries.data_summaries_cache import DataSummariesCache
from conflowgen.domain_models.container import Container
from conflowgen.domain_models.data_types.mode_of_transport import ModeOfTransport
from conflowgen.analyses.abstract_analysis import AbstractAnalysis
from conflowgen.descriptive_datatypes import VehicleIdentifier, FlowDirection


class ContainerFlowByVehicleInstanceAnalysis(AbstractAnalysis):
"""
This analysis can be run after the synthetic data has been generated.
The analysis returns a data structure that can be used for generating reports (e.g., in text or as a figure)
as it is the case with :class:`.ContainerFlowByVehicleInstanceAnalysisReport`.
"""

@DataSummariesCache.cache_result
def get_container_flow_by_vehicle(
self,
vehicle_types: typing.Collection[ModeOfTransport] = (
ModeOfTransport.train,
ModeOfTransport.feeder,
ModeOfTransport.deep_sea_vessel,
ModeOfTransport.barge
),
start_date: typing.Optional[datetime.datetime] = None,
end_date: typing.Optional[datetime.datetime] = None,
) -> [
ModeOfTransport, typing.Dict[VehicleIdentifier, typing.Dict[FlowDirection, (int, int)]]
]:
"""
Args:
vehicle_types: A collection of vehicle types, e.g., passed as a :class:`list` or :class:`set`.
Only the vehicles that correspond to the provided vehicle type(s) are considered in the analysis.
start_date:
The earliest arriving container that is included. Consider all containers if :obj:`None`.
end_date:
The latest departing container that is included. Consider all containers if :obj:`None`.

Returns:
Grouped by vehicle type and vehicle instance, how many import, export, and transshipment containers are
unloaded and loaded (measured in TEU).
"""

container_flow_by_vehicle: typing.Dict[
ModeOfTransport, typing.Dict[VehicleIdentifier,
typing.Dict[FlowDirection, typing.Dict[str, int]]]] = {
vehicle_type: {}
for vehicle_type in ModeOfTransport
}

vehicle_identifier_cache = {}

selected_containers: ModelSelect = Container.select().where(
(Container.delivered_by.in_(vehicle_types) | Container.picked_up_by.in_(vehicle_types))
)

container: Container
for container in selected_containers:
if start_date and container.get_arrival_time() < start_date:
continue
if end_date and container.get_departure_time() > end_date:
continue

if container.delivered_by_large_scheduled_vehicle is not None: # if not transported by truck

if container.delivered_by_large_scheduled_vehicle not in vehicle_identifier_cache:
vehicle_id_inbound = VehicleIdentifier(
id=container.delivered_by_large_scheduled_vehicle.id,
mode_of_transport=container.delivered_by,
service_name=container.delivered_by_large_scheduled_vehicle.schedule.service_name,
vehicle_name=container.delivered_by_large_scheduled_vehicle.vehicle_name,
vehicle_arrival_time=container.get_arrival_time(),
)
vehicle_identifier_cache[container.delivered_by_large_scheduled_vehicle] = vehicle_id_inbound

vehicle_id_inbound = vehicle_identifier_cache[container.delivered_by_large_scheduled_vehicle]

if vehicle_id_inbound not in container_flow_by_vehicle[container.delivered_by]:
container_flow_by_vehicle[container.delivered_by][vehicle_id_inbound] = {
flow_direction: {
"inbound": 0,
"outbound": 0,
}
for flow_direction in FlowDirection
}
container_flow_by_vehicle[
container.delivered_by
][vehicle_id_inbound][container.flow_direction]["inbound"] += container.occupied_teu

if container.picked_up_by_large_scheduled_vehicle is not None: # if not transported by truck

if container.picked_up_by_large_scheduled_vehicle not in vehicle_identifier_cache:
vehicle_id_outbound = VehicleIdentifier(
id=container.picked_up_by_large_scheduled_vehicle.id,
mode_of_transport=container.picked_up_by,
service_name=container.picked_up_by_large_scheduled_vehicle.schedule.service_name,
vehicle_name=container.picked_up_by_large_scheduled_vehicle.vehicle_name,
vehicle_arrival_time=container.get_departure_time(),
)
vehicle_identifier_cache[container.picked_up_by_large_scheduled_vehicle] = vehicle_id_outbound

vehicle_id_outbound = vehicle_identifier_cache[container.picked_up_by_large_scheduled_vehicle]

if vehicle_id_outbound not in container_flow_by_vehicle[container.picked_up_by]:
container_flow_by_vehicle[container.picked_up_by][vehicle_id_outbound] = {
flow_direction: {
"inbound": 0,
"outbound": 0,
}
for flow_direction in FlowDirection
}
container_flow_by_vehicle[
container.picked_up_by][vehicle_id_outbound][container.flow_direction]["outbound"] += 1

for skipped_vehicle_type in set(ModeOfTransport) - set(vehicle_types):
assert len(container_flow_by_vehicle[skipped_vehicle_type]) == 0
del container_flow_by_vehicle[skipped_vehicle_type]

return container_flow_by_vehicle
Loading
Loading