From 59e31a1fc788cb4299aae9fcb110b27ef2e3c887 Mon Sep 17 00:00:00 2001
From: Thomas Bock <thomas.bock@ptb.de>
Date: Tue, 6 Dec 2022 09:15:15 +0100
Subject: [PATCH] dcc sens, clean up

---
 cal/dcc-sections-assignment.json |  30 ++++---
 cal/trans.py                     | 130 ++++++++++---------------------
 cal/utils.py                     |  78 ++++++++++++++-----
 3 files changed, 120 insertions(+), 118 deletions(-)

diff --git a/cal/dcc-sections-assignment.json b/cal/dcc-sections-assignment.json
index ba87b4c..fc8f3c4 100644
--- a/cal/dcc-sections-assignment.json
+++ b/cal/dcc-sections-assignment.json
@@ -1,13 +1,21 @@
 {
-    "device_description":"item",
-    "error_and_cf":"used_method",
-    "result_error":"used_method",
-    "temperature_correction":"used_method",
-    "uncertainty-cdg":"used_method",
-    "calibration_procedure-se3-cdg":"used_method",
-    "calibration_procedure-se3-srg":"used_method",
-    "calibration_procedure-ce3-ig":"used_method",
-    "sigma":"used_method",
-    "uncertainty-srg":"used_method",
-    "uncertainty-ig":"used_method"
+    "device_description": "item",
+
+    "error_and_cf": "used_method",
+    "result_error": "used_method",
+    "result_sens": "used_method",
+
+    "temperature_correction": "used_method",
+
+    "calibration_procedure-se3-cdg": "used_method",
+    "calibration_procedure-se3-srg": "used_method",
+    "calibration_procedure-ce3-ig": "used_method",
+
+    "sigma": "used_method",
+    "sens": "used_method",
+
+    "uncertainty-srg": "used_method",
+    "uncertainty-fm1-tlv": "used_method",
+    "uncertainty-ig": "used_method",
+    "uncertainty-cdg": "used_method"
 }
diff --git a/cal/trans.py b/cal/trans.py
index dbef8c2..8eab4e9 100644
--- a/cal/trans.py
+++ b/cal/trans.py
@@ -78,14 +78,8 @@ class Trans:
             "en": ", comparison with rotary piston gauge"
         }
     }
-    dcc_unit_trans = {
-        "1":"\\one",
-        "mbar": "\\hecto\\kilogram\\metre\\tothe{-1}\\second\\tothe{-2}",
-        "Pa":"\\kilogram\\metre\\tothe{-1}\\second\\tothe{-2}",
-        "1/Pa":"\\kilogram\\tothe{-1}\\metre\\second\\tothe{2}",
-        "K":"\\kelvin",
-        "A":"\\ampere"
-        }
+
+
 
     def __init__(self, config, app, db):
         self.latex_path = config['templates']['latex']
@@ -131,9 +125,7 @@ class Trans:
 
         return cert
 
-
     def dcc(self, cal_docs):
-
         cal_docs = [doc for doc in cal_docs if not utils.should_skipped(doc)]
 
         maintainers =  self.db.get_maintainers()
@@ -141,13 +133,13 @@ class Trans:
         info_doc = cal_docs[-1]
         lang = utils.get_lang(info_doc)
         begin_meas_date, end_meas_date = utils.meas_date_begin_end(cal_docs)
-        cert = {
-            "RequestId": utils.get_request_id(cal_docs=cal_docs),
-            "Meta": utils.get_meta(cal_docs=cal_docs),
-            "Device": utils.get_device(cal_docs=cal_docs),
-            "Helper":{"gas_trans":self.gas_trans, "meas_type_trans":self.meas_type_trans},
-            "Table": utils.get_tables(cal_docs=cal_docs),
-            "MeasurementData":  utils.get_measurement_data(cal_docs=cal_docs),}
+
+        cert = {"RequestId": utils.get_request_id(cal_docs=cal_docs),
+                "Meta": utils.get_meta(cal_docs=cal_docs),
+                "Device": utils.get_device(cal_docs=cal_docs),
+                "Helper":{"gas_trans":self.gas_trans, "meas_type_trans":self.meas_type_trans},
+                "Table": utils.get_tables(cal_docs=cal_docs),
+                "MeasurementData":  utils.get_measurement_data(cal_docs=cal_docs),}
 
         secs = sections.get_all(cert)
         ## needed for replacement of second order templates
