2023-07-25 15:17:23 +00:00
|
|
|
from pprint import pprint
|
|
|
|
from decimal import *
|
|
|
|
|
2023-07-22 02:35:49 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
def parse_transducer(file_path):
|
|
|
|
transducer_data = []
|
|
|
|
with open(file_path, 'r') as file:
|
|
|
|
content = file.read()
|
|
|
|
|
|
|
|
# Split the content into sections based on the blank line
|
|
|
|
sections = content.strip().split('\n\n')
|
|
|
|
|
|
|
|
for section in sections:
|
|
|
|
# Split each section into lines
|
|
|
|
lines = section.strip().split('\n')
|
|
|
|
lines = [line.strip() for line in lines if not line.startswith("==") and line != "|| Transducer Verify Report ||"]
|
|
|
|
lines.pop(0)
|
|
|
|
|
|
|
|
# Extract the Transducer number and Transducer type
|
|
|
|
transducer_line = lines.pop(0).strip()
|
2023-07-25 15:17:23 +00:00
|
|
|
_, 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"
|
|
|
|
|
2023-07-22 02:35:49 +00:00
|
|
|
|
|
|
|
# Create a dictionary to store the data for each transducer
|
|
|
|
transducer_info = {
|
2023-07-25 15:17:23 +00:00
|
|
|
'Part Number': part_number,
|
|
|
|
'Value': value,
|
2023-07-22 02:35:49 +00:00
|
|
|
'Transducer Name': transducer_name,
|
|
|
|
'Transducer Type': transducer_type,
|
2023-07-25 15:17:23 +00:00
|
|
|
'Setpoint Pressure':[],
|
|
|
|
'Instrument Pressure': [],
|
|
|
|
'Master Value': [],
|
|
|
|
'Instrument Flow': [],
|
2023-07-22 02:35:49 +00:00
|
|
|
'Verify Date': '',
|
|
|
|
'Verify Time': ''
|
|
|
|
}
|
|
|
|
|
|
|
|
# Extract other information for the transducer
|
|
|
|
for line in lines:
|
|
|
|
key, value = re.sub(r'\s\s+', ',', line.strip()).split(',')
|
2023-07-25 15:17:23 +00:00
|
|
|
if 'Verify Date' in key:
|
2023-07-22 02:35:49 +00:00
|
|
|
transducer_info['Verify Date'] = value
|
2023-07-25 15:17:23 +00:00
|
|
|
continue
|
2023-07-22 02:35:49 +00:00
|
|
|
elif 'Verify Time' in key:
|
|
|
|
transducer_info['Verify Time'] = value
|
2023-07-25 15:17:23 +00:00
|
|
|
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]))
|
|
|
|
|
2023-07-22 02:35:49 +00:00
|
|
|
|
|
|
|
transducer_data.append(transducer_info)
|
|
|
|
|
|
|
|
return transducer_data
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
file_path = './transducer_verify.txt'
|
2023-07-25 15:17:23 +00:00
|
|
|
parsed_data = parse_transducer(file_path)
|
|
|
|
getcontext().prec = 3
|
2023-07-22 02:35:49 +00:00
|
|
|
|
|
|
|
# Printing the parsed data for each transducer
|
|
|
|
for transducer_info in parsed_data:
|
2023-07-25 15:17:23 +00:00
|
|
|
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'])
|
2023-07-22 02:35:49 +00:00
|
|
|
print("Verify Date:", transducer_info['Verify Date'])
|
|
|
|
print("Verify Time:", transducer_info['Verify Time'])
|
|
|
|
print("==========================")
|
2023-07-25 15:17:23 +00:00
|
|
|
pprint(transducer_info)
|