trip_updated = True db_time = self.get_db_time_from_entry_time(entry) if trip_orm.time != db_time: logger.info("Update trip field time: {:s} -> {:s}".format( trip_orm.time, db_time)) trip_orm.time = db_time trip_updated = True trip_fields = [("city", "city"), ("departure_place", "departure_place"), ("departure_region", "departure_region"), ("departure_coordinate", "departure_coordinate"), ("arrival_place", "arrival_place"), ("arrival_region", "arrival_region"), ("arrival_coordinate", "arrival_coordinate"), ("duration", "duration"), ("distance", "distance"), ("note", "trip_note")] for orm_field, entry_field in trip_fields: orm_val, entry_val = getattr(trip_orm, orm_field), getattr( entry, entry_field) if orm_val != entry_val: logger.info("Update trip field {:s}: {:s} -> {:s}".format( str(orm_field), str(orm_val), str(entry_val))) setattr(trip_orm, orm_field, entry_val) trip_updated = True if trip_updated: self.session.commit() return trip_updated get_mobike_db_ops = singleton(MobikeDbOps)
route_orm = Route() route_orm.task = task_orm route_orm.departure = departure_orm route_orm.arrival = arrival_orm route_orm.train = train_orm route_orm.note = entry.note self.session.add(departure_orm) self.session.add(arrival_orm) self.session.add(route_orm) self.session.commit() return route_orm def add_route(self, input_entry: InputRouteEntry): route_entry = RouteEntry() route_entry.get_data_from_input_route_entry(input_entry) route_orm = self._get_route(route_entry) if route_orm is None: route_orm = self._add_route(route_entry) logger.info("Added route at {:s}.".format( route_orm.departure.time)) else: logger.info("Route exist at {:s}.".format( route_orm.departure.time)) def update_route(self, entry: InputRouteEntry): # TODO: update_route is not frequently used; implementation is postponed pass get_shm_db_ops = singleton(ShmDbOps)
self.city = "Shanghai" self.date_zero = "2013-07-01" self.test_mode = False def switch_to_test_configs(self): super().switch_to_test_configs() self.db_name = "ShanghaiMetroTrips.sqlite" test_folder = os.sep.join([self.root_folder, "test"]) self.db_path = os.sep.join( [test_folder, "database", self.module_name, self.db_name]) self.trip_xlsx_name = "ShanghaiMetroLog.xlsx" self.trip_xlsx_path = os.sep.join( [test_folder, "log", self.module_name, self.trip_xlsx_name]) self.stats_folder = os.sep.join( [test_folder, "report", self.module_name]) self.test_mode = True get_configs = helpers.singleton(ShmSysConfigs) def switch_to_test_mode(): configs: ShmSysConfigs = get_configs() configs.switch_to_test_configs() get_datetime_helper = helpers.singleton(helpers.DateTimeHelper, [get_configs().date_zero]) logger = helpers.transtory_logger.getChild("mobike")
elif name == 'CR400AF': sn_list = get_num_set_from_multiple_ranges([(2001, 2017), (2021, 2064)]) elif name == 'CR400BF 样车': sn_list = get_num_set_from_multiple_ranges([(503, 503), (507, 507)]) elif name == 'CR400BF': sn_list = get_num_set_from_multiple_ranges([(3001, 3023)]) else: raise ValueError('Invalid train type name.') type_train_map[name] = sn_list self.type_vs_train = type_train_map return type_train_map get_public_data = singleton(CrhPublicData) class CrhPublicDataApp(object): def __init__(self): self.public_data: CrhPublicData = get_public_data() self.configs: CrhSysConfigs = get_configs() def _get_stats_full_path(self, fname): return os.path.sep.join([self.configs.stats_folder, fname]) @staticmethod def _get_type_and_seq_from_train_sn(train_sn): return train_sn[:-5], int(train_sn[-4:]) def save_train_type_tree(self):
route_orm = Route() route_orm.seq = route_entry.segment_seq route_orm.type = route_entry.segment_type route_orm.flight = self.get_or_add_flight(route_entry.flight) route_orm.cabin = route_entry.cabin route_orm.seat = route_entry.seat route_orm.fare_code = route_entry.fare_code route_orm.boarding_group = route_entry.boarding_group route_orm.plane = self.get_or_add_plane(route_entry.plane, route_entry.plane_model) route_orm.distance_FA = route_entry.miles_from_FA route_orm.trip = trip_orm self.session.add(route_orm) for leg in route_entry.legs: self.add_leg(leg, route_orm) def add_trip(self, trip_entry: InputTripEntry, is_commit): trip_orm = Trip() trip_orm.confirmation_number = trip_entry.confirmation_num trip_orm.ticket_number = trip_entry.e_ticket_num trip_orm.price = trip_entry.price self.session.add(trip_orm) for segments in trip_entry.segments: self.add_route(segments, trip_orm) if is_commit: self.session.commit() return True get_db_ops = singleton(FlightDbOps)
bike_subtypes.append(["Light 1.2", "Light 1.x"]) # Light 1.3 bike_subtypes.append(["Light 1.3", "Light 1.x"]) # Light 1.4 bike_subtypes.append(["Light 1.4", "Light 1.x"]) # Light 2.x bike_subtypes.append(["Light 2.x", "Light 2.x"]) # Light 2.1 bike_subtypes.append(["Light 2.1", "Light 2.x"]) # Light 2.2 bike_subtypes.append(["Light 2.2", "Light 2.x"]) # Light 2.3 bike_subtypes.append(["Light 2.3", "Light 2.x"]) # Light 2.4 bike_subtypes.append(["Light 2.4", "Light 2.x"]) # Light 2.5 bike_subtypes.append(["Light 2.5", "Light 2.x"]) # Light 2.6 bike_subtypes.append(["Light 2.6", "Light 2.x"]) # Light 2.7 bike_subtypes.append(["Light 2.7", "Light 2.x"]) return bike_subtypes @staticmethod def get_city_eng_name(chn_name): city_name_map = {"上海": "Shanghai", "泰安": "Tai'an"} return city_name_map[chn_name] get_public_data = helpers.singleton(MobikePublicData)
start_orm = TicketStart() start_orm.station = self.get_or_add_station(ticket_entry.start) ticket_orm.start = start_orm end_orm = TicketEnd() end_orm.station = self.get_or_add_station(ticket_entry.end) ticket_orm.end = end_orm ticket_orm.note = ticket_entry.note ticket_orm.trip = trip_orm self.session.add(ticket_orm) return ticket_orm def _add_trip(self, trip_entry: InputTripEntry): trip_orm = Trip() trip_orm.task = self.get_or_add_task(trip_entry.task) trip_orm.line = self.get_or_add_line(trip_entry.train_num, trip_entry.train_num_start, trip_entry.train_num_final) trip_orm.note = trip_entry.note for ticket_entry in trip_entry.tickets: self._add_ticket(ticket_entry, trip_orm) for route_entry in trip_entry.routes: self._add_route(route_entry, trip_orm) return trip_orm def add_trip(self, trip_entry: InputTripEntry): self._add_trip(trip_entry) self.session.commit() return True get_db_ops = singleton(CrhDbOps)
from transtory.common import singleton class FlightPublicDataApp(object): def __init__(self): pass get_public_data_app = singleton(FlightPublicDataApp)