@@ -162,75 +154,35 @@ class Trans:
                 template = self.texenv.env.from_string(p)
                 para["Text"] = template.render(cert).strip()
 
-        return {"administrativeData":{
-                "coreData":{
-                    "countryCodeISO3166_1":"DE",
-                    "usedLangCodeISO639_1":"de",
-                    "usedLangCodeISO639_1":"en",
-                    "mandatoryLangCodeISO639_1":lang,
-                    "uniqueIdentifier":"{}PTB{}".format(utils.get_certificate(info_doc),
-                                                        utils.get_current_year(short=True)),
-                    "identifications":{
-                        "identification":[{"issuer":"calibrationLaboratory",
-                                           "value": utils.get_reference_no(info_doc),
-                                           "name":[{"lang":"en",
-                                                           "content": ["Reference No."]},
-                                                          {"lang":"de",
-                                                           "content": ["Geschäftszeichen"]}]}]},
-                    #"receiptDate": utils.get_current_date(),
-                    "beginPerformanceDate": begin_meas_date,
-                    "endPerformanceDate": end_meas_date,
-                    "performanceLocation": "laboratory",},
-                "items":{
-                    "name":[{"lang":lang,
-                             "content":[utils.get_customerobject_type(info_doc)]}],
-                    "item":[{
-                        "identifications":{
-                            "identification":[{"issuer":"manufacturer",
-                                               "value": utils.get_customerobject_device_serial(info_doc),
-                                               "name":[{"lang":"en",
-                                                               "content":["Serial No."]},
-                                                            {"lang":"de",
-                                                             "content":["Kennnummer"]}]}]},
-                        "description":utils.dcc_calibration_object_description(cal_docs, secs),
-                             "name":[{"lang": utils.get_lang(info_doc),
-                                      "content": [utils.get_customerobject_device_type(info_doc)]}],
-                             "manufacturer": {
-                                 "name":[{"lang": utils.get_lang(info_doc),
-                                          "content": [utils.get_customerobject_device_producer(info_doc)]}]}}]},
-                "calibrationLaboratory":{
-                    "contact":{"name":[{"lang":"de",
-                                        "content":["Physikalisch-Technische Bundesanstalt (PTB)"]},
-                                        {"lang":"en",
-                                        "content":["Physikalisch-Technische Bundesanstalt (PTB)"]}],
-                               "eMail":"vacuum.cal@ptb.de",
-                               "location":{
-                                   "further":[{"lang":"en",
-                                               "content":["Working Group 7.54 Vacuum Metrology"]},
-                                              {"lang":"de",
-                                               "content":["Arbeitsgruppe 7.54 Vakuummetrologie"]}],
-                                   "street":"Abbestraße",
-                                   "streetNo": "2--12",
-                                   "postCode": "10587",
-                                   "city":"Berlin",
-                                   "countryCode":"DE"}}},
-                "respPersons":{
-                    "respPerson":[utils.dcc_resp_person(cal_docs, maintainers),
-                                  utils.dcc_meas_maintainer(cal_docs, maintainers)]},
-                "customer": utils.dcc_customer(cal_docs, countries),
-                "dccSoftware":utils.dcc_software(cal_docs),
-                "statements": utils.dcc_statements(cal_docs)},
-            "measurementResults":{
-                "name":[{"lang":"de",
-                        "content":["Ergebnis der Kalibrierung"]},
-                        {"lang":"en",
-                        "content":["Result of the calibration"]}],
-                "usedMethods":{"usedMethod": utils.dcc_used_methodes(cal_docs, secs)},
-                "influenceConditions": utils.dcc_influence_cond(cal_docs,
-                                                                self.gas_trans,
-                                                                self.meas_type_trans,
-                                                                self.dcc_unit_trans),
-                "results": {"result":utils.dcc_result(cal_docs,
-                                                      self.gas_trans,
-                                                      self.meas_type_trans,
-                                                      self.dcc_unit_trans)}}}
+        return {"administrativeData":{"coreData":{"countryCodeISO3166_1":"DE",
+                                                  "usedLangCodeISO639_1":"de",
+                                                  "usedLangCodeISO639_1":"en",
+                                                  "mandatoryLangCodeISO639_1":lang,
+                                                  "uniqueIdentifier": utils.dcc_unique_identifier(info_doc),
+                                                  "identifications": utils.dcc_identification_lab(info_doc),
+                                                  #"receiptDate": utils.get_current_date(),
+                                                  "beginPerformanceDate": begin_meas_date,
+                                                  "endPerformanceDate": end_meas_date,
+                                                  "performanceLocation": "laboratory"},
+                                      "items":{"name":[{"lang":lang, "content":[utils.get_customerobject_type(info_doc)]}],
+                                               "item":[{"identifications": utils.dcc_identification_manufacturer(info_doc),
+                                                        "description":utils.dcc_calibration_object_description(cal_docs, secs),
+                                                        "name":[{"lang": utils.get_lang(info_doc), "content": [utils.get_customerobject_device_type(info_doc)]}],
+                                                        "manufacturer": utils.dcc_manufacturer(info_doc)}]},
+                                      "calibrationLaboratory": utils.dcc_calibration_laboratory(),
+                                      "respPersons":{"respPerson":[utils.dcc_resp_person(cal_docs, maintainers),
+                                                                   utils.dcc_meas_maintainer(cal_docs, maintainers)]},
+                                      "customer": utils.dcc_customer(cal_docs, countries),
+                                      "dccSoftware":utils.dcc_software(cal_docs),
+                                      "statements": utils.dcc_statements(cal_docs)},
+                "measurementResults":{"name":[{"lang":"de", "content":["Ergebnis der Kalibrierung"]},
+                                              {"lang":"en", "content":["Result of the calibration"]}],
+                                      "usedMethods":{"usedMethod": utils.dcc_used_methodes(cal_docs, secs)},
+                                      "influenceConditions": utils.dcc_influence_cond(cal_docs,
+                                                                                      self.gas_trans,
+                                                                                      self.meas_type_trans,
+                                                                                      utils.dcc_unit_trans()),
+                                      "results": {"result":utils.dcc_result(cal_docs,
+                                                                            self.gas_trans,
+                                                                            self.meas_type_trans,
+                                                                            utils.dcc_unit_trans())}}}
diff --git a/cal/utils.py b/cal/utils.py
index 64cd116..9d159ff 100644
--- a/cal/utils.py
+++ b/cal/utils.py
@@ -3,9 +3,7 @@ import git
 import requests
 import datetime
 import re
