('-' * name_size, '-' * num_size, '-' * date_size, '-' * date_size)) # save the total for last for name in sorted(data.keys()): if name != total_key: print(line_format % (name, data[name]['records'], data[name]['min'], data[name]['max'])) name = total_key print(line_format % ('-' * name_size, '-' * num_size, '-' * date_size, '-' * date_size)) print(line_format % (name, data[name]['records'], data[name]['min'], data[name]['max'])) options = get_command_options( 'none', 'Show ranges in a data file. Input on stdin. Output to stdout.') verbose = int(options['verbose']) error, data = read_framer_results() if error: print(error, file=sys.stderr) sys.exit(1) results = dict() results['total'] = dict() results['total']['records'] = 0 results['total']['min'] = '' results['total']['max'] = '' total_first_time = True
# Input on stdin # Output to stdout # Copyright John Andrea, 2019 import sys import os # setup a few library files dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(dir_path + '/lib/') from framer_util import get_header_key, get_command_options, read_framer_results, get_final_float_format options = get_command_options( 'viewer', 'View output from framer. Input on stdin. Output to stdout as tsv.') verbose = int(options['verbose']) is_separate_style = (options['style'].lower().strip() != 'combined') error, data = read_framer_results() if error: print(error, file=sys.stderr) sys.exit(1) # the output will be tab separated # get all the timestamps to be sorted that way # all the field names # all the instruments
# do the testing with the time added time = date + ' 00:00:00' if string_looks_like_time(time): if not is_valid_timestamp_string(time): error += title + ' date is not a valid date.\n' else: error += title + ' date does not appear to be a date YYYY-MM-DD.' error += ' Note that only dates should be specified, without time.\n' return error options = get_command_options( 'date-select', 'Exclude data outside the specified range. Input on stdin. Output to stdout.' ) min_date = options['mindate'] max_date = options['maxdate'] verbose = int(options['verbose']) error = '' error += date_is_ok('Minimum', min_date) error += date_is_ok('Maximum', max_date) if error: print(error, file=sys.stderr) sys.exit(1) else: if min_date > max_date:
# # Copyright John Andrea, 2019 import sys import os import json import copy # setup a few library files dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(dir_path + '/lib/') from framer_util import get_command_options, get_header_key, read_framer_results_from_file, read_framer_results_allow_empty_stdin options = get_command_options( 'multi-files', 'Join data files. Input on stdin and/or command line. Output to stdout.') verbose = int(options['verbose']) files = options['files'] header_key = get_header_key() # treat the file from stdin as rhe first file error, data = read_framer_results_allow_empty_stdin() if error: print(error, file=sys.stderr) sys.exit(1) # get the others which might occur on the command line
# each minute set to fit withing previous interval # i.e. if interval = 20 # 0 to 19 -> 00, 20 to 39 -> 20, 40 to 59 -> 40 # initialize zero to prevent the modulus being off by 1 lookup.append( '00' ) prev = 0 for i in range(1,60): if i % interval == 0: prev += interval lookup.append( '%02d' % (prev) ) return lookup options = get_command_options( 'average', 'Average over selected interval. Input on stdin. Output to stdout.' ) interval = options['interval'] verbose = int( options['verbose'] ) error,data = read_framer_results() if error: print( error, file=sys.stderr ) sys.exit( 1 ) if interval < 1: # no work to do, output = input json.dump( data, sys.stdout, indent=1 ) sys.exit( 0 ) minute_to_snap = precompute_every_minute( interval )
# polyf and polyu # also loop over the names making a0, a1, a2, ... # and where the name matches the index then put the value into the index for i in range(n): want = 'a' + str(i) for i in range(n): name = fit_config['coeffs'][i]['name'] if name == want: details['coeffs'][i] = float( fit_config['coeffs'][i]['value']) return details options = get_command_options( 'filter', 'Convert values using coeffecients. Input on stdin. Output to stdout.') packagefile = options['packagefile'] configpath = options['configpath'] verbose = int(options['verbose']) if not os.path.isfile(packagefile): print('package file does not exist', file=sys.stderr) sys.exit(1) if not os.path.isdir(configpath): print('data file does not exist', file=sys.stderr) sys.exit(1) error, configs = get_configurations(True, packagefile, configpath)
for instrument in sorted(data.keys()): for field in sorted(data[instrument].keys()): output = out_format['instrument'] % (instrument) output += out_format['field'] % (field) output += out_format['records'] % (str( data[instrument][field]['n'])) for item in stats: # format with precision, then set the string into the column width output += out_format[item] % (float_format % (data[instrument][field][item])) print(output) options = get_command_options( 'none', 'Show stats of a data file. Input on stdin. Output to stdout.') verbose = int(options['verbose']) error, data = read_framer_results() if error: print(error, file=sys.stderr) sys.exit(1) results = dict() header_key = get_header_key() for instrument in data: if instrument == header_key: pass
# Copyright John Andrea, 2019 import sys import os import json #from pprint import pprint # setup a few library files dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(dir_path + '/lib/') from framer_util import get_command_options from framer_config import specific_lower_and_trim, get_changable_config_keys, config_file_verify options = get_command_options('check config', 'Check validity of a single config file.') file = options['configfile'] verbose = int(options['verbose']) if not os.path.isfile(file): print('Config file does not exist:' + file, file=sys.stderr) sys.exit(1) try: with open(file) as f: json_contents = json.load(f) except: print('Error loading config file. Is it valid JSON:' + file, file=sys.stderr) sys.exit(1)
# Output: # error code and messages to stderr # Copyright John Andrea, 2019 import sys import os # setup a few library files dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(dir_path + '/lib/') from framer_util import get_command_options from framer_config import get_configurations options = get_command_options('check package', 'Check validity of package and configs.') packagefile = options['packagefile'] configpath = options['configpath'] verbose = int(options['verbose']) if not os.path.isfile(packagefile): print('package file does not exist', file=sys.stderr) sys.exit(1) if not os.path.isdir(configpath): print('data file does not exist', file=sys.stderr) sys.exit(1) error, configs = get_configurations(True, packagefile, configpath) if error:
timestamp = get_storx_timestamp(data, offset) else: ok = False if verbose > 4: print(' not enough bytes for timestamp', file=sys.stderr) else: # not enough bytes remaining ok = False if verbose > 3: print(' not enough bytes remain', file=sys.stderr) return ok, timestamp, values, length options = get_command_options( 'main', 'Extract data from raw files. Output to stdout.') packagefile = options['packagefile'] configpath = options['configpath'] datafile = options['datafile'] verbose = int(options['verbose']) enable_tests = options['enable tests'] if not os.path.isfile(packagefile): print('package file does not exist', file=sys.stderr) sys.exit(1) if not os.path.isdir(configpath): print('config path does not exist', file=sys.stderr) sys.exit(1) if not os.path.isfile(datafile): print('data file does not exist', datafile, file=sys.stderr)
import sys import os import json import copy from pprint import pprint # setup a few library files dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(dir_path + '/lib/') from framer_util import get_header_key, get_command_options, read_framer_results from framer_config import get_configurations options = get_command_options( 'filter', 'Output only the selected set of instrument/sensors. Input on stdin. Output to stdout.' ) packagefile = options['packagefile'] configpath = options['configpath'] verbose = int(options['verbose']) if not os.path.isfile(packagefile): print('package file does not exist', file=sys.stderr) sys.exit(1) if not os.path.isdir(configpath): print('data file does not exist', file=sys.stderr) sys.exit(1) error, configs = get_configurations(True, packagefile, configpath)
if not ok: if log_this: print(frame_id, timestamp, field, 'Failed validity', value, file=sys.stderr) break return ok options = get_command_options( 'validator', 'Remove values which fail verify rules. Input on stdin. Output to stdout.') packagefile = options['packagefile'] configpath = options['configpath'] verbose = int(options['verbose']) enable_tests = options['enable tests'] log_it = verbose > 3 if not os.path.isfile(packagefile): print('package file does not exist', file=sys.stderr) sys.exit(1) if not os.path.isdir(configpath): print('data file does not exist', file=sys.stderr) sys.exit(1)