Skip to content

Commit

Permalink
Two attributes added with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kadhikari committed Dec 17, 2024
1 parent 72018b0 commit 131db1f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class TravelerProfilesSerializer(serpy.Serializer):
max_bss_direct_path_duration = Field(schema_type=int)
max_car_direct_path_duration = Field(schema_type=int)
max_ridesharing_direct_path_duration = Field(schema_type=int)
max_taxi_direct_path_duration = Field(schema_type=int)
max_car_no_park_direct_path_duration = Field(schema_type=int)


class AutocompleteSerializer(serpy.DictSerializer):
Expand Down
18 changes: 13 additions & 5 deletions source/jormungandr/jormungandr/travelers_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ def __init__(
max_car_duration_to_pt=15 * 60, # type: int
walking_step_penalty=30.0, # type: float
walking_use_hills=0.5, # type: float
max_walking_direct_path_duration=24 * 60 * 60, # type: int
max_bike_direct_path_duration=24 * 60 * 60, # type: int
max_bss_direct_path_duration=24 * 60 * 60, # type: int
max_car_direct_path_duration=24 * 60 * 60, # type: int
max_ridesharing_direct_path_duration=24 * 60 * 60, # type: int
max_walking_direct_path_duration=60 * 60, # type: int
max_bike_direct_path_duration=60 * 60, # type: int
max_bss_direct_path_duration=60 * 60, # type: int
max_car_direct_path_duration=40 * 60, # type: int
max_ridesharing_direct_path_duration=60 * 60, # type: int
max_taxi_direct_path_duration=60 * 60, # type: int
max_car_no_park_direct_path_duration=30 * 60, # type: int
traveler_type='', # type: Text
is_from_db=False, # type: bool
):
Expand Down Expand Up @@ -101,6 +103,8 @@ def __init__(
self.max_bss_direct_path_duration = max_bss_direct_path_duration
self.max_car_direct_path_duration = max_car_direct_path_duration
self.max_ridesharing_direct_path_duration = max_ridesharing_direct_path_duration
self.max_taxi_direct_path_duration = max_taxi_direct_path_duration
self.max_car_no_park_direct_path_duration = max_car_no_park_direct_path_duration

self.wheelchair = wheelchair

Expand All @@ -127,6 +131,8 @@ def override_params(self, args):
('max_bss_direct_path_duration', self.max_bss_direct_path_duration),
('max_car_direct_path_duration', self.max_car_direct_path_duration),
('max_ridesharing_direct_path_duration', self.max_ridesharing_direct_path_duration),
('max_taxi_direct_path_duration', self.max_taxi_direct_path_duration),
('max_car_no_park_direct_path_duration', self.max_car_no_park_direct_path_duration),
)

