def __process_file(self, file_name):
     tcx = GarminDbTcx()
     tcx.read(file_name)
     start_time = tcx.start_time
     (manufacturer, product) = tcx.get_manufacturer_and_product()
     serial_number = tcx.serial_number
     device = {
         'serial_number': serial_number,
         'timestamp': start_time,
         'manufacturer': manufacturer,
         'product': product,
         'hardware_version': None,
     }
     GarminDB.Device.s_insert_or_update(self.garmin_db_session,
                                        device,
                                        ignore_none=True)
     root_logger.info(
         "Processing file: %s for manufacturer %s product %s device %s",
         file_name, manufacturer, product, serial_number)
     (file_id, file_name) = GarminDB.File.name_and_id_from_path(file_name)
     file = {
         'id': file_id,
         'name': file_name,
         'type': GarminDB.File.FileType.tcx,
         'serial_number': serial_number,
     }
     GarminDB.File.s_insert_or_update(self.garmin_db_session, file)
     activity = {
         'activity_id': file_id,
         'start_time': start_time,
         'stop_time': tcx.end_time,
         'laps': tcx.lap_count,
         'sport': tcx.sport,
         'calories': tcx.calories,
         'distance': tcx.distance.kms_or_miles(self.measurement_system),
         'avg_hr': tcx.hr_avg,
         'max_hr': tcx.hr_max,
         'max_cadence': tcx.cadence_max,
         'avg_cadence': tcx.cadence_avg,
         'ascent': tcx.ascent.meters_or_feet(self.measurement_system),
         'descent': tcx.descent.meters_or_feet(self.measurement_system)
     }
     start_loc = tcx.start_loc
     if start_loc is not None:
         activity.update({
             'start_lat': start_loc.lat_deg,
             'start_long': start_loc.long_deg
         })
     end_loc = tcx.end_loc
     if end_loc is not None:
         activity.update({
             'stop_lat': end_loc.lat_deg,
             'stop_long': end_loc.long_deg
         })
     GarminDB.Activities.s_insert_or_update(self.garmin_act_db_session,
                                            activity,
                                            ignore_none=True,
                                            ignore_zero=True)
     for lap_number, lap in enumerate(tcx.laps):
         self.__process_lap(tcx, file_id, lap_number, lap)
Beispiel #2
0
 def check_activity_file(self, filename):
     tcx = GarminDbTcx()
     tcx.read(filename)
     (manufacturer, product) = tcx.get_manufacturer_and_product()
     logger.info(
         "%s: sport %r end_time %r start_time %r manufacturer %r product %r serial_number %r laps %r distance %r calories %r start %r end %r "
         "hr %r, %r max speed %r cadence %r, %r", filename, tcx.sport,
         tcx.end_time, tcx.start_time, manufacturer, product,
         tcx.serial_number, tcx.lap_count, tcx.distance, tcx.calories,
         tcx.start_loc, tcx.end_loc, tcx.hr_avg, tcx.hr_max, tcx.speed_max,
         tcx.cadence_avg, tcx.cadence_max)
     self.assertGreater(tcx.end_time, tcx.start_time)
     self.assertGreater(tcx.lap_count, 0)