transducer work

This commit is contained in:
Tyrel Souza 2023-07-25 21:51:57 -04:00
parent 2144a97a10
commit 0f80f7d4e6
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
5 changed files with 47 additions and 8 deletions

View File

@ -1,2 +1,2 @@
from .hardware import parse_hardware_calibration from .hardware import parse_hardware_calibration
from .transducer import parse_transducer from .transducer import parse_transducer

View File

@ -3,8 +3,16 @@ from decimal import *
import re import re
def parse_transducer(content): def in_range(index, value, master_values):
getcontext().prec = 3 return (
master_values[index]["Low Limit"] <= value <= master_values[index]["High Limit"]
)
def parse_transducer(content, accuracy):
getcontext().prec = 6
accuracy = Decimal(f"{accuracy/100.0}") # Comes in as Percent
transducer_data = [] transducer_data = []
# Split the content into sections based on the blank line # Split the content into sections based on the blank line
@ -37,11 +45,12 @@ def parse_transducer(content):
# Create a dictionary to store the data for each transducer # Create a dictionary to store the data for each transducer
transducer_info = { transducer_info = {
"Accuracy": accuracy,
"Part Number": part_number, "Part Number": part_number,
"Value": value, "Value": value,
"Transducer Name": transducer_name, "Transducer Name": transducer_name,
"Transducer Type": transducer_type, "Transducer Type": transducer_type,
"Setpoint Pressure": [], # "Setpoint Pressure": [],
"Instrument Pressure": [], "Instrument Pressure": [],
"Master Value": [], "Master Value": [],
"Instrument Flow": [], "Instrument Flow": [],
@ -63,15 +72,44 @@ def parse_transducer(content):
v = Decimal(value.split(" ")[0]) v = Decimal(value.split(" ")[0])
key = re.match(r"(.*)\W(\d)", key)[1] key = re.match(r"(.*)\W(\d)", key)[1]
if key in transducer_info: if key in transducer_info:
transducer_info[key].append(Decimal(value.split()[0])) value = Decimal(value.split()[0])
# special case Master to get the limits
if "Master" in key:
hi = Decimal(Decimal(1.0) + accuracy)
lo = Decimal(Decimal(1.0) - accuracy)
transducer_info[key].append(
{
"Low Limit": lo,
"Value": value,
"High Limit": value * hi,
}
)
else:
transducer_info[key].append(value)
transducer_info[f"Instrument {transducer_type}"] = [
{
"Value": v,
"In Range": in_range(idx, v, transducer_info["Master Value"]),
}
for idx, v in enumerate(transducer_info[f"Instrument {transducer_type}"])
]
if transducer_type == "Flow":
del transducer_info["Instrument Pressure"]
elif transducer_type == "Pressure":
del transducer_info["Instrument Flow"]
transducer_data.append(transducer_info) transducer_data.append(transducer_info)
return transducer_data return transducer_data
if __name__ == "__main__": if __name__ == "__main__":
from pprint import pprint
file_path = "./transducer_verify.txt" file_path = "./transducer_verify.txt"
with open(file_path, "r") as file: with open(file_path, "r") as file:
content = file.read() content = file.read()
parsed_data = parse_transducer(file_path) parsed_data = parse_transducer(content, 0.5)
pprint(parsed_data)

View File

@ -29,7 +29,7 @@ Auto Data
Calculations: etc Calculations: etc
- High Limit/ Low Limit eg: (SPAN*1.0005 + column) (SPAN*0.9995 - column) - High Limit/ Low Limit eg: (SPAN*1.0005 + column) (SPAN*0.9995 - column)
- Delta = abs(gauge reading) - abs(asleft|asfound) - Delta = abs(gauge reading) - abs(asleft|asfound)
- PSIA - PRESSURE - PSIA - PRESSURE
- SCCM - FLOW - SCCM - FLOW
- TRANSDUCER1 Will ALWAYS be pressure - TRANSDUCER1 Will ALWAYS be pressure

View File

@ -1,3 +1,3 @@
django django
psycopg2 psycopg2-binary
django-debug-toolbar django-debug-toolbar

View File

@ -83,3 +83,4 @@ Master Value 10 225.000 sccm
Master Value 11 250.000 sccm Master Value 11 250.000 sccm
Verify Date 07/15/21 Verify Date 07/15/21
Verify Time 14:55:10 Verify Time 14:55:10