def override(pair):
Expand Down Expand Up @@ -181,6 +187,8 @@ def make_traveler_profile(cls, coverage, traveler_type):
max_bss_direct_path_duration=model.max_bss_direct_path_duration,
max_car_direct_path_duration=model.max_car_direct_path_duration,
max_ridesharing_direct_path_duration=model.max_ridesharing_direct_path_duration,
max_taxi_direct_path_duration=model.max_taxi_direct_path_duration,
max_car_no_park_direct_path_duration=model.max_car_no_park_direct_path_duration,
is_from_db=True,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@
'last_section_mode': ['walking', 'bss', 'bike'],
'walking_step_penalty': 30.0,
'walking_use_hills': 0.5,
'max_walking_direct_path_duration': 24 * 60 * 60,
'max_bike_direct_path_duration': 24 * 60 * 60,
'max_bss_direct_path_duration': 24 * 60 * 60,
'max_car_direct_path_duration': 24 * 60 * 60,
'max_ridesharing_direct_path_duration': 24 * 60 * 60,
'max_walking_direct_path_duration': 60 * 60,
'max_bike_direct_path_duration': 60 * 60,
'max_bss_direct_path_duration': 60 * 60,
'max_car_direct_path_duration': 40 * 60,
'max_ridesharing_direct_path_duration': 60 * 60,
'max_taxi_direct_path_duration': 60 * 60,
'max_car_no_park_direct_path_duration': 30 * 60,
},
'slow_walker': {
'traveler_type': 'slow_walker',
Expand All @@ -63,11 +65,13 @@
'last_section_mode': ['walking', 'bss', 'bike'],
'walking_step_penalty': 30.0,
'walking_use_hills': 0.5,
'max_walking_direct_path_duration': 24 * 60 * 60,
'max_bike_direct_path_duration': 24 * 60 * 60,
'max_bss_direct_path_duration': 24 * 60 * 60,
'max_car_direct_path_duration': 24 * 60 * 60,
'max_ridesharing_direct_path_duration': 24 * 60 * 60,
'max_walking_direct_path_duration': 60 * 60,
'max_bike_direct_path_duration': 60 * 60,
'max_bss_direct_path_duration': 60 * 60,
'max_car_direct_path_duration': 40 * 60,
'max_ridesharing_direct_path_duration': 60 * 60,
'max_taxi_direct_path_duration': 60 * 60,
'max_car_no_park_direct_path_duration': 30 * 60,
},
'fast_walker': {
'traveler_type': 'fast_walker',
Expand All @@ -83,11 +87,13 @@
'last_section_mode': ['walking', 'bss', 'bike'],
'walking_step_penalty': 30.0,
'walking_use_hills': 0.5,
'max_walking_direct_path_duration': 24 * 60 * 60,
'max_bike_direct_path_duration': 24 * 60 * 60,
'max_bss_direct_path_duration': 24 * 60 * 60,
'max_car_direct_path_duration': 24 * 60 * 60,
'max_ridesharing_direct_path_duration': 24 * 60 * 60,
'max_walking_direct_path_duration': 60 * 60,
'max_bike_direct_path_duration': 60 * 60,
'max_bss_direct_path_duration': 60 * 60,
'max_car_direct_path_duration': 40 * 60,
'max_ridesharing_direct_path_duration': 60 * 60,
'max_taxi_direct_path_duration': 60 * 60,
'max_car_no_park_direct_path_duration': 30 * 60,
},
'luggage': {
'traveler_type': 'luggage',
Expand All @@ -104,11 +110,13 @@
'wheelchair': True,
'walking_step_penalty': 3600.0,
'walking_use_hills': 0,
'max_walking_direct_path_duration': 24 * 60 * 60,
'max_bike_direct_path_duration': 24 * 60 * 60,
'max_bss_direct_path_duration': 24 * 60 * 60,
'max_car_direct_path_duration': 24 * 60 * 60,
'max_ridesharing_direct_path_duration': 24 * 60 * 60,
'max_walking_direct_path_duration': 60 * 60,
'max_bike_direct_path_duration': 60 * 60,
'max_bss_direct_path_duration': 60 * 60,
'max_car_direct_path_duration': 40 * 60,
'max_ridesharing_direct_path_duration': 60 * 60,
'max_taxi_direct_path_duration': 60 * 60,
'max_car_no_park_direct_path_duration': 30 * 60,
},
'wheelchair': {
'traveler_type': 'wheelchair',
Expand All @@ -125,11 +133,13 @@
'wheelchair': True,
'walking_step_penalty': 3600.0,
'walking_use_hills': 0,
'max_walking_direct_path_duration': 24 * 60 * 60,
'max_bike_direct_path_duration': 24 * 60 * 60,
'max_bss_direct_path_duration': 24 * 60 * 60,
'max_car_direct_path_duration': 24 * 60 * 60,
'max_ridesharing_direct_path_duration': 24 * 60 * 60,
'max_walking_direct_path_duration': 60 * 60,
'max_bike_direct_path_duration': 60 * 60,
'max_bss_direct_path_duration': 60 * 60,
'max_car_direct_path_duration': 40 * 60,
'max_ridesharing_direct_path_duration': 60 * 60,
'max_taxi_direct_path_duration': 60 * 60,
'max_car_no_park_direct_path_duration': 30 * 60,
},
# Temporary Profile
'cyclist': {
Expand All @@ -146,11 +156,13 @@
'last_section_mode': ['walking', 'bss'],
'walking_step_penalty': 30.0,
'walking_use_hills': 0.5,
'max_walking_direct_path_duration': 24 * 60 * 60,
'max_bike_direct_path_duration': 24 * 60 * 60,
'max_bss_direct_path_duration': 24 * 60 * 60,
'max_car_direct_path_duration': 24 * 60 * 60,
'max_ridesharing_direct_path_duration': 24 * 60 * 60,
'max_walking_direct_path_duration': 60 * 60,
'max_bike_direct_path_duration': 60 * 60,
'max_bss_direct_path_duration': 60 * 60,
'max_car_direct_path_duration': 40 * 60,
'max_ridesharing_direct_path_duration': 60 * 60,
'max_taxi_direct_path_duration': 60 * 60,
'max_car_no_park_direct_path_duration': 30 * 60,
},
# Temporary Profile
'motorist': {
Expand All @@ -167,11 +179,13 @@
'last_section_mode': ['walking'],
'walking_step_penalty': 30.0,
'walking_use_hills': 0.5,
'max_walking_direct_path_duration': 24 * 60 * 60,
'max_bike_direct_path_duration': 24 * 60 * 60,
'max_bss_direct_path_duration': 24 * 60 * 60,
'max_car_direct_path_duration': 24 * 60 * 60,
'max_ridesharing_direct_path_duration': 24 * 60 * 60,
'max_walking_direct_path_duration': 60 * 60,
'max_bike_direct_path_duration': 60 * 60,
'max_bss_direct_path_duration': 60 * 60,
'max_car_direct_path_duration': 40 * 60,
'max_ridesharing_direct_path_duration': 60 * 60,
'max_taxi_direct_path_duration': 60 * 60,
'max_car_no_park_direct_path_duration': 30 * 60,
},
}

