2022-09-23 23:58:45 +03:00
from pyrmv . classes . Leg import Leg
from pyrmv . classes . Stop import StopTrip
from isodate import parse_duration
class Trip ( ) :
2022-10-05 13:17:51 +03:00
""" Trip object. """
2022-09-23 23:58:45 +03:00
def __init__ ( self , data : dict ) :
2022-09-24 13:08:16 +03:00
2022-09-23 23:58:45 +03:00
self . raw_data = data
self . origin = StopTrip ( data [ " Origin " ] )
self . destination = StopTrip ( data [ " Destination " ] )
2022-09-24 13:08:16 +03:00
self . legs = [ ]
2022-09-23 23:58:45 +03:00
for leg in data [ " LegList " ] [ " Leg " ] :
2022-09-24 13:08:16 +03:00
self . legs . append ( Leg ( leg ) )
2022-09-23 23:58:45 +03:00
self . calculation = data [ " calculation " ]
self . index = data [ " idx " ]
self . id = data [ " tripId " ]
self . ctx_recon = data [ " ctxRecon " ]
self . duration = parse_duration ( data [ " duration " ] )
2022-09-24 14:07:58 +03:00
if " rtDuration " in data :
self . real_time_duration = parse_duration ( data [ " rtDuration " ] )
else :
self . real_time_duration = None
2022-09-23 23:58:45 +03:00
self . checksum = data [ " checksum " ]
2022-09-24 14:07:58 +03:00
if " transferCount " in data :
self . transfer_count = data [ " transferCount " ]
else :
self . transfer_count = 0
2022-09-23 23:58:45 +03:00
def __str__ ( self ) - > str :
return f " Trip from { self . origin . name } to { self . destination . name } lasting { self . duration } ( { self . real_time_duration } ) with { len ( self . legs ) } legs and { self . transfer_count } transfers "