Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import time
- import os
- import argparse
- def process(logdir, filename):
- chunksize = 1000000
- print ('processing {}...'.format(filename))
- for df in pd.read_csv(filename, chunksize=chunksize, iterator=True, #skiprows=skip_idx,
- names=['namespace', 'one', 'timestamp', 'name', 'four', 'five', 'six', 'value']):
- print ('\tchunk.. - logdir: {}'.format(logdir))
- # get relevant columns
- # 0 1 2 3 4 5 6 7
- # namespace, ?, timestamp, name, ?, ?, ?, value
- #foo = '/left_arm_joint_trajectory_controller/command_module/root_body_wrench_d_wx'
- # director,6381427,1527102254571862641,/left_arm_joint_trajectory_controller/command_module/root_body_wrench_d_wx,4,306,1759263548,0
- df = df[['timestamp', 'name', 'value']]
- # downsample
- #df = df.iloc[::10, :]
- # get unique names to collect relevant signals
- dfs = dict(tuple(df.groupby('name')))
- # these are the only values we actually want
- long2short = {'_elmo_thruster_aft_port_actuator_current':'current',
- '_elmo_thruster_aft_port_actuator_vel_act':'actual_velocity',
- '_elmo_thruster_aft_port_actuator_vel_des':'desired_velocity',
- '_elmo_thruster_aft_port_actuator_voltage':'voltage',
- '_elmo_thruster_aft_star_actuator_motor_temp':'thrust'}
- # append to file
- excel_path = os.path.join(logdir, 'parsed.xlsx')
- writer = pd.ExcelWriter(excel_path, engine='xlsxwriter')
- for name in dfs.keys():
- logfilename = name.replace('/','_')
- logfile = os.path.join(logdir, logfilename)
- noname = dfs[name][['timestamp', 'value']]
- # noname.to_csv(logfile)
- if logfilename in long2short:
- noname.to_excel(writer, sheet_name=long2short[logfilename])
- writer.save()
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(description='Parse Thruster data')
- parser.add_argument('input', help='Directory containing Lumberjack data')
- parser.add_argument('--logdir', default='', help='Where to save the log files to')
- args = parser.parse_args()
- #path = '/home/pdinh/thruster/16-07-2018'
- path = args.input
- # get list of all the valid logfile names (crap that ends in .gz)
- logfiles = []
- for root, dirs, files in os.walk(path):
- for filename in files:
- if filename.endswith('.gz'):
- newfile = os.path.join(root, filename)
- logfiles.append(newfile)
- for filename in logfiles:
- # get output directory, use same directory where file exists if --logdir parameter not passed in
- dirname = os.path.dirname(filename)
- basename = os.path.basename(dirname)
- logdir = os.path.join(args.logdir, basename)
- if logdir == '':
- logdir = dirname
- if not os.path.exists(logdir):
- os.makedirs(logdir)
- # parse the data with pandas and output it
- process(logdir, filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement