def main(): mat_file_name = sys.argv[1] limits_dict, filter = read_limits() filter.append('SpeedSensor.v') # loads results with the filtered out variables (and 'time' which is default) pp = PostProcess(mat_file_name, filter) metrics = {} # No need to convert values into string that is done in update_metrics_in_report_json metrics.update({ 'MaximumSpeed': { 'value': pp.global_abs_max('SpeedSensor.v'), 'unit': 'm/s' } }) metrics.update({ 'MaximumSpeed10': { 'value': pp.global_abs_max('SpeedSensor.v') * 10, 'unit': 'm/s' } }) cwd = os.getcwd() os.chdir('..') update_metrics_in_report_json(metrics) check_limits_and_add_to_report_json(pp, limits_dict) os.chdir(cwd)
from common import PostProcess, update_metrics_in_report_json, read_limits, check_limits_and_add_to_report_json if __name__ == '__main__': if len(sys.argv) > 1: try: mat_file_name = sys.argv[1] if not os.path.exists(mat_file_name): print 'Given result file does not exist: {0}'.format( sys.argv[1]) os._exit(3) limits_dict, filter = read_limits() filter.append('VoltageSensor.v') # loads results with the filtered out variables (and 'time' which is default) pp = PostProcess(mat_file_name, filter) metrics = {} # No need to convert values into string that is done in update_metrics_in_report_json metrics.update({ 'VoltageOverInductor': { 'value': pp.global_max('VoltageSensor.v'), 'unit': 'Volt' } }) metrics.update({ 'VoltageOverInductor10': { 'value': pp.global_max('VoltageSensor.v') * 10, 'unit': 'deciVolt' } })
def main(): mat_file_name = sys.argv[1] if not os.path.exists(mat_file_name): raise IOError('Given result file does not exist: {0}'.format( sys.argv[1])) ## First limit part limit_dict, filter = read_limits() ## End of first limit part ## Post processing part bucketCylLength_uri = 'Excavator_.bucketCylLength_unit' filter.append(bucketCylLength_uri) armCylLength_uri = 'Excavator_.armCylLength_unit' filter.append(armCylLength_uri) boomCylLength_uri = 'Excavator_.boomCylLength_unit' filter.append(boomCylLength_uri) boomCylRPressure_uri = 'Excavator_.boomCylLPressure_a' filter.append(boomCylRPressure_uri) armCylPressure_uri = 'Excavator_.armCylPressure_a' filter.append(armCylPressure_uri) bucketCylPressure_uri = 'Excavator_.bucketCylPressure_a' filter.append(bucketCylPressure_uri) arm_ang_vel_uri = 'Excavator_.arm_ang_vel' filter.append(arm_ang_vel_uri) max_Y_uri = 'Excavator_.yDistance' filter.append(max_Y_uri) max_reach_uri = 'Excavator_.xDistance' filter.append(max_reach_uri) State_uri = 'operator_Full.State_1' filter.append(State_uri) tip_uri = 'Excavator_.tipping_torque' filter.append(tip_uri) deflection_uri = 'Excavator_.yDistance' filter.append(deflection_uri) # loads results with the filtered out variables (and 'time' which is default) pp = PostProcess(mat_file_name, filter) max_p_time = pp.global_max_time(boomCylRPressure_uri) max_v_time = pp.global_max_time(arm_ang_vel_uri) #max_p_time = pp.global_max_time(armCylPressure_uri) #max_p_time = pp.global_max_time(bucketCylPressure_uri) print 'Maximum pressure obtained at : {0}'.format(max_p_time) print 'Max tip torque : {0}'.format(pp.global_abs_max(tip_uri)) y_deflection = pp.get_data_by_index(deflection_uri, 0) - pp.last_value(deflection_uri) metrics = {} metrics.update({ 'bucketCylLength_unit': { 'value': pp.get_data_by_time(bucketCylLength_uri, max_p_time)[0], 'unit': 'm' }, 'boomCylLength_unit': { 'value': pp.get_data_by_time(boomCylLength_uri, max_p_time)[0], 'unit': 'm' }, 'armCylLength_unit': { 'value': pp.get_data_by_time(armCylLength_uri, max_p_time)[0], 'unit': 'm' }, 'bucketCylPressure': { 'value': pp.global_abs_max(bucketCylPressure_uri) * 0.00001, 'unit': 'bar' }, 'boomCylRPressure': { 'value': pp.global_abs_max(boomCylRPressure_uri) * 0.00001, 'unit': 'bar' }, 'armCylPressure': { 'value': pp.global_abs_max(armCylPressure_uri) * 0.00001, 'unit': 'bar' }, 'tipTorque': { 'value': pp.global_abs_max(tip_uri), 'unit': 'N-m' }, 'y_deflection': { 'value': y_deflection, 'unit': 'm' }, #'swing_speed': {'value': pp.last_value(swing_uri), 'unit':'rad/s'}, }) cwd = os.getcwd() os.chdir('..') # print 'Plot saved to : {0}'.format(pp.save_as_svg(vehicle_speed, # pp.global_abs_max(vehicle_speed), # 'VehicleSpeed', # 'max(FTP_Driver.driver_bus.vehicle_speed)', # 'kph')) dur = 100 pp.store_data_to_csv(bucketCylLength_uri, '{0}.csv'.format(bucketCylLength_uri), 0, 0.1, dur) pp.store_data_to_csv(armCylLength_uri, '{0}.csv'.format(armCylLength_uri), 0, 0.1, dur) pp.store_data_to_csv(boomCylLength_uri, '{0}.csv'.format(boomCylLength_uri), 0, 0.1, dur) pp.store_data_to_csv(boomCylRPressure_uri, '{0}.csv'.format(boomCylRPressure_uri), 0, 0.1, dur) pp.store_data_to_csv(arm_ang_vel_uri, '{0}.csv'.format(arm_ang_vel_uri), 0, 0.1, dur) pp.store_data_to_csv(max_Y_uri, '{0}.csv'.format(max_Y_uri), 0, 0.1, dur) pp.store_data_to_csv(max_reach_uri, '{0}.csv'.format(max_reach_uri), 0, 0.1, dur) pp.store_data_to_csv(State_uri, '{0}.csv'.format(State_uri), 0, 0.1, dur) ## end of postprocessing part ## Second limit part check_limits_and_add_to_report_json(pp, limit_dict) update_metrics_in_report_json(metrics) ## end of Second limit part os.chdir(cwd)
def main(): mat_file_name = sys.argv[1] if not os.path.exists(mat_file_name): raise IOError('Given result file does not exist: {0}'.format( sys.argv[1])) ## First limit part limit_dict, filter = read_limits() ## End of first limit part ## Post processing part bucketCylLength_uri = 'Excavator_.bucketCylLength_unit' filter.append(bucketCylLength_uri) armCylLength_uri = 'Excavator_.armCylLength_unit' filter.append(armCylLength_uri) boomCylLength_uri = 'Excavator_.boomCylLength_unit' filter.append(boomCylLength_uri) boomCylRPressure_uri = 'Excavator_.boomCylLPressure_a' filter.append(boomCylRPressure_uri) armCylPressure_uri = 'Excavator_.armCylPressure_a' filter.append(armCylPressure_uri) bucketCylPressure_uri = 'Excavator_.bucketCylPressure_a' filter.append(bucketCylPressure_uri) arm_ang_vel_uri = 'Excavator_.arm_ang_vel' filter.append(arm_ang_vel_uri) max_Y_uri = 'Excavator_.yDistance' filter.append(max_Y_uri) max_reach_uri = 'Excavator_.xDistance' filter.append(max_reach_uri) swing_uri = 'Excavator_.carriage2.swingRevolute.w' filter.append(swing_uri) # loads results with the filtered out variables (and 'time' which is default) pp = PostProcess(mat_file_name, filter) max_p_time = pp.global_max_time(boomCylRPressure_uri) max_v_time = pp.global_max_time(arm_ang_vel_uri) print 'Maximum pressure obtained at : {0}'.format(max_p_time) max_p_time = pp.global_max_time(armCylPressure_uri) print 'Maximum pressure obtained at : {0}'.format(max_p_time) max_p_time = pp.global_max_time(bucketCylPressure_uri) print 'Maximum pressure obtained at : {0}'.format(max_p_time) print 'Maximum velocity obtained at : {0}'.format(max_v_time) print 'Maximum Reach obtained at : {0}'.format( pp.global_max_time(max_reach_uri)) metrics = {} metrics.update({ 'bucketCylLength_unit': { 'value': pp.get_data_by_time(bucketCylLength_uri, max_p_time)[0], 'unit': 'm' }, 'boomCylLength_unit': { 'value': pp.get_data_by_time(boomCylLength_uri, max_p_time)[0], 'unit': 'm' }, 'boomCylRPressure': { 'value': pp.global_abs_max(boomCylRPressure_uri) * 0.00001, 'unit': 'bar' }, 'armCylLength_unit': { 'value': pp.get_data_by_time(armCylLength_uri, max_p_time)[0], 'unit': 'm' }, 'armCylPressure': { 'value': pp.global_abs_max(armCylPressure_uri) * 0.00001, 'unit': 'bar' }, 'bucketCylPressure': { 'value': pp.global_abs_max(bucketCylPressure_uri) * 0.00001, 'unit': 'bar' }, 'arm_angVel': { 'value': pp.global_abs_max(arm_ang_vel_uri), 'unit': 'rads/s' }, 'max_reach': { 'value': pp.global_max(max_reach_uri), 'unit': 'm' }, 'max_high_reach': { 'value': pp.global_max(max_Y_uri), 'unit': 'm' }, 'max_low_reach': { 'value': pp.global_min(max_Y_uri), 'unit': 'm' }, 'swing_speed': { 'value': pp.last_value(swing_uri), 'unit': 'rad/s' }, }) cwd = os.getcwd() os.chdir('..') # print 'Plot saved to : {0}'.format(pp.save_as_svg(vehicle_speed, # pp.global_abs_max(vehicle_speed), # 'VehicleSpeed', # 'max(FTP_Driver.driver_bus.vehicle_speed)', # 'kph')) pp.store_data_to_csv(bucketCylLength_uri, '{0}.csv'.format(bucketCylLength_uri), 0, 0.1, 200) pp.store_data_to_csv(armCylLength_uri, '{0}.csv'.format(armCylLength_uri), 0, 0.1, 200) pp.store_data_to_csv(boomCylLength_uri, '{0}.csv'.format(boomCylLength_uri), 0, 0.1, 200) pp.store_data_to_csv(boomCylRPressure_uri, '{0}.csv'.format(boomCylRPressure_uri), 0, 0.1, 200) pp.store_data_to_csv(arm_ang_vel_uri, '{0}.csv'.format(arm_ang_vel_uri), 0, 0.1, 200) pp.store_data_to_csv(max_Y_uri, '{0}.csv'.format(max_Y_uri), 0, 0.1, 500) pp.store_data_to_csv(max_reach_uri, '{0}.csv'.format(max_reach_uri), 0, 0.1, 200) update_metrics_in_report_json(metrics) ## end of postprocessing part ## Second limit part check_limits_and_add_to_report_json(pp, limit_dict) ## end of Second limit part os.chdir(cwd)
def main(): print "in main....." sampleRate = 0.10 startAnalysisTime = 50 f = open('rawdata.csv', 'w') mat_file_name = sys.argv[1] print "Mat file name is " + mat_file_name if not os.path.exists(mat_file_name): raise IOError('Given result file does not exist: {0}'.format( sys.argv[1])) else: dstpath = os.path.join(os.getcwd(), 'matfiles') if not os.path.isdir(dstpath): os.makedirs(dstpath) numFiles = len(os.listdir(dstpath)) dstname = '_' + str(numFiles) + mat_file_name shutil.copyfile(mat_file_name, os.path.join(dstpath, dstname)) print "Line 24: Opened " + mat_file_name ## First limit part limit_dict, filter = read_limits() print "done limits" filter = [] ## End of first limit part ## Post processing part #--------accelerations----------------------------------------------- #--------------------------------------------------------------------------------- # Processing #--------------------------------------------------------------------------------- # loads results with the filtered out variables (and 'time' which is default) filter = [] pp = PostProcess(mat_file_name, filter) vars_available = pp.get_names() dumpList = [] print vars_available[1] for vv in vars_available: if vv.find("current_") != -1: print "add to dumpList: " + vv dumpList.append(vv) if vv.find("voltage_") != -1: print "add to dumpList: " + vv dumpList.append(vv) if vv.find("angle_") != -1: print "add to dumpList: " + vv dumpList.append(vv) pp.print_time() print "Last time is " + str(pp.get_max_time()) sampData = [] for vv in dumpList: ndat = pp.resample_data(vv, sampleRate) print "got ndat size=", len(ndat) sampData.append(ndat) print 'sampdata=', len(sampData), 'cols', len(sampData[0]), 'rows' i = 0 print "dumping raw data headers" for c, vv in enumerate(dumpList): print vv, c f.write(vv + ',') f.write("\n") print "dump data" print len(sampData), 'cols', len(sampData[0]) while i < len(sampData[0]): if i % 1000 == 0: print "line ", i for c, vv in enumerate(dumpList): f.write(str(sampData[c][i]) + ',') f.write("\n") i = i + 1 f.close() actAngleIdx = -1 setAngleIdx = -1 voltBusIdx = -1 currGyroIdx = -1 for c, vv in enumerate(dumpList): if vv.find("angle_set") != -1: setAngleIdx = c if vv.find("angle_act") != -1: actAngleIdx = c if vv.find("voltage_bus") != -1: voltBusIdx = c if vv.find("current_gyro") != -1: currGyroIdx = c print "gyro idx ", currGyroIdx maxErr = 0 sumErr = 0 avgErr = 0 maxBusV = -1 minBusV = 100 minBattCap = 100 maxGyroCurr = 0 if actAngleIdx != -1 and setAngleIdx != -1: i = int(startAnalysisTime / sampleRate) first = i print "scanning angles from ", i, " to ", len(sampData[setAngleIdx]) while i < len(sampData[setAngleIdx]): angErr = abs(sampData[setAngleIdx][i] - sampData[actAngleIdx][i]) if angErr > maxErr: maxErr = angErr sumErr = sumErr + angErr i = i + 1 avgErr = sumErr / (i - first + 1) if voltBusIdx != -1: i = int(startAnalysisTime / sampleRate) while i < len(sampData[voltBusIdx]): vts = abs(sampData[voltBusIdx][i]) if vts > maxBusV: maxBusV = vts if vts < minBusV: minBusV = vts i = i + 1 if currGyroIdx != -1: i = int(startAnalysisTime / sampleRate) print "scanning Gyro currents from ", i, " to ", len( sampData[currGyroIdx]) while i < len(sampData[currGyroIdx]): vts = abs(sampData[currGyroIdx][i]) if vts > maxGyroCurr: maxGyroCurr = vts print vts i = i + 1 output_dir = "../" json_filename = os.path.join(output_dir, 'testbench_manifest.json') import json json_data = {} if os.path.isfile(json_filename): with open(json_filename, "r") as json_file: print "reading json" json_data = json.load(json_file) print "json_data is....." print json_data for metric in json_data['Metrics']: if metric["Name"] == "angleMaxError": metric["Value"] = str(maxErr) if metric["Name"] == "angleAvgError": metric["Value"] = str(avgErr) if metric["Name"] == "minBusVoltage": metric["Value"] = str(minBusV) if metric["Name"] == "maxBusVoltage": metric["Value"] = str(maxBusV) if metric["Name"] == "minBattCapacity": metric["Value"] = str(minBattCap) if metric["Name"] == "maxGyroCurrent": metric["Value"] = str(maxGyroCurr) print "dumping to ", json_filename print json_data with open(json_filename, "w") as json_file: json.dump(json_data, json_file, indent=4) # #--------------------------------------------------------------------------------- # # Potential_Design # #--------------------------------------------------------------------------------- # Potential_Design = 0 # followTime = pp.get_data_by_index(followTime_uri, -1) # if (SettlingTime == -1 or riseTime == -1 or minDistance < .1*minDistanceVelocity*followTime): # Potential_Design = -1 # else: Potential_Design = 1 # print "Potential_Design: %d" %Potential_Design # #--------------------------------------------------------------------------------- # # Metrics # #--------------------------------------------------------------------------------- # metrics = {} # metrics.update({'vehicleMass':{'value': vehicleMass, 'unit':'kg'}, # 'distanceTraveled':{'value': distanceTraveled, 'unit': 'm'}, # 'minDistance': {'value': minDistance, 'unit': 'm'}, # 'finalVelocity':{'value': Vf, 'unit': 'm/s'}, # 'requiredTorque':{'value': requiredTorque, 'unit':'N-m'}, # 'riseTime':{'value': np.amax(riseTime), 'unit' :''}, # 'Overshoot':{'value': np.amax(Overshoot), 'unit' :''}, # 'settlingTime':{'value': np.amax(SettlingTime), 'unit' :''}, # 'rms_error':{'value': RMS_error, 'unit' : ''}, # 'numSetpointCrossings':{'value':numSetPointCrossings, 'unit': ''}, # 'averageA': {'value': maxAccel, 'unit': 'm/s2'}, # 'averageJ': {'value': maxJerk, 'unit': 'm/s3'}, # 'Potential_Design': {'value': Potential_Design, 'unit': ''}, # #'chassisType':{'value': chassisType, 'unit' :''}, # }) #print metrics cwd = os.getcwd() os.chdir('..') # print 'Plot saved to : {0}'.format(pp.save_as_svg(vehicle_speed, # pp.global_abs_max(vehicle_speed), # 'VehicleSpeed', # 'max(FTP_Driver.driver_bus.vehicle_speed)', # 'kph')) #pp.store_data_to_csv(jerk_uri, '{0}.csv'.format(jerk_uri), 0, time_inc, numSamples) #pp.store_data_to_csv(a_uri, '{0}.csv'.format(a_uri), 0, time_inc, numSamples) #pp.store_data_to_csv(pp.time_array, '{0}.csv'.format(pp.time_array), 0, time_inc, numSamples) #pp.store_data_to_csv(boomCylLength_uri, '{0}.csv'.format(boomCylLength_uri), 0, time_inc, numSamples) #pp.store_data_to_csv(armCylLength_uri, '{0}.csv'.format(armCylLength_uri), 0, time_inc, numSamples) #pp.store_data_to_csv(bucketCylLength_uri, '{0}.csv'.format(bucketCylLength_uri), 0, time_inc, numSamples) #pp.store_data_to_csv(boomCylRPressure_uri, '{0}.csv'.format(boomCylRPressure_uri), 0, 0.1, dur) #pp.store_data_to_csv(arm_ang_vel_uri, '{0}.csv'.format(arm_ang_vel_uri), 0, 0.1, dur) #pp.store_data_to_csv(max_Y_uri, '{0}.csv'.format(max_Y_uri), 0, 0.1, dur) #pp.store_data_to_csv(max_reach_uri, '{0}.csv'.format(max_reach_uri), 0, 0.1, dur) #pp.store_data_to_csv(State_uri, '{0}.csv'.format(State_uri), 0, 0.1, dur) ## end of postprocessing part ## Second limit part #check_limits_and_add_to_report_json(pp, limit_dict) #update_metrics_in_report_json(metrics) ## end of Second limit part os.chdir(cwd) print "done main"