From 0b438788c36b9dc9e9fb98d92f7f0815b540fb24 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Tue, 25 Jul 2023 11:17:23 -0400 Subject: [PATCH] parsing more --- parse_transducer.py | 63 ++++++++++++++++++++++++++++++--------------- tags | 3 ++- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/parse_transducer.py b/parse_transducer.py index a0c1a4e..85d83b9 100644 --- a/parse_transducer.py +++ b/parse_transducer.py @@ -1,3 +1,6 @@ +from pprint import pprint +from decimal import * + import re def parse_transducer(file_path): @@ -16,16 +19,30 @@ def parse_transducer(file_path): # Extract the Transducer number and Transducer type transducer_line = lines.pop(0).strip() - _, transducer_name, transducer_type = transducer_line.split(None, 2) + _, transducer_name, part_number = transducer_line.split(None, 2) + + # Get part number and values + value = None + transducer_type = None + if part_number != "Custom": + value = part_number.split()[-1] + part_number = part_number.split()[1] + if value.endswith("SCCM"): + transducer_type = "Flow" + if value.endswith("PSIA"): + transducer_type = "Pressure" + # Create a dictionary to store the data for each transducer transducer_info = { + 'Part Number': part_number, + 'Value': value, 'Transducer Name': transducer_name, 'Transducer Type': transducer_type, - 'Setpoint Pressures': {}, - 'Instrument Pressures': {}, - 'Master Values': {}, - 'Instrument Flows': {}, + 'Setpoint Pressure':[], + 'Instrument Pressure': [], + 'Master Value': [], + 'Instrument Flow': [], 'Verify Date': '', 'Verify Time': '' } @@ -33,18 +50,19 @@ def parse_transducer(file_path): # Extract other information for the transducer for line in lines: key, value = re.sub(r'\s\s+', ',', line.strip()).split(',') - if 'Setpoint Pressure' in key: - transducer_info['Setpoint Pressures'][key] = value - elif 'Instrument Pressure' in key: - transducer_info['Instrument Pressures'][key] = value - elif 'Master Value' in key: - transducer_info['Master Values'][key] = value - elif 'Instrument Flow' in key: - transducer_info['Instrument Flows'][key] = value - elif 'Verify Date' in key: + if 'Verify Date' in key: transducer_info['Verify Date'] = value + continue elif 'Verify Time' in key: transducer_info['Verify Time'] = value + continue + + # Toss anything else where it belongs + v = Decimal(value.split(" ")[0]) + key = re.match(r'(.*)\W(\d)', key)[1] + if key in transducer_info: + transducer_info[key].append(Decimal(value.split()[0])) + transducer_data.append(transducer_info) @@ -53,16 +71,19 @@ def parse_transducer(file_path): if __name__ == '__main__': file_path = './transducer_verify.txt' - parsed_data = parse_text_file(file_path) + parsed_data = parse_transducer(file_path) + getcontext().prec = 3 # Printing the parsed data for each transducer for transducer_info in parsed_data: - print("Transducer Name:", transducer_info['Transducer Name']) - print("Transducer Type:", transducer_info['Transducer Type']) - print("Setpoint Pressures:", transducer_info['Setpoint Pressures']) - print("Instrument Pressures:", transducer_info['Instrument Pressures']) - print("Master Values:", transducer_info['Master Values']) - print("Instrument Flows:", transducer_info['Instrument Flows']) + print("Part Number", transducer_info['Part Number']) + print("Value", transducer_info['Value']) + print("Transducer Type", transducer_info['Transducer Type']) + print("Setpoint Pressures:", transducer_info['Setpoint Pressure']) + print("Instrument Pressures:", transducer_info['Instrument Pressure']) + print("Master Values:", transducer_info['Master Value']) + print("Instrument Flows:", transducer_info['Instrument Flow']) print("Verify Date:", transducer_info['Verify Date']) print("Verify Time:", transducer_info['Verify Time']) print("==========================") + pprint(transducer_info) diff --git a/tags b/tags index b1c2dac..1db1d15 100644 --- a/tags +++ b/tags @@ -13,7 +13,8 @@ parse_file parse_hardware.py /^def parse_file(file_path):$/;" f parse_instrument_info parse_hardware.py /^def parse_instrument_info(text):$/;" f parse_ports parse_hardware.py /^def parse_ports(text):$/;" f parse_transducer parse_transducer.py /^def parse_transducer(file_path):$/;" f -parsed_data parse_transducer.py /^ parsed_data = parse_text_file(file_path)$/;" v +parsed_data parse_transducer.py /^ parsed_data = parse_transducer(file_path)$/;" v pprint parse_hardware.py /^from pprint import pprint$/;" i +pprint parse_transducer.py /^from pprint import pprint$/;" i re parse_hardware.py /^import re$/;" i re parse_transducer.py /^import re$/;" i