Expand Down
14 changes: 14 additions & 0 deletions source/navitiacommon/navitiacommon/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,20 @@ class TravelerProfile(db.Model): # type: ignore
server_default=str(default_values.max_ridesharing_direct_path_duration),
)

max_taxi_direct_path_duration = db.Column(
db.Integer,
default=default_values.max_taxi_direct_path_duration,
nullable=False,
server_default=str(default_values.max_taxi_direct_path_duration),
)

max_car_no_park_direct_path_duration = db.Column(
db.Integer,
default=default_values.max_car_no_park_direct_path_duration,
nullable=False,
server_default=str(default_values.max_car_no_park_direct_path_duration),
)

@classmethod
def get_by_coverage_and_type(cls, coverage, traveler_type):
model = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ def upgrade():
'traveler_profile',
sa.Column('max_ridesharing_direct_path_duration', sa.Integer(), server_default='86400', nullable=False),
)
op.add_column(
'traveler_profile',
sa.Column('max_taxi_direct_path_duration', sa.Integer(), server_default='86400', nullable=False),
)
op.add_column(
'traveler_profile',
sa.Column('max_car_no_park_direct_path_duration', sa.Integer(), server_default='86400', nullable=False),
)


def downgrade():
Expand Down Expand Up @@ -138,3 +146,5 @@ def downgrade():
op.drop_column('traveler_profile', 'max_bss_direct_path_duration')
op.drop_column('traveler_profile', 'max_car_direct_path_duration')
op.drop_column('traveler_profile', 'max_ridesharing_direct_path_duration')
op.drop_column('traveler_profile', 'max_taxi_direct_path_duration')
op.drop_column('traveler_profile', 'max_car_no_park_direct_path_duration')
12 changes: 7 additions & 5 deletions source/tyr/tests/integration/instance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,11 @@ def test_create_traveler_profile(create_instance, traveler_profile_params):
check_traveler_profile(resp[0], traveler_profile_params)

# Let's check some attributes absent in traveler_profile_params
# They should have default value of database
assert resp[0]['max_car_direct_path_duration'] == 24 * 60 * 60
assert resp[0]['max_ridesharing_direct_path_duration'] == 24 * 60 * 60
# They should have default value of default_traveler_profile_params
assert resp[0]['max_car_direct_path_duration'] == 40 * 60
assert resp[0]['max_ridesharing_direct_path_duration'] == 60 * 60
assert resp[0]['max_taxi_direct_path_duration'] == 60 * 60
assert resp[0]['max_car_no_park_direct_path_duration'] == 30 * 60

# Those present in traveler_profile_params should have values as declared
assert resp[0]['walking_use_hills'] == 0.5
Expand All @@ -422,8 +424,8 @@ def test_update_traveler_profile(create_instance, traveler_profile_params):

# Let's check some attributes absent in traveler_profile_params
# They should have default value of database
assert resp[0]['max_car_direct_path_duration'] == 24 * 60 * 60
assert resp[0]['max_ridesharing_direct_path_duration'] == 24 * 60 * 60
assert resp[0]['max_car_direct_path_duration'] == 40 * 60
assert resp[0]['max_ridesharing_direct_path_duration'] == 60 * 60

# Those present in traveler_profile_params should have values as declared
assert resp[0]['walking_use_hills'] == 0.5
Expand Down
2 changes: 2 additions & 0 deletions source/tyr/tyr/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def format(self, value):
'max_bss_direct_path_duration': fields.Raw,
'max_car_direct_path_duration': fields.Raw,
'max_ridesharing_direct_path_duration': fields.Raw,
'max_taxi_direct_path_duration': fields.Raw,
'max_car_no_park_direct_path_duration': fields.Raw,
'error': fields.String,
}

Expand Down

0 comments on commit 131db1f

Please sign in to comment.