-
 from flask import  jsonify, Response
-
 from pprint import pprint
 
 def set_filename_header(res, no):
@@ -14,7 +12,7 @@ def set_filename_header(res, no):
     res.headers['Content-Type'] = 'application/x-latex;charset=utf-8'
     res.headers['content-disposition'] = 'attachment'
     res.headers['Access-Control-Expose-Headers'] = 'filename, content-disposition, Server, Date, Content-Type'
-    res.headers['filename'] = '\"ks-{no}-{today}.tex\"'.format( no=no, today=today)
+    res.headers['filename'] = '\"ks-{no}-{today}.tex\"'.format(no=no, today=today)
 
     return res
 
@@ -53,8 +51,8 @@ def get_meta(cal_docs):
             "id":[],
             "kind":[],
             "gas":[],
-            "lang":""
-            }
+            "lang":""}
+
     for i, doc in enumerate(cal_docs):
         meta['skip'].append(should_skipped(doc))
         meta['std'].append(get_std(doc))
@@ -74,7 +72,6 @@ def get_request_id(cal_docs):
     doc = cal_docs[-1]
     return doc.get("Calibration", {}).get("Presettings", {}).get("RequestId")
 
-
 def get_last_cert(cal_docs):
     """Returns the last Cert sign or None.
     """
