From cd3c37e8aef44831c547b0dce80fc5afea064097 Mon Sep 17 00:00:00 2001 From: Thomas Bock <thomas.bock@ptb.de> Date: Thu, 13 Jan 2022 09:25:08 +0100 Subject: [PATCH] clean up some fns --- cal/utils.py | 88 ++++++++----------- .../result_error/de-para_0-alt_0-result.tex | 1 - 2 files changed, 37 insertions(+), 52 deletions(-) diff --git a/cal/utils.py b/cal/utils.py index 7adc790..65c1cd9 100644 --- a/cal/utils.py +++ b/cal/utils.py @@ -82,7 +82,6 @@ def get_last_cert(cal_docs): if last_cert and last_year: return "{}\\,PTB\\,{}".format(last_cert, last_year[-2:]) - def sort_by_pressure(cal_docs): """Sort caldocs by pressure in order to get the result tables in the correct order""" @@ -150,8 +149,8 @@ def get_measurement_data(cal_docs): gas = get_gas(doc) result_type = get_result_type(doc) - res = doc.get("Calibration", {}).get("Result", {}) - meas_data = res.get("MeasurementData") + meas_data = doc.get("Calibration", {}).get("Result", {}).get("MeasurementData") + if meas_data is None: continue if not gas in measurement_data: @@ -166,11 +165,11 @@ def get_device(cal_docs): for i, doc in enumerate(cal_docs): pass - dev["Text"] = doc.get("Calibration", {}).get("CustomerObject", {}).get("Text", { - "shipping": "", - "specials": "" - }) - dev_setup = doc.get("Calibration", {}).get("CustomerObject", {}).get("Setup",{}) + empty_txt = {"shipping": "", + "specials": "",} + + dev["Text"] = doc.get("Calibration", {}).get("CustomerObject", {}).get("Text", empty_txt) + dev_setup = doc.get("Calibration", {}).get("CustomerObject", {}).get("Setup", {}) dev["Setup"] = safe_device_setup(dev_setup) dev["DeviceClass"] = doc.get("Calibration", {}).get("CustomerObject", {}).get("Class","") @@ -198,8 +197,8 @@ def get_titlepage(cal_docs, countries, maintainers): title = { "ShortYear":get_current_year(short=True), "FullYear": get_current_year(), - "CertificateDate": get_current_date(), - } + "CertificateDate": get_current_date(),} + fs_val = 0.0 fs_unit = "Pa" @@ -503,24 +502,20 @@ def dcc_analysis_software(cal_docs): doc = cal_docs[-1] name, release = get_analysis_software(doc) if name: - return {"name":[{"lang":"en", - "content": [name]}], - "release":release} + return {"name": [{"lang":"en", "content": [name]}], + "release": release} def dcc_result_software(cal_docs): doc = cal_docs[-1] name, release = get_result_software(doc) if name: - return {"name":[{"lang":"en", - "content": [name]}], - "release":release} + return {"name":[{"lang":"en", "content": [name]}], + "release": release} def dcc_cal_software(cal_docs): doc = cal_docs[-1] - - return {"name":[{"lang":"en", - "content":["cal (generation of json-dcc)"]}], - "release":git_cmd(get_config_dict()).describe()} + return {"name":[{"lang": "en", "content": ["cal (generation of json-dcc)"]}], + "release": git_cmd(get_config_dict()).describe()} def dcc_customer(cal_docs, countries): doc = cal_docs[-1] @@ -529,15 +524,13 @@ def dcc_customer(cal_docs, countries): contact = customer.get("Contact", {}) lang = get_lang(doc) - return {"name":[{"lang": lang, - "content": [customer.get("Name")]}], - "eMail":contact.get("Email"), - "location":{ - "street":adr.get("Street"), - #"streetNo": "", - "postCode": adr.get("Zipcode"), - "city":adr.get("Town"), - "countryCode":adr.get("Land").upper()}} + + return {"name":[{"lang": lang, "content": [customer.get("Name")]}], + "eMail": contact.get("Email"), + "location":{"street": adr.get("Street"), + "postCode": adr.get("Zipcode"), + "city": adr.get("Town"), + "countryCode": adr.get("Land").upper()}} def dcc_calibration_object_description(cal_docs, secs): doc = cal_docs[-1] @@ -545,8 +538,8 @@ def dcc_calibration_object_description(cal_docs, secs): item_descr = [] for i, m in enumerate(secs): if m.get("DccAssigment", "none") == "item": - item_descr.append({"lang":lang, - "content":dcc_strip_content(m.get("Paragraph"))}) + item_descr.append({"lang":lang, "content":dcc_strip_content(m.get("Paragraph"))}) + return item_descr def meas_date_begin_end(cal_docs): @@ -572,7 +565,7 @@ def format_fs_value(v): return "{:.1e}".format(v) def should_skipped(doc): - return doc.get("Calibration", {}).get("Result",{}).get("Skip", False) + return doc.get("Calibration", {}).get("Result", {}).get("Skip", False) def get_analysis_software(doc): aux = doc.get("Calibration", {}).get("Analysis").get("AuxValues") @@ -624,25 +617,20 @@ def get_customer(doc, countries): short_land = adr.get("Land") lang = get_lang(doc) - cust = { - "Name": escape_items(customer.get("Name")), - "AddName": escape_items(customer.get("AddName")), - "Street": adr.get("Street"), - "Town": adr.get("Town"), - "Zipcode": adr.get("Zipcode"), - "Land": countries.get(short_land, {}).get(lang, {}).get("short", short_land), - "CountryCode": short_land.upper(), - "ContactName": contact.get("Name"), - "ContactPhone": contact.get("Phone"), - "Email": contact.get("Email"), - } - - return cust + return {"Name": escape_items(customer.get("Name")), + "AddName": escape_items(customer.get("AddName")), + "Street": adr.get("Street"), + "Town": adr.get("Town"), + "Zipcode": adr.get("Zipcode"), + "Land": countries.get(short_land, {}).get(lang, {}).get("short", short_land), + "CountryCode": short_land.upper(), + "ContactName": contact.get("Name"), + "ContactPhone": contact.get("Phone"), + "Email": contact.get("Email"),} def get_reference_no(doc): - ref_no = doc.get("Calibration",{}).get("Presettings",{}).get("ReferenceNo", "-") # "[[?|{ref_no}|7.5-1.6-YY-Anz.IG-Anz.Ges.]]".format(ref_no=ref_no) - return ref_no + return doc.get("Calibration",{}).get("Presettings",{}).get("ReferenceNo", "-") def get_certificate(doc): return doc.get("Calibration",{}).get("Certificate") @@ -658,8 +646,6 @@ def make_meas_date_title(begin_date, end_date, lang): return m_str.format(d_from=begin_date, d_to = end_date) - - def get_std(doc): """ .. code:: @@ -734,4 +720,4 @@ def get_current_year(short=False): return y def get_current_date(short=False): - return "{}".format(datetime.datetime.today().date()) + return "{}".format(datetime.datetime.today().date()) diff --git a/templates/latex/result_error/de-para_0-alt_0-result.tex b/templates/latex/result_error/de-para_0-alt_0-result.tex index b378e90..035c9de 100644 --- a/templates/latex/result_error/de-para_0-alt_0-result.tex +++ b/templates/latex/result_error/de-para_0-alt_0-result.tex @@ -27,7 +27,6 @@ konstante Gastemperatur von $T_1=$ ((*-for result_type, measurement_data in MeasurementData[gas].items()*)) ((*if gas == "N2"*)) ((*if measurement_data.TemperatureCorrection == "yes"*)) - (((measurement_data.NormTemperature))). ((*endif*)) ((*endif*)) -- GitLab