def main(args=None): options = parse_args(args) frames = [] try: with fitdecode.FitReader( options.infile, processor=fitdecode.StandardUnitsDataProcessor(), check_crc=options.nocrc, keep_raw_chunks=True) as fit: for frame in fit: if options.nodef and isinstance( frame, fitdecode.FitDefinitionMessage): continue if (options.filter and isinstance( frame, (fitdecode.FitDefinitionMessage, fitdecode.FitDataMessage)) and (frame.name not in options.filter) and (frame.global_mesg_num not in options.filter)): continue frames.append(frame) except Exception: print( 'WARNING: the following error occurred while parsing FIT file. ' 'Output file might be incomplete or corrupted.', file=sys.stderr) print('', file=sys.stderr) traceback.print_exc() json.dump(frames, fp=options.output, cls=RecordJSONEncoder) return 0
def retrieve_data(file_path, log_file): dat = [] session = [] try: with fitdecode.FitReader( file_path, processor=fitdecode.StandardUnitsDataProcessor()) as fit: for frame in fit: r = {} s = {} if isinstance(frame, fitdecode.FitDataMessage): if frame.name == 'record': for name in data_fields: if frame.has_field(name): r[name] = frame.get_value(name) dat.append(r) if frame.name == 'session': for name in session_fields: if frame.has_field(name): s[name] = frame.get_value(name) session.append(s) df = pd.DataFrame(dat) sf = pd.DataFrame(session) with open(log_file, 'a+') as log: log.write('\nThe .fit file was read in...') return df, sf except Exception as e: with open(log_file, 'a+') as log: log.write( f'\nSomething went wrong while trying to read in the .fit file. Exception raised: {e}' )
def main(args=None): options = parse_args(args) def _echo(*objects, sep=' ', end='\n', file=options.output, flush=False): print(*objects, sep=sep, end=end, file=file, flush=flush) def _echo_separator(): _echo('') _echo('*' * 80) _echo('') _echo('') global echo echo = _echo # fully parse input file and filter out the unwanted messages frames = [] with fitdecode.FitReader(options.infile, processor=fitdecode.StandardUnitsDataProcessor(), check_crc=not (options.nocrc), keep_raw_chunks=True) as fit: for frame in fit: if options.nodef and isinstance(frame, fitdecode.FitDefinitionMessage): continue if (options.filter and isinstance( frame, (fitdecode.FitDefinitionMessage, fitdecode.FitDataMessage)) and (frame.name not in options.filter) and (frame.global_mesg_num not in options.filter)): continue frames.append(frame) # print some statistics before starting txt_print(global_stats(frames, options)) echo('') # pretty-print the file had_frames = False for frame in frames: if had_frames and isinstance(frame, fitdecode.FitHeader): _echo_separator() had_frames = True txt_print(frame) echo('')
def test_fitparse_units_processor(self): for x in ('2013-02-06-12-11-14.fit', '2015-10-13-08-43-15.fit', 'Activity.fit', 'Edge810-Vector-2013-08-16-15-35-10.fit', 'MonitoringFile.fit', 'Settings.fit', 'Settings2.fit', 'WeightScaleMultiUser.fit', 'WeightScaleSingleUser.fit', 'WorkoutCustomTargetValues.fit', 'WorkoutIndividualSteps.fit', 'WorkoutRepeatGreaterThanStep.fit', 'WorkoutRepeatSteps.fit', 'activity-large-fenxi2-multisport.fit', 'activity-small-fenix2-run.fit', 'antfs-dump.63.fit', 'sample-activity-indoor-trainer.fit', 'sample-activity.fit', 'garmin-fenix-5-bike.fit', 'garmin-fenix-5-run.fit', 'garmin-fenix-5-walk.fit', 'garmin-edge-820-bike.fit'): tuple( fitdecode.FitReader( _test_file(x), processor=fitdecode.StandardUnitsDataProcessor()))
def main(args=None): options = parse_args(args) frames = [] with fitdecode.FitReader(options.infile, processor=fitdecode.StandardUnitsDataProcessor(), check_crc=not (options.nocrc), keep_raw_chunks=True) as fit: for frame in fit: if options.nodef and isinstance(frame, fitdecode.FitDefinitionMessage): continue if (options.filter and isinstance( frame, (fitdecode.FitDefinitionMessage, fitdecode.FitDataMessage)) and (frame.name not in options.filter) and (frame.global_mesg_num not in options.filter)): continue frames.append(frame) json.dump(frames, fp=options.output, cls=RecordJSONEncoder)
def main(args=None): options = parse_args(args) def _echo(*objects, sep=' ', end='\n', file=options.output, flush=False): print(*objects, sep=sep, end=end, file=file, flush=flush) def _echo_separator(): _echo('') _echo('*' * 80) _echo('') _echo('') global echo echo = _echo # fully parse input file and filter out the unwanted messages frames = [] exception_msg = None try: with fitdecode.FitReader( options.infile, processor=fitdecode.StandardUnitsDataProcessor(), check_crc=options.nocrc, keep_raw_chunks=True) as fit: for frame in fit: if options.nodef and isinstance( frame, fitdecode.FitDefinitionMessage): continue if (options.filter and isinstance(frame, ( fitdecode.FitDefinitionMessage, fitdecode.FitDataMessage)) and (frame.name not in options.filter) and (frame.global_mesg_num not in options.filter)): continue frames.append(frame) except Exception: print( 'WARNING: error(s) occurred while parsing FIT file. ' 'See output file for more info.', file=sys.stderr) exception_msg = traceback.format_exc() # print some statistics as a header if not exception_msg: txt_print(global_stats(frames, options)) echo('') else: echo('ERROR OCCURRED WHILE PARSING', options.infile.name) echo('') echo(exception_msg) echo('') # pretty-print the file had_frames = False for frame in frames: if had_frames and isinstance(frame, fitdecode.FitHeader): _echo_separator() had_frames = True txt_print(frame) echo('') return 0