@@ -199,10 +196,9 @@ def get_calibration_data(cal_docs):
     return doc.get("Calibration", {}).get("Result", {}).get("CalibrationData")
 
 def get_titlepage(cal_docs, countries, maintainers):
-    title = {
-      "ShortYear":get_current_year(short=True),
-      "FullYear": get_current_year(),
-      "CertificateDate": get_current_date(),}
+    title = { "ShortYear":get_current_year(short=True),
+              "FullYear": get_current_year(),
+              "CertificateDate": get_current_date(),}
 
     fs_val = 0.0
     fs_unit = "Pa"
@@ -239,10 +235,58 @@ def get_titlepage(cal_docs, countries, maintainers):
 
     return title
 
-
 def rm_leading_comma(s):
     return re.sub("^,\s" , "", s)
 
+def dcc_unit_trans():
+    return {"1":"\\one",
+            "mbar": "\\hecto\\kilogram\\metre\\tothe{-1}\\second\\tothe{-2}",
+            "Pa":   "\\kilogram\\metre\\tothe{-1}\\second\\tothe{-2}",
+            "1/Pa": "\\kilogram\\tothe{-1}\\metre\\second\\tothe{2}",
+            "K":    "\\kelvin",
+            "A":    "\\ampere"}
+
+def dcc_calibration_laboratory():
+    return {"contact":{"name":[{"lang":"de",
+                                "content":["Physikalisch-Technische Bundesanstalt (PTB)"]},
+                               {"lang":"en",
+                                "content":["Physikalisch-Technische Bundesanstalt (PTB)"]}],
+                       "eMail": "vacuum.cal@ptb.de",
+                       "location":{
+                           "further":[{"lang": "en",
+                                       "content":["Working Group 7.54 Vacuum Metrology"]},
+                                    {"lang": "de",
+                                     "content":["Arbeitsgruppe 7.54 Vakuummetrologie"]}],
+                           "street": "Abbestraße",
+                           "streetNo": "2--12",
+                           "postCode": "10587",
+                           "city": "Berlin",
+                           "countryCode": "DE"}}}
+
+def dcc_unique_identifier(info_doc):
+    return "{}PTB{}".format(get_certificate(info_doc), get_current_year(short=True))
+
+
+def dcc_identification_lab(info_doc):
+    return {"identification":[{"issuer":"calibrationLaboratory",
+                               "value": get_reference_no(info_doc),
+                               "name":[{"lang":"en",
+                                        "content": ["Reference No."]},
+                                       {"lang":"de",
+                                        "content": ["Geschäftszeichen"]}]}]}
+
+def dcc_manufacturer(info_doc):
+    return {"name":[{"lang": get_lang(info_doc),
+                     "content": [get_customerobject_device_producer(info_doc)]}]}
+
+def dcc_identification_manufacturer(info_doc):
+    return {"identification":[{"issuer":"manufacturer",
+                               "value": get_customerobject_device_serial(info_doc),
+                               "name":[{"lang":"en",
+                                        "content":["Serial No."]},
+                                       {"lang":"de",
+                                        "content":["Kennnummer"]}]}]}
+
 def dcc_result(cal_docs, gas_trans, meas_type_trans, unit_trans):
 
     result = []
@@ -328,15 +372,13 @@ def dcc_sigma_result(doc, dcc_unit_trans ):
     return res
 
 def dcc_gen_real(val, unit, uncert, cover, prob):
-    return {"value":val,
-                    "unit":unit,
-                    "expandedUnc":{
-                        "uncertainty":uncert,
-                        "coverageFactor": cover,
-                        "coverageProbability": prob,}}
+    return {"value": val,
+            "unit": unit,
+            "expandedUnc":{"uncertainty": uncert,
+                           "coverageFactor": cover,
+                           "coverageProbability": prob}}
 
 def dcc_influence_cond(cal_docs, gas_trans, meas_type_trans, unit_trans):
-
     influence_cond = {"name":[{"lang":"de",
                                "content":["Die Kalibrierung wurde bei folgenden Umgebungsbedingungen ausgeführt"]},
                               {"lang":"en",
-- 
GitLab