1
1
from dataclasses import dataclass , field
2
- from typing import List
2
+ from typing import Union
3
3
4
4
from osrd_schemas .train_schedule import (
5
- Allowance ,
6
5
AllowanceDistribution ,
7
6
AllowancePercentValue ,
8
7
AllowanceTimePerDistanceValue ,
17
16
18
17
def _train_id ():
19
18
# pytype: disable=name-error
20
- res = f"train.{ TrainSchedule ._INDEX } "
21
- TrainSchedule ._INDEX += 1
19
+ res = f"train.{ TrainSchedule ._index } "
20
+ TrainSchedule ._index += 1
22
21
# pytype: enable=name-error
23
22
return res
24
23
@@ -29,10 +28,12 @@ class TrainSchedule:
29
28
rolling_stock : str = field (default = "fast_rolling_stock" )
30
29
departure_time : float = field (default = 0.0 )
31
30
initial_speed : float = field (default = 0.0 )
32
- stops : List [Stop ] = field (default_factory = list )
33
- allowances : List [Allowance ] = field (default_factory = list )
31
+ stops : list [Stop ] = field (default_factory = list )
32
+ allowances : list [Union [EngineeringAllowance , StandardAllowance ]] = field (
33
+ default_factory = list
34
+ )
34
35
35
- _INDEX = 0
36
+ _index = 0
36
37
37
38
def add_stop (self , * args , ** kwargs ):
38
39
stop = Stop (* args , ** kwargs )
@@ -54,18 +55,18 @@ def add_standard_single_value_allowance(
54
55
"""Add a standard allowance with a single value. For more information on allowances, see
55
56
the documentation of the Allowance class in osrd_schemas."""
56
57
if value_type == "time" :
57
- value = AllowanceTimeValue (seconds = value )
58
+ allowance = AllowanceTimeValue (seconds = value )
58
59
elif value_type == "time_per_distance" :
59
- value = AllowanceTimePerDistanceValue (minutes = value )
60
+ allowance = AllowanceTimePerDistanceValue (minutes = value )
60
61
elif value_type == "percentage" :
61
- value = AllowancePercentValue (percentage = value )
62
+ allowance = AllowancePercentValue (percentage = value )
62
63
else :
63
64
raise ValueError (f"Unknown value kind { value_type } " )
64
65
65
66
distribution = AllowanceDistribution (distribution )
66
67
67
68
self .add_allowance (
68
- default_value = value ,
69
+ default_value = allowance ,
69
70
distribution = distribution ,
70
71
ranges = [],
71
72
capacity_speed_limit = - 1 ,
@@ -86,8 +87,8 @@ def format(self):
86
87
87
88
def _group_id ():
88
89
# pytype: disable=name-error
89
- res = f"group.{ TrainScheduleGroup ._INDEX } "
90
- TrainScheduleGroup ._INDEX += 1
90
+ res = f"group.{ TrainScheduleGroup ._index } "
91
+ TrainScheduleGroup ._index += 1
91
92
# pytype: enable=name-error
92
93
return res
93
94
@@ -96,11 +97,11 @@ def _group_id():
96
97
class TrainScheduleGroup :
97
98
"""A group of train schedules that share the same waypoints."""
98
99
99
- schedules : List [TrainSchedule ] = field (default_factory = list )
100
- waypoints : List [ List [DirectedLocation ]] = field (default_factory = list )
100
+ schedules : list [TrainSchedule ] = field (default_factory = list )
101
+ waypoints : list [ list [DirectedLocation ]] = field (default_factory = list )
101
102
id : str = field (default_factory = _group_id )
102
103
103
- _INDEX = 0
104
+ _index = 0
104
105
105
106
def format (self ):
106
107
return {
0 commit comments