city_retrofit/city_model_structure/transport/phase.py

135 lines
3.1 KiB
Python
Raw Normal View History

"""
Phase module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2021 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Contributor Milad milad.aghamohamadnia@concordia.ca
"""
2021-09-14 13:46:48 -04:00
from typing import List, Union
class Phase:
"""
Phase class
"""
def __init__(self):
self._duration = None
self._state = None
self._min_duration = None
self._max_duration = None
self._name = None
self._next = None
@property
2021-09-14 13:46:48 -04:00
def duration(self) -> Union[None, int]:
"""
Get phase duration in seconds
2021-09-14 13:46:48 -04:00
:return: None or int
"""
return self._duration
@duration.setter
def duration(self, value):
"""
Set phase duration in seconds
:param value: int
"""
2021-09-14 13:46:48 -04:00
if value is not None:
self._duration = int(value)
@property
2021-09-14 13:46:48 -04:00
def state(self) -> Union[None, List[str]]:
"""
Get the list of signal states
2021-09-14 13:46:48 -04:00
:return: None or [str]
"""
return self._state
@state.setter
def state(self, value):
"""
Set the list of signal states
:param value: [str]
"""
2021-09-14 13:46:48 -04:00
if value is not None:
self._state = [str(i) for i in value]
@property
2021-09-14 13:46:48 -04:00
def min_duration(self) -> Union[None, int]:
"""
Get phase minimum duration in seconds
2021-09-14 13:46:48 -04:00
:return: None or int
"""
if self._min_duration is None:
self._min_duration = self._duration
return self._min_duration
@min_duration.setter
def min_duration(self, value):
"""
Set phase minimum duration in seconds
:param value: int
"""
2021-09-14 13:46:48 -04:00
if value is not None:
self._min_duration = int(value)
@property
2021-09-14 13:46:48 -04:00
def max_duration(self) -> Union[None, int]:
"""
Get phase maximum duration in seconds
2021-09-14 13:46:48 -04:00
:return: None or int
"""
if self._max_duration is None:
self._max_duration = self._duration
return self._max_duration
@max_duration.setter
def max_duration(self, value):
"""
Set phase maximum duration in seconds
:param value: int
"""
2021-09-14 13:46:48 -04:00
if value is not None:
self._max_duration = int(value)
@property
2021-09-14 13:46:48 -04:00
def name(self) -> Union[None, str]:
"""
Get phase name
2021-09-14 13:46:48 -04:00
:return: None or str
"""
return self._name
@name.setter
def name(self, value):
"""
Set phase name
:param value: str
"""
2021-09-14 13:46:48 -04:00
if value is not None:
self._name = str(value)
@property
2021-09-14 13:46:48 -04:00
def next(self) -> Union[None, List[int]]:
"""
Get the next phase in the cycle after the current.
This is useful when adding extra transition phases to a traffic light plan which are not part of every cycle.
Traffic lights of type 'actuated' can make use of a list of indices for selecting among alternative
successor phases.
2021-09-14 13:46:48 -04:00
:return: None or [int]
"""
return self._next
@next.setter
def next(self, value):
"""
Get the next phase in the cycle after the current.
This is useful when adding extra transition phases to a traffic light plan which are not part of every cycle.
Traffic lights of type 'actuated' can make use of a list of indices for selecting among alternative
successor phases.
:param value: [int]
"""
2021-09-14 13:46:48 -04:00
if value is not None:
self._next = [int(i) for i in value]