Skip to content

Commit

Permalink
blacken
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-sijia committed Jul 30, 2024
1 parent 55efcac commit 684c9d9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
14 changes: 7 additions & 7 deletions tm2py/components/network/transit/transit_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ def run(self):
if self.config.journey_levels.use_algorithm == True:
faresystem_groups = self.group_faresystems(faresystems)

if self.config.journey_levels.specify_manually ==True:
if self.config.journey_levels.specify_manually == True:
faresystem_groups = self.group_faresystems_simplified(faresystems)

journey_levels, mode_map = self.generate_transfer_fares(
Expand Down Expand Up @@ -1507,14 +1507,14 @@ def matching_xfer_fares(xfer_fares_list1, xfer_fares_list2):
self._log.append({"content": xfer_fares_table, "type": "table"})

return faresystem_groups

def group_faresystems_simplified(self, faresystems):
"""This function allows for manual specification of journey levels/ faresystem groups"""
self._log.append(
{"type": "header", "content": "Simplified faresystem groups"}
)
self._log.append({"type": "header", "content": "Simplified faresystem groups"})

manual_groups = [groups.group_fare_systems for groups in self.config.journey_levels.manual]
manual_groups = [
groups.group_fare_systems for groups in self.config.journey_levels.manual
]
group_xfer_fares_mode = [([], [], []) for _ in range(len(manual_groups) + 1)]

for fs_id, fs_data in faresystems.items():
Expand All @@ -1527,7 +1527,7 @@ def group_faresystems_simplified(self, faresystems):
group_xfer_fares_mode[i][1].append(fs_id)
group_xfer_fares_mode[i][2].extend(fs_modes)
assigned = True
break
break
if not assigned:
group_xfer_fares_mode[-1][0].append(xfers)
group_xfer_fares_mode[-1][1].append(fs_id)
Expand Down
30 changes: 18 additions & 12 deletions tm2py/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@ class TransitVehicleConfig(ConfigItem):
@dataclass(frozen=True)
class TransitClassConfig(ConfigItem):
"""Transit demand class definition."""

skim_set_id: str
name: str
description: str
Expand All @@ -1153,14 +1154,16 @@ class TransitClassConfig(ConfigItem):

@dataclass(frozen=True)
class ManualJourneyLevelsConfig(ConfigItem):
"""Manual Journey Level Specification"""
level_id: int
group_fare_systems: Tuple[int, ...]
"""Manual Journey Level Specification"""

level_id: int
group_fare_systems: Tuple[int, ...]


@dataclass(frozen=True)
class TransitJourneyLevelsConfig(ConfigItem):
"""Transit manual journey levels structure."""

use_algorithm: bool = False
"""
The original translation from Cube to Emme used an algorithm to, as faithfully as possible, reflect transfer fares via journey levels.
Expand All @@ -1177,8 +1180,10 @@ class TransitJourneyLevelsConfig(ConfigItem):
To specify this configuration, a single `manual` entry identifying the SF Muni fare systems is needed.
The other faresystem group is automatically generated in the code with the rest of the faresystems which are not specified in any of the groups.
See the `manual` entry for an example.
"""
manual: Optional[Tuple[ManualJourneyLevelsConfig, ...]] = (ManualJourneyLevelsConfig(level_id=1, group_fare_systems=(25,)),)
"""
manual: Optional[Tuple[ManualJourneyLevelsConfig, ...]] = (
ManualJourneyLevelsConfig(level_id=1, group_fare_systems=(25,)),
)
"""
If 'specify_manually' is set to `True`, there should be at least one faresystem group specified here.
The format includes two entries: `level_id`, which is the serial number of the group specified,
Expand All @@ -1197,23 +1202,25 @@ class TransitJourneyLevelsConfig(ConfigItem):
group_fare_systems = [12,14]
"""


@validator("specify_manually")
def check_exclusivity(cls, v, values):
"""Valdiates that exactly one of specify_manually and use_algorithm is True"""
use_algorithm = values.get("use_algorithm")
assert (use_algorithm != v), 'Exactly one of "use_algorithm" or "specify_manually" must be True.'
assert (
use_algorithm != v
), 'Exactly one of "use_algorithm" or "specify_manually" must be True.'
return v

@validator('manual', always=True)
@validator("manual", always=True)
def check_manual(cls, v, values):
if values.get('specify_manually'):
assert v is not None and len(v) > 0, "If 'specify_manually' is True, 'manual' cannot be None or empty."
if values.get("specify_manually"):
assert (
v is not None and len(v) > 0
), "If 'specify_manually' is True, 'manual' cannot be None or empty."
return v



@dataclass(frozen=True)
class AssignmentStoppingCriteriaConfig(ConfigItem):
"Assignment stop configuration parameters."
Expand Down Expand Up @@ -1266,7 +1273,6 @@ class CongestedAssnConfig(ConfigItem):
pm_peaking_factor: float = Field(default=1.262)



@dataclass(frozen=True)
class TransitConfig(ConfigItem):
"""Transit assignment parameters."""
Expand Down

0 comments on commit 684c9d9

Please sign in to comment.