diff --git a/API-V2-elab.py b/API-V2-elab.py index 5f91c1e34f363c9a008c5fb35d9d5f3f938f06cb..e1375b0fe7f7f9e60ccaaa237ec2470827af83e5 100644 --- a/API-V2-elab.py +++ b/API-V2-elab.py @@ -1,232 +1,233 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Jul 5 09:51:18 2023 - -@author: becker07 -""" - -#!/usr/bin/env python -import os -import time -import datetime -import elabapi_python -from elabapi_python.rest import ApiException -import requests -import json -import couchdb -import numpy as np -from urllib3.exceptions import InsecureRequestWarning -from urllib3 import disable_warnings - - -couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') -db = couch['vl_db'] # existing - -######################### -# CONFIG # -######################### -API_HOST_URL = 'https://elabftw.ptb.de/api/v2' -# replace with your api key -API_KEY = 'a2c6b77fdd5b19b35b3043dbfd5ac73883c4265ab210a3672037ace64a6207cfa4231a0a834ed30c19be8' -# number of days to look back - -######################### -# END CONFIG # -######################### - -# Configure the api client -configuration = elabapi_python.Configuration() -configuration.api_key['api_key'] = API_KEY -configuration.api_key_prefix['api_key'] = 'Authorization' -configuration.host = API_HOST_URL -configuration.debug = False -configuration.verify_ssl = True - -# create an instance of the API class -api_client = elabapi_python.ApiClient(configuration) -# fix issue with Authorization header not being properly set by the generated lib -api_client.set_default_header(header_name='Authorization', header_value=API_KEY) - -# create an instance of Experiments -experimentsApi = elabapi_python.ExperimentsApi(api_client) -uploadsApi = elabapi_python.UploadsApi(api_client) - -# create an instance of Tags -api_instance = elabapi_python.TagsApi(api_client) - -# calculate the date -today = datetime.date.today() - -######## - -elab_id=640 -cers = ["75562_0001","75563_0001","75564_0001","75565_0001","75566_0001","75567_0001","75568_0001","75569_0001","75570_0001","75571_0001","75572_0001","75573_0001"] # Beispiel: cers = ["75511_0001","75512_0001"] -TL1_2= "FM1" #### FM1 oder TLA - -year = "2024" -kk= "KK" -commentar = '' - -################################ - - -# get experiment with ID xxxx -exp = experimentsApi.get_experiment(elab_id) -print('='*72) -print('\n ******** Experiment {} (Original): \n'.format(elab_id), exp) -print('\n ******** Experiment-Body ', exp.body) -print('\n ******** Experiment-Tags ', exp.userid) -print('='*72) - - - - -################################# - -if kk == "KK": - type_k = "-kk-" - tag_type = "KK" - -################################# - -if TL1_2 == "TLA": - tl="-tl2" - json_file = "cal-" + year + tl + type_k + cers[0] - print(json_file) - doc = db.get(json_file) - STD1 ="TLA" - STD2 ="TL2" - tab_begin=' </p><table style="border-collapse:collapse;width:100%;height:100%;"><tr style="height:16px;"><td style="width:33.3222%;height:16px;">DB-Link</td><td style="width:33.3222%;height:16px;">p-upstream</td><td style="width:33.3222%;height:16px;">Gas</td></tr>' - -else : - tl="-fm1" - json_file = "cal-" + year + tl + type_k + cers[0] - print(json_file) - doc = db.get(json_file) - Type_k =(doc["Calibration"]["Type"]) - STD1 ="TLV" - STD2 ="FM1" - tab_begin=' </p><table style="border-collapse:collapse;width:100%;height:100%;"><tr style="height:16px;"><td style="width:33.3222%;height:16px;">DB-Link</td><td style="width:33.3222%;height:16px;">Ventil</td><td style="width:33.3222%;height:16px;">Gas</td></tr>' - - -# Die Überschrift wird zusammengesetzt -title1=doc["Calibration"]["Customer"]["Sign"] -body_title = STD1 + ' / ' + STD2 + ' Kalibrierung [' + title1 + ']' - - -# Die Tabelle wird zusammengesetzt -body_begin='<p> ' -#tab_begin=' </p><table style="border-collapse:collapse;width:100%;height:100%;"><tr style="height:16px;"><td style="width:33.3222%;height:16px;">DB-Link</td><td style="width:33.3222%;height:16px;">p-upstream</td><td style="width:33.3222%;height:16px;">Gas</td></tr>' -text1='<tr style="height:16px;"><td style="width:33.3222%;height:16px;"><a href="http://a73434.berlin.ptb.de:5984/_utils/#database/vl_db/' -text1_1='tl2' -text1_2='-' -text1_3='kk' -text1_4='-' -text2='" target="_blank" rel="noreferrer noopener">cal-' -text3='</a></td><td style="width:33.3222%;height:16px;">' -text4='</td><td style="width:33.3222%;height:16px;">' -text5='</td></tr>' -tab_end='</table><p> </p><p> </p>' - - - -# Die Tags werden zusammengesetzt -json_file_tag = "cal-" + year + tl + type_k + cers[0] -doc_tag = db.get(json_file_tag) -ReferenceNo =doc_tag["Calibration"]["Presettings"]["CommonReferenceNo"] -print('stopp') - -Type_k =(doc_tag["Calibration"]["Type"]) -CustomerSign =(doc_tag["Calibration"]["Customer"]["Sign"]) - - - -len_cers=len(cers) - -val = "" -size = len_cers -tab_body = [val] * size -p_up = [val] * size -gas = [val] * size -vent = [val] * size -print('111111111', tab_body) - - -if TL1_2 == 'TLA': - - i = 0 - while i < len(cers): - json_file = "cal-" + year + tl + type_k + cers[i] - print(json_file) - doc = db.get(json_file) - p_up[i]=doc["Calibration"]["Result"]["Formula"]["PressureUpstream"] - gas[i]=doc["Calibration"]["ToDo"]["Gas"] - body=text1 + json_file + text2+ year +tl + type_k + cers[i]+ text3 + p_up[i] + text4 + gas[i] + text5 - tab_body[i] = body - p_up[i]=np.array(doc["Calibration"]["Result"]["Formula"]["PressureUpstream"]) - - - i += 1 -else : - i = 0 - while i < len(cers): - json_file = "cal-" + year + tl + type_k + cers[i] - print(json_file) - x = cers[i][:5] - doc = db.get(json_file) - name_plot= "Scan_" + x + ".pdf" - file_plot= 'C:/Users/becker07/python/TL1/' + name_plot - name_Scan_json= "Scan" + x + ".pdf" - file_json= 'C:/Users/becker07/python/TL1/' + name_Scan_json - attachment = db.get_attachment(doc, "Scan.pdf").read() - with open(file_json, 'wb') as pdf_object: - pdf_object.write(attachment) - uploadsApi.post_upload('experiments', elab_id, file=file_json, comment='Plot: Signal und Offset vom Leck') - os.remove(file_json) - gas[i]=doc["Calibration"]["ToDo"]["Gas"] - vent[i]=doc["Calibration"]["Result"]["Formula"]["Valve"] - body=text1 + json_file + text2 + year + tl + type_k + cers[i]+ text3 + vent[i] + text4 + gas[i] + text5 - tab_body[i] = body - i += 1 - - -text_all= ''.join(tab_body) - -body_tab=body_begin + commentar + tab_begin + text_all + tab_end - - -now = datetime.datetime.now() - -#new_body='<p>Neu von UteXX x({})</p>'.format(now.strftime('%Y-%m-%d %H:%M:%S')) - - -data_body = { 'body': body_tab} -data_title = {'title': body_title} - - -print('elab_id= ', elab_id) - -# === Modifizieren der Einträge (hier Eintrag "body") === -response_body = experimentsApi.patch_experiment(elab_id, body=data_body) -response_title = experimentsApi.patch_experiment(elab_id, body=data_title) -data_tag={ 'tag': ReferenceNo} -response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) -data_tag={ 'tag': Type_k} -response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) -data_tag={ 'tag': STD1} -response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) -data_tag={ 'tag': STD2} -response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) -data_tag={ 'tag': CustomerSign} -response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) -#response = experimentsApi.patch_experiment(elab_id, tags=new_tags) -print('='*72) -# === der modifizierte Zustand === -print('\n******** Experiment {} (modifiziert): \n'.format(elab_id), response_body) -print('='*72) - - - - - - +# -*- coding: utf-8 -*- +""" +Created on Wed Jul 5 09:51:18 2023 + +@author: becker07 +""" + +#!/usr/bin/env python +import os +import time +import datetime +import elabapi_python +from elabapi_python.rest import ApiException +import requests +import json +import couchdb +import numpy as np +from urllib3.exceptions import InsecureRequestWarning +from urllib3 import disable_warnings + + +couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') +db = couch['vl_db'] # existing + +######################### +# CONFIG # +######################### +API_HOST_URL = 'https://elabftw.ptb.de/api/v2' +# replace with your api key +API_KEY = 'a2c6b77fdd5b19b35b3043dbfd5ac73883c4265ab210a3672037ace64a6207cfa4231a0a834ed30c19be8' +# number of days to look back + +######################### +# END CONFIG # +######################### + +# Configure the api client +configuration = elabapi_python.Configuration() +configuration.api_key['api_key'] = API_KEY +configuration.api_key_prefix['api_key'] = 'Authorization' +configuration.host = API_HOST_URL +configuration.debug = False +configuration.verify_ssl = True + +# create an instance of the API class +api_client = elabapi_python.ApiClient(configuration) +# fix issue with Authorization header not being properly set by the generated lib +api_client.set_default_header(header_name='Authorization', header_value=API_KEY) + +# create an instance of Experiments +experimentsApi = elabapi_python.ExperimentsApi(api_client) +uploadsApi = elabapi_python.UploadsApi(api_client) + +# create an instance of Tags +api_instance = elabapi_python.TagsApi(api_client) + +# calculate the date +today = datetime.date.today() + +######## + +elab_id=643 +cers = ["75552_0001","75553_0001"] # Beispiel: cers = ["75511_0001","75512_0001"] +TL1_2= "TLA" #### FM1 oder TLA + +year = "2024" +kk= "KK" +commentar = '' + +################################ + + +# get experiment with ID xxxx +exp = experimentsApi.get_experiment(elab_id) +print('='*72) +print('\n ******** Experiment {} (Original): \n'.format(elab_id), exp) +print('\n ******** Experiment-Body ', exp.body) +print('\n ******** Experiment-Tags ', exp.userid) +print('='*72) + + + + +################################# + +if kk == "KK": + type_k = "-kk-" + tag_type = "KK" + +################################# + +if TL1_2 == "TLA": + tl="-tl2" + json_file = "cal-" + year + tl + type_k + cers[0] + print(json_file) + doc = db.get(json_file) + STD1 ="TLA" + STD2 ="TL2" + tab_begin=' </p><table style="border-collapse:collapse;width:100%;height:100%;"><tr style="height:16px;"><td style="width:33.3222%;height:16px;">DB-Link</td><td style="width:33.3222%;height:16px;">p-upstream</td><td style="width:33.3222%;height:16px;">Gas</td></tr>' + +else : + tl="-fm1" + json_file = "cal-" + year + tl + type_k + cers[0] + print(json_file) + doc = db.get(json_file) + Type_k =(doc["Calibration"]["Type"]) + STD1 ="TLV" + STD2 ="FM1" + tab_begin=' </p><table style="border-collapse:collapse;width:100%;height:100%;"><tr style="height:16px;"><td style="width:33.3222%;height:16px;">DB-Link</td><td style="width:33.3222%;height:16px;">Ventil</td><td style="width:33.3222%;height:16px;">Gas</td></tr>' + + +# Die Überschrift wird zusammengesetzt +title1=doc["Calibration"]["Customer"]["Sign"] +body_title = STD1 + ' / ' + STD2 + ' Kalibrierung [' + title1 + ']' + + +# Die Tabelle wird zusammengesetzt +body_begin='<p> ' +#tab_begin=' </p><table style="border-collapse:collapse;width:100%;height:100%;"><tr style="height:16px;"><td style="width:33.3222%;height:16px;">DB-Link</td><td style="width:33.3222%;height:16px;">p-upstream</td><td style="width:33.3222%;height:16px;">Gas</td></tr>' +text1='<tr style="height:16px;"><td style="width:33.3222%;height:16px;"><a href="http://a73434.berlin.ptb.de:5984/_utils/#database/vl_db/' +text1_1='tl2' +text1_2='-' +text1_3='kk' +text1_4='-' +text2='" target="_blank" rel="noreferrer noopener">cal-' +text3='</a></td><td style="width:33.3222%;height:16px;">' +text4='</td><td style="width:33.3222%;height:16px;">' +text5='</td></tr>' +tab_end='</table><p> </p><p> </p>' + + + +# Die Tags werden zusammengesetzt +json_file_tag = "cal-" + year + tl + type_k + cers[0] +doc_tag = db.get(json_file_tag) +ReferenceNo =doc_tag["Calibration"]["Presettings"]["CommonReferenceNo"] +print('stopp') + +Type_k =(doc_tag["Calibration"]["Type"]) +print(Type_k) +CustomerSign =(doc_tag["Calibration"]["Customer"]["Sign"]) + + + +len_cers=len(cers) + +val = "" +size = len_cers +tab_body = [val] * size +p_up = [val] * size +gas = [val] * size +vent = [val] * size +print('111111111', tab_body) + + +if TL1_2 == 'TLA': + + i = 0 + while i < len(cers): + json_file = "cal-" + year + tl + type_k + cers[i] + print(json_file) + doc = db.get(json_file) + p_up[i]=doc["Calibration"]["Result"]["Formula"]["PressureUpstream"] + gas[i]=doc["Calibration"]["ToDo"]["Gas"] + body=text1 + json_file + text2+ year +tl + type_k + cers[i]+ text3 + p_up[i] + text4 + gas[i] + text5 + tab_body[i] = body + p_up[i]=np.array(doc["Calibration"]["Result"]["Formula"]["PressureUpstream"]) + + + i += 1 +else : + i = 0 + while i < len(cers): + json_file = "cal-" + year + tl + type_k + cers[i] + print(json_file) + x = cers[i][:5] + doc = db.get(json_file) + name_plot= "Scan_" + x + ".pdf" + file_plot= 'C:/Users/becker07/python/TL1/' + name_plot + name_Scan_json= "Scan" + x + ".pdf" + file_json= 'C:/Users/becker07/python/TL1/' + name_Scan_json + attachment = db.get_attachment(doc, "Scan.pdf").read() + with open(file_json, 'wb') as pdf_object: + pdf_object.write(attachment) + uploadsApi.post_upload('experiments', elab_id, file=file_json, comment='Plot: Signal und Offset vom Leck') + os.remove(file_json) + gas[i]=doc["Calibration"]["ToDo"]["Gas"] + vent[i]=doc["Calibration"]["Result"]["Formula"]["Valve"] + body=text1 + json_file + text2 + year + tl + type_k + cers[i]+ text3 + vent[i] + text4 + gas[i] + text5 + tab_body[i] = body + i += 1 + + +text_all= ''.join(tab_body) + +body_tab=body_begin + commentar + tab_begin + text_all + tab_end + + +now = datetime.datetime.now() + +#new_body='<p>Neu von UteXX x({})</p>'.format(now.strftime('%Y-%m-%d %H:%M:%S')) + + +data_body = { 'body': body_tab} +data_title = {'title': body_title} + + +print('elab_id= ', elab_id) + +# === Modifizieren der Einträge (hier Eintrag "body") === +response_body = experimentsApi.patch_experiment(elab_id, body=data_body) +response_title = experimentsApi.patch_experiment(elab_id, body=data_title) +data_tag={ 'tag': ReferenceNo} +response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) +data_tag={ 'tag': Type_k} +response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) +data_tag={ 'tag': STD1} +response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) +data_tag={ 'tag': STD2} +response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) +data_tag={ 'tag': CustomerSign} +response_tag = api_instance.post_tag('experiments', elab_id, body=data_tag) +#response = experimentsApi.patch_experiment(elab_id, tags=new_tags) +print('='*72) +# === der modifizierte Zustand === +print('\n******** Experiment {} (modifiziert): \n'.format(elab_id), response_body) +print('='*72) + + + + + + diff --git a/attachment_cer.py b/attachment_cer.py index e9a733243e2292832b229a38efaf3a32329b0efa..3e23f079b3b56ad278c9cfdb2fd5063549d8c3a9 100644 --- a/attachment_cer.py +++ b/attachment_cer.py @@ -1,69 +1,69 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Jan 6 11:14:44 2023 - -@author: becker07 -""" - -import pathlib -import os - -import couchdb - - -couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') -db = couch['vl_db'] # existing - - -year = "2024" - -cers = ["75564","75565","75566","75567","75568","75569","75570","75571","75572","75573"] # Beispiel: cers = ["75511_0001","75512_0001"] -#cers = ["75562","75563"] # Beispiel: cers = ["75511_0001","75512_0001"] - -################### die Kalibrierscheine werden an das cer-json-dokument angehangen ################## -i = 0 -while i < len(cers): - json_file = "cer-" + year + '-' + cers[i] - print(json_file) - doc = db.get(json_file) - cer_pdf= "ks-" +cers[i] + "-" + year + ".pdf" - cer_tex= "ks-" +cers[i] + "-" + year + ".tex" - print(cer_pdf, cer_tex) - ks_pdf = "C:\\Users\\becker07\\kalibrierschein\\" + cer_pdf - ks_tex = "C:\\Users\\becker07\\kalibrierschein\\" + cer_tex - print(ks_pdf, ks_tex) - content_pdf=pathlib.Path(ks_pdf).read_bytes() - content_tex=pathlib.Path(ks_tex).read_bytes() - db.put_attachment(doc, content_pdf, cer_pdf , content_type='application/pdf') - db.put_attachment(doc, content_tex, cer_tex , content_type='text/plain') - - i += 1 - - -################### die Kalibrierscheine werden im Ordner Kalibrierscheine gelöscht ################## - -i = 0 -while i < len(cers): - json_file = "cer-" + year + '-' + cers[i] - print(json_file) - doc = db.get(json_file) - cer_pdf= "ks-" +cers[i] + "-" + year + ".pdf" - cer_tex= "ks-" +cers[i] + "-" + year + ".tex" - cer_aux= "ks-" +cers[i] + "-" + year + ".aux" - cer_log= "ks-" +cers[i] + "-" + year + ".log" - cer_gz= "ks-" +cers[i] + "-" + year + ".synctex.gz" - print(cer_pdf, cer_tex) - ks_pdf = "C:\\Users\\becker07\\kalibrierschein\\" + cer_pdf - ks_tex = "C:\\Users\\becker07\\kalibrierschein\\" + cer_tex - ks_aux = "C:\\Users\\becker07\\kalibrierschein\\" + cer_aux - ks_log = "C:\\Users\\becker07\\kalibrierschein\\" + cer_log - ks_gz = "C:\\Users\\becker07\\kalibrierschein\\" + cer_gz - - print(ks_pdf, ks_tex) - os.remove(ks_pdf) - os.remove(ks_tex) - os.remove(ks_aux) - os.remove(ks_log) - os.remove(ks_gz) - +# -*- coding: utf-8 -*- +""" +Created on Fri Jan 6 11:14:44 2023 + +@author: becker07 +""" + +import pathlib +import os + +import couchdb + + +couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') +db = couch['vl_db'] # existing + + +year = "2024" + +cers = ["75552","75553"] # Beispiel: cers = ["75511_0001","75512_0001"] +#cers = ["75562","75563"] # Beispiel: cers = ["75511_0001","75512_0001"] + +################### die Kalibrierscheine werden an das cer-json-dokument angehangen ################## +i = 0 +while i < len(cers): + json_file = "cer-" + year + '-' + cers[i] + print(json_file) + doc = db.get(json_file) + cer_pdf= "ks-" +cers[i] + "-" + year + ".pdf" + cer_tex= "ks-" +cers[i] + "-" + year + ".tex" + print(cer_pdf, cer_tex) + ks_pdf = "C:\\Users\\becker07\\kalibrierschein\\" + cer_pdf + ks_tex = "C:\\Users\\becker07\\kalibrierschein\\" + cer_tex + print(ks_pdf, ks_tex) + content_pdf=pathlib.Path(ks_pdf).read_bytes() + content_tex=pathlib.Path(ks_tex).read_bytes() + db.put_attachment(doc, content_pdf, cer_pdf , content_type='application/pdf') + db.put_attachment(doc, content_tex, cer_tex , content_type='text/plain') + + i += 1 + + +################### die Kalibrierscheine werden im Ordner Kalibrierscheine gelöscht ################## + +i = 0 +while i < len(cers): + json_file = "cer-" + year + '-' + cers[i] + print(json_file) + doc = db.get(json_file) + cer_pdf= "ks-" +cers[i] + "-" + year + ".pdf" + cer_tex= "ks-" +cers[i] + "-" + year + ".tex" + cer_aux= "ks-" +cers[i] + "-" + year + ".aux" + cer_log= "ks-" +cers[i] + "-" + year + ".log" + cer_gz= "ks-" +cers[i] + "-" + year + ".synctex.gz" + print(cer_pdf, cer_tex) + ks_pdf = "C:\\Users\\becker07\\kalibrierschein\\" + cer_pdf + ks_tex = "C:\\Users\\becker07\\kalibrierschein\\" + cer_tex + ks_aux = "C:\\Users\\becker07\\kalibrierschein\\" + cer_aux + ks_log = "C:\\Users\\becker07\\kalibrierschein\\" + cer_log + ks_gz = "C:\\Users\\becker07\\kalibrierschein\\" + cer_gz + + print(ks_pdf, ks_tex) + os.remove(ks_pdf) + os.remove(ks_tex) + os.remove(ks_aux) + os.remove(ks_log) + os.remove(ks_gz) + i += 1 \ No newline at end of file diff --git a/file-to-couchdb_TLA.py b/file-to-couchdb_TLA.py index a855f438a606cba48d0c6972617123060240c4d0..fa4f7eecd4142d6a88fff2c0e28851ed9bbdf938 100644 --- a/file-to-couchdb_TLA.py +++ b/file-to-couchdb_TLA.py @@ -1,150 +1,155 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Jul 1 12:12:37 2022 - -@author: becker07 -""" - -from matplotlib import pyplot as plt -from statistics import mean -from datetime import datetime -#from IPython.display import Markdown as md -import numpy as np -import math -import statistics -import pandas as pd -import json -import couchdb -from pathlib import Path -couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') -db = couch['vl_db'] # existing - - -## Eingabe von: -# - Kalibrierscheinnummer -# - Jahr der Kalibrierung -# - laufende Nummer der Kalibrierung - - - -cal_cert = "75553" -year = "2024" -no = "0001" - -pfad = Path("P:\TLA\Messdaten") -print(pfad) -#exit() - -json_file = "cal-" + year + "-tl2-kk-" + cal_cert + "_" + no -doc = db.get(json_file) - -# Die Daten aus dem File mit der entsprechenden Kalibrierscheinnummer werden eingelesen: -# datum, time, p_up und alle Temperaturen, - -datei = cal_cert + "PTB" + year -datei_S = cal_cert + "PTB" + year + "_S" -print(json_file) - -datei_pkt = pd.read_csv(pfad.joinpath(datei), sep="\t", decimal = ',' ) -datei_S_pkt = pd.read_csv(pfad.joinpath(datei_S), sep="\t", decimal = ',' ) -datum=datei_pkt["Datum"] -time=datei_pkt["Zeit"] -p_up=datei_pkt["Druck"] - -p_up=np.array(p_up) -p_up = np.asarray(p_up, dtype=float) - -q_tab=datei_pkt["q_mol"] -T_room=datei_pkt["Raumtemperatur"] -T_h2o=datei_pkt["T-H2O"] -T_wv=datei_pkt["T-WV"] -T_tl=datei_pkt["T-TL"] -T_rv=datei_pkt["T-RV"] -p_atm=datei_pkt["Umgebungsdruck p_0"]*100 # Umrechnung in Pa -m_sz = datei_pkt["m-SZ"] -m1_drift = datei_pkt["m1_D"] -m2_drift = datei_pkt["m2_D"] -print(p_atm) -# Die Werte der Sägezähne befinden sich im File "Kalibrierscheinnummer_S". -# Da pro Messpunkt 2 Sägezähne gefahren werden, existieren auch für jeden Messpunkt -# jeweils zwei Zeiten t_i und zwei Hübe l_1 - -l_1=datei_S_pkt["pos1_i"] -l_2=datei_S_pkt["pos2_i"] -l_pos= l_1-l_2 -l_i=datei_S_pkt["h_i"] -t_i=datei_S_pkt["t_i"] - -# Im File Datei_S sind die einzelnen Hübe l_i der Nadel in einer Spalte gespeichert, der Hub l -# muss daher in Hub l_1 und l_2 aufgegliedert werden, da in der Regel 2 Sägezähne gefahren werden. -l_1=l_pos[0::2] # Begonnen wird in der Spalte beim Element 0 bis zum Ende der Spalte in zweier Schritte -l_2=l_pos[1::2] # Begonnen wird in der Spalte beim Element 1 bis zum Ende der Spalte in zweier Schritte - - - -#l_1=np.genfromtxt(datei_S,skip_header=1,usecols=(2)) #### wenn nur 1 SZ vorhanden - - - -# Das gleiche gilt für die Zeit t_i -t_1=t_i[0::2] # Begonnen wird in der Spalte beim Element 0 bis zum Ende der Spalte in zweier Schritte -t_2=t_i[1::2] # Begonnen wird in der Spalte beim Element 1 bis zum Ende der Spalte in zweier Schritte -#t_1=np.genfromtxt(datei_S,skip_header=1,usecols=(3))#### wenn nur 1 SZ vorhanden - -# Temperatur -lis_T_h2o = T_h2o.tolist() -lis_T_room = T_room.tolist() -lis_T_tl = T_tl.tolist() -lis_T_wv = T_wv.tolist() -lis_T_rv = T_rv.tolist() -# Druck -lis_p_atm = p_atm.tolist() -lis_p_up = p_up.tolist() -# Drift -lis_m1_drift = m1_drift.tolist() -lis_m2_drift = m2_drift.tolist() -lis_m_sz = m_sz.tolist() -# Datum -lis_date = datum.tolist() -lis_dtime = time.tolist() - -lis_l1 = l_1.tolist() -lis_l2 = l_2.tolist() -lis_t1 = t_1.tolist() -lis_t2 = t_2.tolist() - -print(lis_l1 ,lis_l2 ,lis_t1 ,lis_t2 ) - -datum_meas = lis_date[0:1] - - -print(lis_T_room) - - - - -doc["Calibration"]["Measurement"]["Values"]={"Temperature": [{"Unit": "C","Type": "T-H2O ","Comment":"Temperatur T ","Value": lis_T_h2o}, - {"Unit": "C","Type": "T-Room","Comment":"Temperatur T","Value": lis_T_room}, - {"Unit": "C","Type": "T-TL ","Comment":"Temperatur T","Value": lis_T_tl}, - {"Unit": "C","Type": "T-WV ","Comment":"Temperatur T","Value": lis_T_wv}, - {"Unit": "C","Type": "T-RV ","Comment":"Temperatur T","Value": lis_T_rv}], - "Pressure": [{"Unit": "mbar","Type": "Atmosparic pressure ","Value": lis_p_atm}, - {"Unit": "bar","Type": "Upstream pressure ","Value": lis_p_up}], - "Time": [{"Unit": "s","Type": "Zeit des ersten Sägezahns ","Value": lis_t1}, - {"Unit": "s","Type": "Zeit des zweiten Sägezahns ","Value": lis_t2}], - "L": [{"Unit": "mm","Type": "Hub des ersten Sägezahns ","Value": lis_l1}, - {"Unit": "mm","Type": "Hub des zweiten Sägezahns ","Value": lis_l2}], - "Drift": [{"Unit": "mbar/s","Type": "Steigung des Sägezahns ","Value": lis_m_sz}, - {"Unit": "mbar/s","Type": "Drift des ersten Sägezahns ","Value": lis_m1_drift}, - {"Unit": "mbar/s","Type": "Drift des zweiten Sägezahns ","Value": lis_m2_drift}], - "DateTime": [{"Unit": "yyyy-mm-dd","Type": "Date ","Value": lis_date}, - {"Unit": "hh:mm","Type": "Time ","Value": lis_dtime}]} - - - -doc["Calibration"]["Measurement"]["Date"]=[{"Type": "measurement","Value":datum_meas}] - - -db.save(doc) - - +# -*- coding: utf-8 -*- +""" +Created on Fri Jul 1 12:12:37 2022 + +@author: becker07 +""" + +from matplotlib import pyplot as plt +from statistics import mean +from datetime import datetime +from IPython.display import Markdown as md +import numpy as np +import math +import statistics +import pandas as pd +import json +import couchdb +couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') +db = couch['vl_db'] # existing + + +## Eingabe von: +# - Kalibrierscheinnummer +# - Jahr der Kalibrierung +# - laufende Nummer der Kalibrierung + + + +cal_cert = "75556" +year = "2024" +no = "0001" + + +json_file = "cal-" + year + "-tl2-kk-" + cal_cert + "_" + no +doc = db.get(json_file) + +# Die Daten aus dem File mit der entsprechenden Kalibrierscheinnummer werden eingelesen: +# datum, time, p_up und alle Temperaturen, +path='C:\\Users\\becker07\\python\\TL2\\' +datei = path + cal_cert + "PTB" + year +datei_S = path + cal_cert + "PTB" + year + "_S" +print(json_file) + +datei_pkt = pd.read_csv(datei, sep="\t", decimal = ',' ) +datei_S_pkt = pd.read_csv(datei_S, sep="\t", decimal = ',' ) +datum=datei_pkt["Datum"] +time=datei_pkt["Zeit"] +p_up=datei_pkt["Druck"] + +p_up=np.array(p_up) +p_up = np.asarray(p_up, dtype=float) + +q_tab=datei_pkt["q_mol"] +T_room=datei_pkt["Raumtemperatur"] +T_h2o=datei_pkt["T-H2O"] +T_wv=datei_pkt["T-WV"] +T_tl=datei_pkt["T-TL"] +T_rv=datei_pkt["T-RV"] +p_atm=datei_pkt["Umgebungsdruck p_0"]*100 # Umrechnung in Pa + + +m1_drift = datei_pkt["m1_D"] +m2_drift = datei_pkt["m2_D"] +print(p_atm) +# Die Werte der Sägezähne befinden sich im File "Kalibrierscheinnummer_S". +# Da pro Messpunkt 2 Sägezähne gefahren werden, existieren auch für jeden Messpunkt +# jeweils zwei Zeiten t_i und zwei Hübe l_1 + +l_1=datei_S_pkt["pos1_i"] +l_2=datei_S_pkt["pos2_i"] +l_pos= l_1-l_2 +l_i=datei_S_pkt["h_i"] +t_i=datei_S_pkt["t_i"] +m_sz_i =datei_S_pkt["m_i"] + + +# Im File Datei_S sind die einzelnen Hübe l_i der Nadel in einer Spalte gespeichert, der Hub l +# muss daher in Hub l_1 und l_2 aufgegliedert werden, da in der Regel 2 Sägezähne gefahren werden. +l_1=l_pos[0::2] # Begonnen wird in der Spalte beim Element 0 bis zum Ende der Spalte in zweier Schritte +l_2=l_pos[1::2] # Begonnen wird in der Spalte beim Element 1 bis zum Ende der Spalte in zweier Schritte + + +#l_1=np.genfromtxt(datei_S,skip_header=1,usecols=(2)) #### wenn nur 1 SZ vorhanden + + + +# Das gleiche gilt für die Zeit t_i +t_1=t_i[0::2] # Begonnen wird in der Spalte beim Element 0 bis zum Ende der Spalte in zweier Schritte +t_2=t_i[1::2] # Begonnen wird in der Spalte beim Element 1 bis zum Ende der Spalte in zweier Schritte +#t_1=np.genfromtxt(datei_S,skip_header=1,usecols=(3))#### wenn nur 1 SZ vorhanden + + +# Das gleiche gilt für den SZ m_sz__i +m_sz_1=m_sz_i[0::2] # Begonnen wird in der Spalte beim Element 0 bis zum Ende der Spalte in zweier Schritte +m_sz_2=m_sz_i[1::2] # Begonnen wird in der Spalte beim Element 1 bis zum Ende der Spalte in zweier Schritte + +# Temperatur +lis_T_h2o = T_h2o.tolist() +lis_T_room = T_room.tolist() +lis_T_tl = T_tl.tolist() +lis_T_wv = T_wv.tolist() +lis_T_rv = T_rv.tolist() +# Druck +lis_p_atm = p_atm.tolist() +lis_p_up = p_up.tolist() +# Drift +lis_m1_drift = m1_drift.tolist() +lis_m2_drift = m2_drift.tolist() +lis_m1_sz = m_sz_1.tolist() +lis_m2_sz = m_sz_2.tolist() +# Datum +lis_date = datum.tolist() +lis_dtime = time.tolist() + +lis_l1 = l_1.tolist() +lis_l2 = l_2.tolist() +lis_t1 = t_1.tolist() +lis_t2 = t_2.tolist() + +print(lis_l1 ,lis_l2 ,lis_t1 ,lis_t2 ) + +datum_meas = lis_date[0:1] + + +print(lis_T_room) + + + + +doc["Calibration"]["Measurement"]["Values"]={"Temperature": [{"Unit": "C","Type": "T-H2O","Comment":"Temperatur T ","Value": lis_T_h2o}, + {"Unit": "C","Type": "T-Room","Comment":"Temperatur T","Value": lis_T_room}, + {"Unit": "C","Type": "T-TL","Comment":"Temperatur T","Value": lis_T_tl}, + {"Unit": "C","Type": "T-WV","Comment":"Temperatur T","Value": lis_T_wv}, + {"Unit": "C","Type": "T-RV","Comment":"Temperatur T","Value": lis_T_rv}], + "Pressure": [{"Unit": "Pa","Type": "Atmosparic pressure","Value": lis_p_atm}, + {"Unit": "bar","Type": "Upstream pressure","Value": lis_p_up}], + "Time": [{"Unit": "s","Type": "Zeit des ersten Saegezahns","Value": lis_t1}, + {"Unit": "s","Type": "Zeit des zweiten Saegezahns","Value": lis_t2}], + "L": [{"Unit": "mm","Type": "Hub des ersten Saegezahns","Value": lis_l1}, + {"Unit": "mm","Type": "Hub des zweiten Saegezahns","Value": lis_l2}], + "Drift": [{"Unit": "Pa/s","Type": "Steigung des ersten Saegezahns","Value": lis_m1_sz}, + {"Unit": "Pa/s","Type": "Steigung des zweiten Saegezahns","Value": lis_m2_sz}, + {"Unit": "Pa/s","Type": "Drift des ersten Saegezahns","Value": lis_m1_drift}, + {"Unit": "Pa/s","Type": "Drift des zweiten Saegezahns","Value": lis_m2_drift}], + "DateTime": [{"Unit": "yyyy-mm-dd","Type": "Date","Value": lis_date}, + {"Unit": "hh:mm","Type": "Time ","Value": lis_dtime}]} + + + +doc["Calibration"]["Measurement"]["Date"]=[{"Type": "measurement","Value":datum_meas}] + + +db.save(doc) + + diff --git a/writeLaTeX-ks-TLA.py b/writeLaTeX-ks-TLA.py index 6982c47df29bdfd78874f99de097c57afd8e1051..b0b61cc9aa857fcb2f9c6800cb37f9ac3a4ae52d 100644 --- a/writeLaTeX-ks-TLA.py +++ b/writeLaTeX-ks-TLA.py @@ -1,484 +1,484 @@ -import time -import couchdb -from datetime import date -couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') -db = couch['vl_db'] # existing - -cal_cert = "75204" -year = "2023" -no = "0001" - - -# Druckanzeige pup_cus_ptb = 0 (PTB/Wika) ; pup_cus_ptb = 1 (customer) -#pup_cus_ptb = 0 - -# Druckanzeige durch eine Interpolation intp = 0 (PTB) ; intp = 1 (customer) -#intp = 1 - - -CertificateDate = str(date.today()) - -json_file_cer = "cer-" + year + "-" + cal_cert - -print(json_file_cer) - - -### Kontrolle ob schon ein cer existiert ######### - -id_cer = 0 - -mango = {'selector': {'_id':json_file_cer}} -for i in db.find(mango): - id_cer = 1 - -print(id_cer) - - -doc = {'_id': json_file_cer} - - -if id_cer == 0: - db.save(doc) - print ( "Warten! 30 Sekunden" ) - time.sleep ( 30 ) - print ( json_file_cer," ist in der Couch angelegt" ) - -else: - print ( json_file_cer," ist bereits in der Couch angelegt" ) - - -id_ = "cal-" + year + "-tl2-kk-" + cal_cert + "_" + no -ks = "P:\\TLA\\KS\\ks-" + cal_cert + "-" + year + ".tex" -cer = "cer-" + year + "-" + cal_cert - -json_file_cal = id_ -json_file_cer = cer -doc_cal = db.get(json_file_cal) -doc_cer = db.get(json_file_cer) - - - - ##### Daten aus dem cal Dokument werden eingelesen####### - -std = doc_cal["Calibration"]["ToDo"]["Standard"] -kind = doc_cal["Calibration"]["ToDo"]["Type"] -gas = doc_cal["Calibration"]["ToDo"]["Gas"] -lang = doc_cal["Calibration"]["Customer"]["Lang"] -todo = doc_cal["Calibration"]["ToDo"]["Type"] -analy = doc_cal["Calibration"]["Result"]["Formula"]["Analyses"] - - - -###### Überprüfung welches Todo ######################### - -if "flow_std" in todo: - res = 1 # Reservoir res = 1 (ja) ; res = 0 (nein) - pup_cus_ptb = 1 # Druckanzeige pup_cus_ptb = 0 (PTB/Wika) ; pup_cus_ptb = 1 (customer) - -else: - res = 0 # Reservoir res = 1 (ja) ; res = 0 (nein) - pup_cus_ptb = 0 # Druckanzeige pup_cus_ptb = 0 (PTB/Wika) ; pup_cus_ptb = 1 (customer) - - -print(lang) -calibration_type = "KK" -last_cert_no = doc_cal["Calibration"]["Presettings"] - -###### überprüfen ob eine letztes Cal-Zeichen gibt ######################### - -if "LastCalibrationYear" in last_cert_no: - print("\"last_cert_no\" ist vorhanden.") - last_cert_no = doc_cal["Calibration"]["Presettings"]["LastCalibrationCertificate"] - last_cert_year = doc_cal["Calibration"]["Presettings"]["LastCalibrationYear"] - last_cert = last_cert_no + "\\,PTB\\," + last_cert_year[2:] - sectionDiscription_noyes= "yes" - print(last_cert) - -else: - print("\"last_cert_no\" ist nicht vorhanden.") - sectionDiscription_noyes= "no" - last_cert = "" - - - -Standard = doc_cal["Calibration"]["ToDo"]["Standard"] -Land= doc_cal["Calibration"]["Customer"]["Address"]["Land"] - -##### Titlepage ####### -Certificate = str(doc_cal["Calibration"]["Certificate"]) -ReferenceNo = doc_cal["Calibration"]["Presettings"]["ReferenceNo"] -Name= doc_cal["Calibration"]["Customer"]["Name"] -AddName= doc_cal["Calibration"]["Customer"]["AddName"] -Street= doc_cal["Calibration"]["Customer"]["Address"]["Street"] -Town= doc_cal["Calibration"]["Customer"]["Address"]["Town"] -Zipcode= doc_cal["Calibration"]["Customer"]["Address"]["Zipcode"] -ObjectOfCalibration= doc_cal["Calibration"]["CustomerObject"]["Type"] -Producer= doc_cal["Calibration"]["CustomerObject"]["Device"]["Producer"] -Type= doc_cal["Calibration"]["CustomerObject"]["Device"]["Type"] ########## Type -Object= doc_cal["Calibration"]["CustomerObject"]["Type"] ########## Gegenstand/Object -Serial= doc_cal["Calibration"]["CustomerObject"]["Name"] ########## Kennummer -Examiner= doc_cal["Calibration"]["Measurement"]["Maintainer"] -ByOrder= "Dr. Matthias Bernien" -MeasurementDate= doc_cal["Calibration"]["Result"]["Formula"]["MeasurementDate"] - -print(MeasurementDate) - -obj ='\\object{'+ Object + '}\n' -manufacturer = '\\manufacturer{' + Producer +' }\n' -typ = '\\type{' + Type + '}\n' -serialNo = '\\serialNo{' + Serial + '}\n' -applicant = '\\applicant{{' + Name + '}\n {' + Street + '} \n {' + Zipcode + Town +'}\n {' + Land+'}}\n' -refNo = '\\refNo{ ' + ReferenceNo + '}\n' -calibMark = '\\calibMark{ ' +' ' + Certificate + ' PTB 23}\n' -calibDate = '\\calibDate{' + MeasurementDate + '}\n' -examiner = '\\examiner{' + Examiner + '}\n' -certificateDate = '\\certificateDate{' + CertificateDate + '}\n' - - -################## Ergebnisse ################################################### -NoOfMeasurements= doc_cal["Calibration"]["Result"]["Formula"]["NoOfMeasurements"] -TemperatureTL= doc_cal["Calibration"]["Result"]["Formula"]["TemperatureTL"] - -PressureUpstream= doc_cal["Calibration"]["Result"]["Formula"]["PressureUpstream"] -PressureUpstreamMin= doc_cal["Calibration"]["Result"]["Formula"]["PressureUpstreamMin"] -PressureUpstreamMax= doc_cal["Calibration"]["Result"]["Formula"]["PressureUpstreamMax"] -LeakUncertainty= doc_cal["Calibration"]["Result"]["Formula"]["LeakUncertainty"] -PressureAtmosmin= doc_cal["Calibration"]["Result"]["Formula"]["PressureAtmosmin"] ####### Pascal -a =float(PressureUpstreamMin) -b = f'{a:1f}' -PressureUpstreamMin = b[:-2] -PressureAtmosmax= doc_cal["Calibration"]["Result"]["Formula"]["PressureAtmosmax"] -a =float(PressureUpstreamMax) -b = f'{a:1f}' -PressureUpstreamMax = b[:-2] -FlowMol= doc_cal["Calibration"]["Result"]["Formula"]["FlowMol"] -FlowpV= doc_cal["Calibration"]["Result"]["Formula"]["FlowpV"] -LeakUncertainty= doc_cal["Calibration"]["Result"]["Formula"]["LeakUncertainty"] -TextDE= doc_cal["Calibration"]["CustomerObject"]["Text"]["description"]["de"] -TextEN= doc_cal["Calibration"]["CustomerObject"]["Text"]["description"]["en"] - -############################################################################################################################################################### - - - - - -####### Überschriften ###################### - -######## Deutsch ########################## - -sectionDescriptionTitle = 'Beschreibung zum Kalibriergerät' -sectionTitelProcedure = 'Kalibrierverfahren ' -sectionTitelResult = 'Messergebnis ' -sectionTitelUncertainty = 'Unsicherheit ' - - - - -######## Englisch ########################## - -sectionDescriptionTitle_en = 'Description relating to calibration device' -sectionTitelProcedure_en = 'Calibration procedure ' -sectionTitelResult_en = 'Measurement results' -sectionTitelUncertainty_en = 'Uncertainty of Calibration' - - - -####### Überschriften Ende ###################### - - -####### Formeln #################### - -q_pV_allg = ' \\[ q_{pV} = p_{\\text{atm}} \\cdot \\frac{\\Delta V}{\\Delta t}\\] \n ' -q_mol_allg = ' \\[ q_\\text{mol} = \\frac{q_{pV}}{RT}\\] \n ' -q_mol_Val= 'q_\\text{mol}(\\vartheta_\\text{TL}) =\\SI{ ' + FlowMol + ' }{\\mol\\per\\second}' -q_pV_Val_all = '\\[q_{pV}(\\vartheta_\\text{Ch}) = q_{\\text{mol}}(\\vartheta_\\text{TL})\\cdot R \\cdot (\\vartheta_\\text{Ch} + T_0)\\] ' -q_pV_Val = 'q_{pV}(\\SI{23}{\\degreeCelsius})= \\num{' + FlowpV + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}' ######### Wichtig beim deutsch/englisch Text , der Wert steht beim Englisch in einer Zeile - -######## Tabellen um die Formeln zu zentriert. Bei den deutsch englischen Kalibrierschein stehen beide Ergebnisse direkt untereinander########################### - -tab_q_mol_Val= '\\begin{center}\\begin{tabular}[h]{c} $$$' + q_mol_Val + '$$$ \\\\ $$$\\begin{english} ' + q_mol_Val + ' \\end{english}$$$ \\end{tabular}\\end{center}' -tab_q_mol_Val_en= ' \\[ ' + q_mol_Val + '\\] \n' - -tab_q_pV_Val= '\\begin{center}\\begin{tabular}[h]{c} $$$' + q_pV_Val + '$$$ \\\\ $$$\\begin{english} '+ q_pV_Val + '\\end{english}$$$ \\end{tabular}\\end{center}' -tab_q_pV_Val_en= ' \\[ ' + q_pV_Val + '\\] \n' - - -######## Formeln Ende ###################### - - - - - - - - -###### 1. Section: Beschreibung zum Kalibriergerät ################### - - -sectionDiscription_1= TextDE ###### Beschreibung aus dem cal-Dokument -sectionDiscription_1_en= TextEN ###### Beschreibung aus dem cal-Dokument - - -if (sectionDiscription_noyes!= 'yes'): - - sectionDiscription_2= " Dies ist die erste von der PTB durchgeführte Kalibrierung." - sectionDiscription_2_en= "This is the previous calibration at PTB." - print(" 1. durchgeführte Kalibrierung") - -else: - - sectionDiscription_2= " Die von der PTB zuletzt durchgeführten Kalibrierung ist im Kalibrierschein " + last_cert + " beschrieben." - sectionDiscription_2_en= " The previous calibration at PTB had been carried out " + last_cert_year + ' with the calibration mark ' + last_cert + " ." - - - - -sectionDiscription_1_en= TextEN ###### Beschreibung aus dem cal-Dokument - -sectionDiscription = '\\section{' + sectionDescriptionTitle + '\\linebreak {\\small \\emph{' + sectionDescriptionTitle_en + '}}}\n' + sectionDiscription_1 + sectionDiscription_2 + '\n' + '\\begin{english}' + TextEN + sectionDiscription_2_en + '\\end{english} \n' -sectionDiscription_en = '\\section{' + sectionDescriptionTitle_en +'}\n' + TextEN + sectionDiscription_2_en - - -print(sectionDiscription, " Discription funktioniert") - - -####### 2. Section: Procedure ################################### - - -sectionProcedure1='''Der gemäß DIN 28400, Teil 1, definierte \\(pV\\)-Durchfluss \\(q_{pV}\\) des aus dem Testleck gegen Atmosphäre ausströmenden Gases wird mit dem Primärnormal TL2 des Labors für Vakuummetrologie der PTB bestimmt. -Das Testleck ist dazu an einer kleinen abgeschlossenen Kammer mit veränderbarem Volumen angeflanscht. Die Kammer des Primärnormals und das Testleck sind gemeinsam thermisch von der Umgebung isoliert. -Um den Druck \\(p_{\\text{atm}}\\) (atmosphärischer Luftdruck) in dem Behälter bei einströmendem Gas aus dem Testleck konstant zu halten, wird das Volumen vergrößert. -Der \\(pV\\)-Durchfluss \\(q_{pV}\\) bei der Temperatur \\(T\\) (in K) und der zeitlichen Volumenänderung (\\(\\Delta V/\\Delta t\\)) im Primärnormal ist gegeben durch \n ''' -sectionProcedure2=''' Der Druck \\(p_{\\text{atm}}\\) wird mit einem kalibrierten digitalen Manometer gemessen. -Die zeitliche Volumenänderung (\\(\\Delta V/\\Delta t\\)) wird mit Hilfe einer kalibrierten Nadel und einer elektronischen Uhr bestimmt. -Die molare Durchflussrate \\(q_{\\text{mol}}\\) wird nach folgender Beziehung berechnet\n ''' -sectionProcedure3=' Die molare Gaskonstante \\(R\\) hat den Wert 8,3145~\\(\\text{Pa}\\)~\\(\\text{m}^3\\)~\\(\\text{mol}^{-1}\\)~\\(\\text{K}^{-1}\\).' - - -sectionProcedure1_en ='''The gas flow \\(q_{pV}\\) of the leak defined by ISO 3529-1 flowing against atmosphere is measured in the primary test leak standard TL2 of PTB. -The leak is connected to a small chamber of variable size. The chamber of the primary standard and the test leak are thermally isolated from the environment. -The gas of the leak flowing into the chamber causes an increasing pressure, which is compensated by a change of the volume. -The leak rate \\(q_{pV}\\) is calculated from the temporal volume change (\\(\\Delta V/\\Delta t\\)) and the pressure \\(p_{\\text{atm}}\\) (atmospheric pressure) inside the chamber at the temperature \\(T\\) (in K) via ''' -sectionProcedure2_en=''' The pressure \\(p_{\\text{atm}}\\) is measured by means of a calibrated digital pressure gauge. -The temporal volume change \\(\\Delta V/\\Delta t\\) is obtained of a calibrated needle and an electronic clock. The molar leak rate \\(q_{\\text{mol}}\\) of the test leak can be calculated by the following equation:''' -sectionProcedure3_en=' The molar gas constant \\(R\\) has the value 8.3145~\\(\\text{Pa}\\)~\\(\\text{m}^3\\)~\\(\\text{mol}^{-1}\\)~\\(\\text{K}^{-1}\\).' - - -sectionProcedure = '\\section{' + sectionTitelProcedure + '\\linebreak {\\small \\emph{' + sectionTitelProcedure_en + '}}}\n' + sectionProcedure1 + '\\begin{english}' + sectionProcedure1_en + '\\end{english} \n' + q_pV_allg + sectionProcedure2 + '\\begin{english}' + sectionProcedure2_en + '\\end{english} \n' + q_mol_allg + sectionProcedure3 + '\\begin{english}' + sectionProcedure3_en +'\\end{english} \n' -sectionProcedure_en = '\\section{' + sectionTitelProcedure_en + '}\n' + sectionProcedure1_en + q_pV_allg + sectionProcedure2_en + q_mol_allg + sectionProcedure3_en - - -####### 3. Section: Result ################################### - -sectionResult1 = 'Mit dem Testleck wurden insgesamt ' + NoOfMeasurements + ' Leckratenbestimmungen an verschiedenen Tagen bei der Testlecktemperatur \\( \\vartheta_\\text{TL}= \\num{ ' + TemperatureTL + '}\\pm \\SI{0.1}{\\degreeCelsius} \\) durchgeführt.\n Die Atmosphärendrücke lagen zwischen \\(p_{\\text{atm}_1}=(\\num{ ' + PressureAtmosmin + '}\\pm \\SI{0.1})~ \\si{Pa} \\) und \\(p_{\\text{atm}_2}=(\\num{ ' +PressureAtmosmax + '} \\pm \\num{0.1})~ \\si{Pa} \\).\n' -sectionResult2 = 'Daraus kann für den Ort mit einer Temperatur \\(\\vartheta_\\text{Ch}\\) in \\si{\\degreeCelsius}, an dem sich das Testleck befindet, mit \\(T_0 = \\SI{273.15}{\\kelvin}\\), der \\(pV\\)-Durchfluss nach folgender Beziehung berechnet werden.' -sectionResult3 = '\\linebreak Bei einer Temperatur \\( \\vartheta_\\text{Ch}= \\SI{ 23 }{\\degreeCelsius} \\) ergibt sich ein \\(pV\\)-Durchfluss \\(q_{pV}\\) von ' -sectionResult4 = 'Die relative Unsicherheit \\(U\\) der angegebenen Leckraten beträgt \\( \\SI{'+ LeakUncertainty +'}{\\percent} \\).' - - -sectionResult_std = 'Die mittlere molare Leckrate ergab einen Wert von:\n' -sectionResult_std_en = 'The mean leak rate (molar flow) was determined to:\n' - -sectionResult_pup_mean = 'Die mittlere molare Leckrate, bei einem relativ zur Atmosphäre eingestellten Druck von \\( p_\\text{up}= \\SI{ ' + PressureUpstream + '}{\\kPa} \\) ergab einen Wert von:\n' -sectionResult_pup_mean_en = 'The mean leak rate (molar flow) for relativ pressure \\( p_\\text{up}= \\SI{ ' + PressureUpstream + '}{\\kPa} \\) at the upstream pressure side was determined to:\n' - -sectionResult_pup_int1 = 'Die molare Leckrate, bei einem relativ zur Atmosphäre eingestellten Druck von \\( p_\\text{up}= \\SI{ ' + PressureUpstream + '}{\\kPa} \\) ergab einen Wert von:' -sectionResult_pup_int2 = 'Der Wert ergab sich aus der Interpolation der gemessenen Werte in einem Bereich von \\(p_{\\text{up}_1}=(\\num{ ' + PressureUpstreamMin + '}\\pm \\SI{0.1})~ \\si{kPa} \\) and \\(p_{\\text{up}_2}=(\\num{ ' + PressureUpstreamMax + '}\\pm \\SI{0.1})~ \\si{kPa} \\). Die Unsicherheit des relativ eingestellten Drucks ist \\( \\SI{0.5}{\\percent} \\).' - -sectionResult1_en = NoOfMeasurements + ' measurements were carried out on several days at a leak temperature \\( \\vartheta_\\text{TL}= \\num{ ' + TemperatureTL + '}\\pm \\SI{0.1}{\\degreeCelsius} \\) (thermostated) and an atmospheric pressure between \\(p_{\\text{atm}_1}=(\\num{ ' + PressureAtmosmin + ' }\\pm \\SI{0.1})~ \\si{ Pa} \\) and \\(p_{\\text{atm}_2}=(\\num{ ' + PressureAtmosmax + ' } \\pm \\num{0.1})~ \\si{ Pa} \\).' -sectionResult2_en = ' From this the \\(pV\\)-flow can be calculated for a place at a temperature \\(\\vartheta_\\text{Ch}\\) (in \\si{\\degreeCelsius}), where a device under test is mounted and \\(T_0 = \\SI{273.15}{\\kelvin}\\), by the equation ' -sectionResult3_en = 'At the temperature \\( \\vartheta_\\text{Ch}= \\SI{ 23 }{\\degreeCelsius} \\) the flow rate is' -sectionResult4_en = 'The relative uncertainty \\(U\\) of the stated leak rate are \\( \\SI{'+ LeakUncertainty +'}{\\percent} \\).' - -if res == 1: - print ( "Standartmessung - mit Reservoir" ) - sectionResult = '\\section{' + sectionTitelResult + '\\linebreak {\\small \\emph{' + sectionTitelResult_en + '}}}\n' + sectionResult1 + sectionResult_std + '\\begin{english}' + sectionResult1_en + sectionResult_std_en + '\\end{english} ' + tab_q_mol_Val - sectionResult_en = '\\section{' + sectionTitelResult_en + '}\n' + sectionResult1_en + sectionResult_std_en + tab_q_mol_Val_en - - - - -else: - if(analy!='mean'): - print ( "Standartmessung - ohne Reservoir" ) - - sectionResult = '\\section{' + sectionTitelResult + '\\linebreak {\\small \\emph{' + sectionTitelResult_en + '}}}\n' - + sectionResult1 + sectionResult_pup_mean + q_mol_Val - + '\\begin{english}' + sectionResult1_en + ' The mean leak rate (molar flow) was determined to:' + q_mol_Val + '\\end{english} \n' - - -sectionResult = sectionResult + sectionResult2 + '\\begin{english}' + sectionResult2_en + '\\end{english} \n' + q_pV_Val_all + sectionResult3 + '\\begin{english}' + sectionResult3_en + '\\end{english} \n' + tab_q_pV_Val + sectionResult4 + '\\begin{english}' + sectionResult4_en + '\\end{english} \n' -sectionResult_en = sectionResult_en + sectionResult2_en + q_pV_Val_all + sectionResult3_en + tab_q_pV_Val_en + sectionResult4_en - - - - - -####### 4. Section: Uncertainty ################################### - -sectionU1 = 'Angegeben ist die erweiterte Messunsicherheit \\(U\\), die sich aus der Standardmessunsicherheit durch Multiplikation mit dem Erweiterungsfaktor \\(k = 2\\) ergibt. Sie wurde gemäß dem „Guide to the Expression of Uncertainty in Measurement (GUM)“ ermittelt. Der Wert der Messgröße liegt dann im Regelfall mit einer Wahrscheinlichkeit von annähernd \\SI{95}{\\percent} im zugeordneten Überdeckungsintervall.\n ' -sectionU1_en = 'The uncertainty \\(U\\) stated is the expanded measurement uncertainty obtained by multiplying the standard measurement uncertainty by the coverage factor \\(k = 2\\). It has been determined in accordance with the “Guide to the Expression of Uncertainty in Measurement (GUM)”. The value of the measurand then normally lies, with a probability of approximately \\SI{95}{\\percent} within the attributed coverage interval.' - -sectionU = '\\section{' + sectionTitelUncertainty + '\\linebreak {\\small \\emph{' + sectionTitelUncertainty_en + '}}}\n' + sectionU1 + '\\begin{english}' + sectionU1_en + '\\end{english} \n' -sectionU_en = '\\section{' + sectionTitelUncertainty_en + '}\n' + sectionU1_en - - - -if(lang!='en'): - print("Kalibrierschein in deutsch",lang) - - with open(ks,'w', encoding='utf-8') as file: - - file.write('\\listfiles\n') - file.write('\\documentclass[de,KK,noCMC]{kalibrierschein}\n ') - file.write(obj) - file.write(manufacturer) - file.write(typ) - file.write(serialNo) - file.write(applicant) - file.write(refNo) - file.write(calibMark) - file.write(calibDate) - file.write('\\byOrder{Dr. M.Bernien}\n') - file.write(examiner) - file.write(certificateDate) - - file.write('\\begin{document}\n') - - file.write('\\printFirstPage\n') - file.write(sectionDiscription) - - - - file.write(sectionProcedure) - file.write('\\pagebreak ') - file.write(sectionResult) - file.write(sectionU) - - - - file.write('\\pagebreak ') - - file.write('\\printLastPage') - file.write('\\end{document}\n') - print("bis hier funktioniert") -else: - print('"Kalibrierschein in ',lang, "en") - - - with open(ks,'w', encoding='utf-8') as file: - - file.write('\\listfiles\n') - file.write('\\documentclass[en,KK,noCMC]{kalibrierschein}\n ') - file.write(obj) - file.write(manufacturer) - file.write(typ) - file.write(serialNo) - file.write(applicant) - file.write(refNo) - file.write(calibMark) - file.write(calibDate) - file.write('\\byOrder{Dr. M.Bernien}\n') - file.write(examiner) - file.write(certificateDate) - - file.write('\\begin{document}\n') - - file.write('\\printFirstPage\n') - file.write(sectionDiscription_en) - - - - file.write(sectionProcedure_en) - file.write(sectionResult_en) - file.write(sectionU_en) - - - - file.write('\\pagebreak ') - - file.write('\\printLastPage') - file.write('\\end{document}\n') - print("bis hier funktioniert") - - - ####################Erstellung des cer-Dokuments ########################## - - - - ##### Doukument "cer" wird erstellt####### - - -MeasurementDateBegin = doc_cal["Calibration"]["Measurement"]["Date"][0]["Value"] -MeasurementDateBegin = MeasurementDateBegin[0] -MeasurementDateEnd = doc_cal["Calibration"]["Measurement"]["Date"][0]["Value"] -MeasurementDateEnd = MeasurementDateEnd[0] -DeviceClass= "TLA" - - -doc_cer["Certificate"]={"Meta":{"std": ["TL2"], - "id":[id_], - "kind" :[kind], - "gas": [gas], - "lang":lang, - "calibration_type":calibration_type, - "last_cert":last_cert}} - -doc_cer["Certificate"]["Titlepage"]={"CertificateDate" :CertificateDate, - "FullYear": "2024", - "ShortYear": "24", - "MeasurementDate": MeasurementDate, - "MeasurementDateBegin": MeasurementDateBegin, - "MeasurementDateEnd": MeasurementDateEnd, - "Certificate": Certificate, - "ReferenceNo": ReferenceNo, - "Customer": { - "Name": Name, - "AddName": AddName, - "Street": Street, - "Town": Town, - "Zipcode": Zipcode, - "Land": Land, - "CountryCode": Land }, - "ObjectOfCalibration": ObjectOfCalibration, - "Producer": Producer, - "Type": Type, - "Object": Object, - "Serial": Serial , - "Examiner": Examiner, - "DeviceClass": DeviceClass, - "ByOrder": ByOrder, - } - - -doc_cer["Certificate"]["Section"]= [{"Heading": "Description relating to calibration device","Paragraph":sectionDiscription}, - {"Heading": "Calibration procedure","Paragraph":sectionProcedure}, - {"Heading": "Measurement results","Paragraph":sectionResult}, - {"Heading": "Uncertainty of Calibration","Paragraph":sectionU}], - -doc_cer["Certificate"]["Formula"]={"NoOfMeasurements": NoOfMeasurements, - "FlowMol": FlowMol, - "FlowpV":FlowpV, - "TemperatureTL": TemperatureTL, - "LeakUncertainty": LeakUncertainty, - "MeasurementDate": MeasurementDate, - "PressureUpstream": PressureUpstream, - "PressureAtmosmin": PressureAtmosmin, - "PressureAtmosmax": PressureAtmosmax, - } - - - - # - # - # - -db.save(doc_cer) - - - - - - +import time +import couchdb +from datetime import date +couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') +db = couch['vl_db'] # existing + +cal_cert = "75553" +year = "2024" +no = "0001" + + +# Druckanzeige pup_cus_ptb = 0 (PTB/Wika) ; pup_cus_ptb = 1 (customer) +#pup_cus_ptb = 0 + +# Druckanzeige durch eine Interpolation intp = 0 (PTB) ; intp = 1 (customer) +#intp = 1 + + +CertificateDate = str(date.today()) + +json_file_cer = "cer-" + year + "-" + cal_cert + +print(json_file_cer) + + +### Kontrolle ob schon ein cer existiert ######### + +id_cer = 0 + +mango = {'selector': {'_id':json_file_cer}} +for i in db.find(mango): + id_cer = 1 + +print(id_cer) + + +doc = {'_id': json_file_cer} + + +if id_cer == 0: + db.save(doc) + print ( "Warten! 30 Sekunden" ) + time.sleep ( 30 ) + print ( json_file_cer," ist in der Couch angelegt" ) + +else: + print ( json_file_cer," ist bereits in der Couch angelegt" ) + + +id_ = "cal-" + year + "-tl2-kk-" + cal_cert + "_" + no +ks = "C:\\Users\\becker07\\kalibrierschein\\ks-" + cal_cert + "-" + year + ".tex" +cer = "cer-" + year + "-" + cal_cert + +json_file_cal = id_ +json_file_cer = cer +doc_cal = db.get(json_file_cal) +doc_cer = db.get(json_file_cer) + + + + ##### Daten aus dem cal Dokument werden eingelesen####### + +std = doc_cal["Calibration"]["ToDo"]["Standard"] +kind = doc_cal["Calibration"]["ToDo"]["Type"] +gas = doc_cal["Calibration"]["ToDo"]["Gas"] +lang = doc_cal["Calibration"]["Customer"]["Lang"] +todo = doc_cal["Calibration"]["ToDo"]["Type"] +analy = doc_cal["Calibration"]["Result"]["Formula"]["Analyses"] + + + +###### Überprüfung welches Todo ######################### + +if "flow_std" in todo: + res = 1 # Reservoir res = 1 (ja) ; res = 0 (nein) + pup_cus_ptb = 1 # Druckanzeige pup_cus_ptb = 0 (PTB/Wika) ; pup_cus_ptb = 1 (customer) + +else: + res = 0 # Reservoir res = 1 (ja) ; res = 0 (nein) + pup_cus_ptb = 0 # Druckanzeige pup_cus_ptb = 0 (PTB/Wika) ; pup_cus_ptb = 1 (customer) + + +print(lang) +calibration_type = "KK" +last_cert_no = doc_cal["Calibration"]["Presettings"] + +###### überprüfen ob eine letztes Cal-Zeichen gibt ######################### + +if "LastCalibrationYear" in last_cert_no: + print("\"last_cert_no\" ist vorhanden.") + last_cert_no = doc_cal["Calibration"]["Presettings"]["LastCalibrationCertificate"] + last_cert_year = doc_cal["Calibration"]["Presettings"]["LastCalibrationYear"] + last_cert = last_cert_no + "\\,PTB\\," + last_cert_year[2:] + sectionDiscription_noyes= "yes" + print(last_cert) + +else: + print("\"last_cert_no\" ist nicht vorhanden.") + sectionDiscription_noyes= "no" + last_cert = "" + + + +Standard = doc_cal["Calibration"]["ToDo"]["Standard"] +Land= doc_cal["Calibration"]["Customer"]["Address"]["Land"] + +##### Titlepage ####### +Certificate = str(doc_cal["Calibration"]["Certificate"]) +ReferenceNo = doc_cal["Calibration"]["Presettings"]["ReferenceNo"] +Name= doc_cal["Calibration"]["Customer"]["Name"] +AddName= doc_cal["Calibration"]["Customer"]["AddName"] +Street= doc_cal["Calibration"]["Customer"]["Address"]["Street"] +Town= doc_cal["Calibration"]["Customer"]["Address"]["Town"] +Zipcode= doc_cal["Calibration"]["Customer"]["Address"]["Zipcode"] +ObjectOfCalibration= doc_cal["Calibration"]["CustomerObject"]["Type"] +Producer= doc_cal["Calibration"]["CustomerObject"]["Device"]["Producer"] +Type= doc_cal["Calibration"]["CustomerObject"]["Device"]["Type"] ########## Type +Object= doc_cal["Calibration"]["CustomerObject"]["Type"] ########## Gegenstand/Object +Serial= doc_cal["Calibration"]["CustomerObject"]["Name"] ########## Kennummer +Examiner= doc_cal["Calibration"]["Measurement"]["Maintainer"] +ByOrder= "Dr. Matthias Bernien" +MeasurementDate= doc_cal["Calibration"]["Result"]["Formula"]["MeasurementDate"] + +print(MeasurementDate) + +obj ='\\object{'+ Object + '}\n' +manufacturer = '\\manufacturer{' + Producer +' }\n' +typ = '\\type{' + Type + '}\n' +serialNo = '\\serialNo{' + Serial + '}\n' +applicant = '\\applicant{{' + Name + '}\n {' + Street + '} \n {' + Zipcode + Town +'}\n {' + Land+'}}\n' +refNo = '\\refNo{ ' + ReferenceNo + '}\n' +calibMark = '\\calibMark{ ' +' ' + Certificate + ' PTB 23}\n' +calibDate = '\\calibDate{' + MeasurementDate + '}\n' +examiner = '\\examiner{' + Examiner + '}\n' +certificateDate = '\\certificateDate{' + CertificateDate + '}\n' + + +################## Ergebnisse ################################################### +NoOfMeasurements= doc_cal["Calibration"]["Result"]["Formula"]["NoOfMeasurements"] +TemperatureTL= doc_cal["Calibration"]["Result"]["Formula"]["TemperatureTL"] + +PressureUpstream= doc_cal["Calibration"]["Result"]["Formula"]["PressureUpstream"] +PressureUpstreamMin= doc_cal["Calibration"]["Result"]["Formula"]["PressureUpstreamMin"] +PressureUpstreamMax= doc_cal["Calibration"]["Result"]["Formula"]["PressureUpstreamMax"] +LeakUncertainty= doc_cal["Calibration"]["Result"]["Formula"]["LeakUncertainty"] +PressureAtmosmin= doc_cal["Calibration"]["Result"]["Formula"]["PressureAtmosmin"] ####### Pascal +a =float(PressureUpstreamMin) +b = f'{a:1f}' +PressureUpstreamMin = b[:-2] +PressureAtmosmax= doc_cal["Calibration"]["Result"]["Formula"]["PressureAtmosmax"] +a =float(PressureUpstreamMax) +b = f'{a:1f}' +PressureUpstreamMax = b[:-2] +FlowMol= doc_cal["Calibration"]["Result"]["Formula"]["FlowMol"] +FlowpV= doc_cal["Calibration"]["Result"]["Formula"]["FlowpV"] +LeakUncertainty= doc_cal["Calibration"]["Result"]["Formula"]["LeakUncertainty"] +TextDE= doc_cal["Calibration"]["CustomerObject"]["Text"]["description"]["de"] +TextEN= doc_cal["Calibration"]["CustomerObject"]["Text"]["description"]["en"] + +############################################################################################################################################################### + + + + + +####### Überschriften ###################### + +######## Deutsch ########################## + +sectionDescriptionTitle = 'Beschreibung zum Kalibriergerät' +sectionTitelProcedure = 'Kalibrierverfahren ' +sectionTitelResult = 'Messergebnis ' +sectionTitelUncertainty = 'Unsicherheit ' + + + + +######## Englisch ########################## + +sectionDescriptionTitle_en = 'Description relating to calibration device' +sectionTitelProcedure_en = 'Calibration procedure ' +sectionTitelResult_en = 'Measurement results' +sectionTitelUncertainty_en = 'Uncertainty of Calibration' + + + +####### Überschriften Ende ###################### + + +####### Formeln #################### + +q_pV_allg = ' \\[ q_{pV} = p_{\\text{atm}} \\cdot \\frac{\\Delta V}{\\Delta t}\\] \n ' +q_mol_allg = ' \\[ q_\\text{mol} = \\frac{q_{pV}}{RT}\\] \n ' +q_mol_Val= 'q_\\text{mol}(\\vartheta_\\text{TL}) =\\SI{ ' + FlowMol + ' }{\\mol\\per\\second}' +q_pV_Val_all = '\\[q_{pV}(\\vartheta_\\text{Ch}) = q_{\\text{mol}}(\\vartheta_\\text{TL})\\cdot R \\cdot (\\vartheta_\\text{Ch} + T_0)\\] ' +q_pV_Val = 'q_{pV}(\\SI{23}{\\degreeCelsius})= \\num{' + FlowpV + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}' ######### Wichtig beim deutsch/englisch Text , der Wert steht beim Englisch in einer Zeile + +######## Tabellen um die Formeln zu zentriert. Bei den deutsch englischen Kalibrierschein stehen beide Ergebnisse direkt untereinander########################### + +tab_q_mol_Val= '\\begin{center}\\begin{tabular}[h]{c} $$$' + q_mol_Val + '$$$ \\\\ $$$\\begin{english} ' + q_mol_Val + ' \\end{english}$$$ \\end{tabular}\\end{center}' +tab_q_mol_Val_en= ' \\[ ' + q_mol_Val + '\\] \n' + +tab_q_pV_Val= '\\begin{center}\\begin{tabular}[h]{c} $$$' + q_pV_Val + '$$$ \\\\ $$$\\begin{english} '+ q_pV_Val + '\\end{english}$$$ \\end{tabular}\\end{center}' +tab_q_pV_Val_en= ' \\[ ' + q_pV_Val + '\\] \n' + + +######## Formeln Ende ###################### + + + + + + + + +###### 1. Section: Beschreibung zum Kalibriergerät ################### + + +sectionDiscription_1= TextDE ###### Beschreibung aus dem cal-Dokument +sectionDiscription_1_en= TextEN ###### Beschreibung aus dem cal-Dokument + + +if (sectionDiscription_noyes!= 'yes'): + + sectionDiscription_2= " Dies ist die erste von der PTB durchgeführte Kalibrierung." + sectionDiscription_2_en= "This is the previous calibration at PTB." + print(" 1. durchgeführte Kalibrierung") + +else: + + sectionDiscription_2= " Die von der PTB zuletzt durchgeführten Kalibrierung ist im Kalibrierschein " + last_cert + " beschrieben." + sectionDiscription_2_en= " The previous calibration at PTB had been carried out " + last_cert_year + ' with the calibration mark ' + last_cert + " ." + + + + +sectionDiscription_1_en= TextEN ###### Beschreibung aus dem cal-Dokument + +sectionDiscription = '\\section{' + sectionDescriptionTitle + '\\linebreak {\\small \\emph{' + sectionDescriptionTitle_en + '}}}\n' + sectionDiscription_1 + sectionDiscription_2 + '\n' + '\\begin{english}' + TextEN + sectionDiscription_2_en + '\\end{english} \n' +sectionDiscription_en = '\\section{' + sectionDescriptionTitle_en +'}\n' + TextEN + sectionDiscription_2_en + + +print(sectionDiscription, " Discription funktioniert") + + +####### 2. Section: Procedure ################################### + + +sectionProcedure1='''Der gemäß DIN 28400, Teil 1, definierte \\(pV\\)-Durchfluss \\(q_{pV}\\) des aus dem Testleck gegen Atmosphäre ausströmenden Gases wird mit dem Primärnormal TL2 des Labors für Vakuummetrologie der PTB bestimmt. +Das Testleck ist dazu an einer kleinen abgeschlossenen Kammer mit veränderbarem Volumen angeflanscht. Die Kammer des Primärnormals und das Testleck sind gemeinsam thermisch von der Umgebung isoliert. +Um den Druck \\(p_{\\text{atm}}\\) (atmosphärischer Luftdruck) in dem Behälter bei einströmendem Gas aus dem Testleck konstant zu halten, wird das Volumen vergrößert. +Der \\(pV\\)-Durchfluss \\(q_{pV}\\) bei der Temperatur \\(T\\) (in K) und der zeitlichen Volumenänderung (\\(\\Delta V/\\Delta t\\)) im Primärnormal ist gegeben durch \n ''' +sectionProcedure2=''' Der Druck \\(p_{\\text{atm}}\\) wird mit einem kalibrierten digitalen Manometer gemessen. +Die zeitliche Volumenänderung (\\(\\Delta V/\\Delta t\\)) wird mit Hilfe einer kalibrierten Nadel und einer elektronischen Uhr bestimmt. +Die molare Durchflussrate \\(q_{\\text{mol}}\\) wird nach folgender Beziehung berechnet\n ''' +sectionProcedure3=' Die molare Gaskonstante \\(R\\) hat den Wert 8,3145~\\(\\text{Pa}\\)~\\(\\text{m}^3\\)~\\(\\text{mol}^{-1}\\)~\\(\\text{K}^{-1}\\).' + + +sectionProcedure1_en ='''The gas flow \\(q_{pV}\\) of the leak defined by ISO 3529-1 flowing against atmosphere is measured in the primary test leak standard TL2 of PTB. +The leak is connected to a small chamber of variable size. The chamber of the primary standard and the test leak are thermally isolated from the environment. +The gas of the leak flowing into the chamber causes an increasing pressure, which is compensated by a change of the volume. +The leak rate \\(q_{pV}\\) is calculated from the temporal volume change (\\(\\Delta V/\\Delta t\\)) and the pressure \\(p_{\\text{atm}}\\) (atmospheric pressure) inside the chamber at the temperature \\(T\\) (in K) via ''' +sectionProcedure2_en=''' The pressure \\(p_{\\text{atm}}\\) is measured by means of a calibrated digital pressure gauge. +The temporal volume change \\(\\Delta V/\\Delta t\\) is obtained of a calibrated needle and an electronic clock. The molar leak rate \\(q_{\\text{mol}}\\) of the test leak can be calculated by the following equation:''' +sectionProcedure3_en=' The molar gas constant \\(R\\) has the value 8.3145~\\(\\text{Pa}\\)~\\(\\text{m}^3\\)~\\(\\text{mol}^{-1}\\)~\\(\\text{K}^{-1}\\).' + + +sectionProcedure = '\\section{' + sectionTitelProcedure + '\\linebreak {\\small \\emph{' + sectionTitelProcedure_en + '}}}\n' + sectionProcedure1 + '\\begin{english}' + sectionProcedure1_en + '\\end{english} \n' + q_pV_allg + sectionProcedure2 + '\\begin{english}' + sectionProcedure2_en + '\\end{english} \n' + q_mol_allg + sectionProcedure3 + '\\begin{english}' + sectionProcedure3_en +'\\end{english} \n' +sectionProcedure_en = '\\section{' + sectionTitelProcedure_en + '}\n' + sectionProcedure1_en + q_pV_allg + sectionProcedure2_en + q_mol_allg + sectionProcedure3_en + + +####### 3. Section: Result ################################### + +sectionResult1 = 'Mit dem Testleck wurden insgesamt ' + NoOfMeasurements + ' Leckratenbestimmungen an verschiedenen Tagen bei der Testlecktemperatur \\( \\vartheta_\\text{TL}= \\num{ ' + TemperatureTL + '}\\pm \\SI{0.1}{\\degreeCelsius} \\) durchgeführt.\n Die Atmosphärendrücke lagen zwischen \\(p_{\\text{atm}_1}=(\\num{ ' + PressureAtmosmin + '}\\pm \\SI{0.1})~ \\si{Pa} \\) und \\(p_{\\text{atm}_2}=(\\num{ ' +PressureAtmosmax + '} \\pm \\num{0.1})~ \\si{Pa} \\).\n' +sectionResult2 = 'Daraus kann für den Ort mit einer Temperatur \\(\\vartheta_\\text{Ch}\\) in \\si{\\degreeCelsius}, an dem sich das Testleck befindet, mit \\(T_0 = \\SI{273.15}{\\kelvin}\\), der \\(pV\\)-Durchfluss nach folgender Beziehung berechnet werden.' +sectionResult3 = '\\linebreak Bei einer Temperatur \\( \\vartheta_\\text{Ch}= \\SI{ 23 }{\\degreeCelsius} \\) ergibt sich ein \\(pV\\)-Durchfluss \\(q_{pV}\\) von ' +sectionResult4 = 'Die relative Unsicherheit \\(U\\) der angegebenen Leckraten beträgt \\( \\SI{'+ LeakUncertainty +'}{\\percent} \\).' + + +sectionResult_std = 'Die mittlere molare Leckrate ergab einen Wert von:\n' +sectionResult_std_en = 'The mean leak rate (molar flow) was determined to:\n' + +sectionResult_pup_mean = 'Die mittlere molare Leckrate, bei einem relativ zur Atmosphäre eingestellten Druck von \\( p_\\text{up}= \\SI{ ' + PressureUpstream + '}{\\kPa} \\) ergab einen Wert von:\n' +sectionResult_pup_mean_en = 'The mean leak rate (molar flow) for relativ pressure \\( p_\\text{up}= \\SI{ ' + PressureUpstream + '}{\\kPa} \\) at the upstream pressure side was determined to:\n' + +sectionResult_pup_int1 = 'Die molare Leckrate, bei einem relativ zur Atmosphäre eingestellten Druck von \\( p_\\text{up}= \\SI{ ' + PressureUpstream + '}{\\kPa} \\) ergab einen Wert von:' +sectionResult_pup_int2 = 'Der Wert ergab sich aus der Interpolation der gemessenen Werte in einem Bereich von \\(p_{\\text{up}_1}=(\\num{ ' + PressureUpstreamMin + '}\\pm \\SI{0.1})~ \\si{kPa} \\) and \\(p_{\\text{up}_2}=(\\num{ ' + PressureUpstreamMax + '}\\pm \\SI{0.1})~ \\si{kPa} \\). Die Unsicherheit des relativ eingestellten Drucks ist \\( \\SI{0.5}{\\percent} \\).' + +sectionResult1_en = NoOfMeasurements + ' measurements were carried out on several days at a leak temperature \\( \\vartheta_\\text{TL}= \\num{ ' + TemperatureTL + '}\\pm \\SI{0.1}{\\degreeCelsius} \\) (thermostated) and an atmospheric pressure between \\(p_{\\text{atm}_1}=(\\num{ ' + PressureAtmosmin + ' }\\pm \\SI{0.1})~ \\si{ Pa} \\) and \\(p_{\\text{atm}_2}=(\\num{ ' + PressureAtmosmax + ' } \\pm \\num{0.1})~ \\si{ Pa} \\).' +sectionResult2_en = ' From this the \\(pV\\)-flow can be calculated for a place at a temperature \\(\\vartheta_\\text{Ch}\\) (in \\si{\\degreeCelsius}), where a device under test is mounted and \\(T_0 = \\SI{273.15}{\\kelvin}\\), by the equation ' +sectionResult3_en = 'At the temperature \\( \\vartheta_\\text{Ch}= \\SI{ 23 }{\\degreeCelsius} \\) the flow rate is' +sectionResult4_en = 'The relative uncertainty \\(U\\) of the stated leak rate are \\( \\SI{'+ LeakUncertainty +'}{\\percent} \\).' + +if res == 1: + print ( "Standartmessung - mit Reservoir" ) + sectionResult = '\\section{' + sectionTitelResult + '\\linebreak {\\small \\emph{' + sectionTitelResult_en + '}}}\n' + sectionResult1 + sectionResult_std + '\\begin{english}' + sectionResult1_en + sectionResult_std_en + '\\end{english} ' + tab_q_mol_Val + sectionResult_en = '\\section{' + sectionTitelResult_en + '}\n' + sectionResult1_en + sectionResult_std_en + tab_q_mol_Val_en + + + + +else: + if(analy!='mean'): + print ( "Standartmessung - ohne Reservoir" ) + + sectionResult = '\\section{' + sectionTitelResult + '\\linebreak {\\small \\emph{' + sectionTitelResult_en + '}}}\n' + + sectionResult1 + sectionResult_pup_mean + q_mol_Val + + '\\begin{english}' + sectionResult1_en + ' The mean leak rate (molar flow) was determined to:' + q_mol_Val + '\\end{english} \n' + + +sectionResult = sectionResult + sectionResult2 + '\\begin{english}' + sectionResult2_en + '\\end{english} \n' + q_pV_Val_all + sectionResult3 + '\\begin{english}' + sectionResult3_en + '\\end{english} \n' + tab_q_pV_Val + sectionResult4 + '\\begin{english}' + sectionResult4_en + '\\end{english} \n' +sectionResult_en = sectionResult_en + sectionResult2_en + q_pV_Val_all + sectionResult3_en + tab_q_pV_Val_en + sectionResult4_en + + + + + +####### 4. Section: Uncertainty ################################### + +sectionU1 = 'Angegeben ist die erweiterte Messunsicherheit \\(U\\), die sich aus der Standardmessunsicherheit durch Multiplikation mit dem Erweiterungsfaktor \\(k = 2\\) ergibt. Sie wurde gemäß dem „Guide to the Expression of Uncertainty in Measurement (GUM)“ ermittelt. Der Wert der Messgröße liegt dann im Regelfall mit einer Wahrscheinlichkeit von annähernd \\SI{95}{\\percent} im zugeordneten Überdeckungsintervall.\n ' +sectionU1_en = 'The uncertainty \\(U\\) stated is the expanded measurement uncertainty obtained by multiplying the standard measurement uncertainty by the coverage factor \\(k = 2\\). It has been determined in accordance with the “Guide to the Expression of Uncertainty in Measurement (GUM)”. The value of the measurand then normally lies, with a probability of approximately \\SI{95}{\\percent} within the attributed coverage interval.' + +sectionU = '\\section{' + sectionTitelUncertainty + '\\linebreak {\\small \\emph{' + sectionTitelUncertainty_en + '}}}\n' + sectionU1 + '\\begin{english}' + sectionU1_en + '\\end{english} \n' +sectionU_en = '\\section{' + sectionTitelUncertainty_en + '}\n' + sectionU1_en + + + +if(lang!='en'): + print("Kalibrierschein in deutsch",lang) + + with open(ks,'w', encoding='utf-8') as file: + + file.write('\\listfiles\n') + file.write('\\documentclass[de,KK,noCMC]{kalibrierschein}\n ') + file.write(obj) + file.write(manufacturer) + file.write(typ) + file.write(serialNo) + file.write(applicant) + file.write(refNo) + file.write(calibMark) + file.write(calibDate) + file.write('\\byOrder{Dr. M.Bernien}\n') + file.write(examiner) + file.write(certificateDate) + + file.write('\\begin{document}\n') + + file.write('\\printFirstPage\n') + file.write(sectionDiscription) + + + + file.write(sectionProcedure) + file.write('\\pagebreak ') + file.write(sectionResult) + file.write(sectionU) + + + + file.write('\\pagebreak ') + + file.write('\\printLastPage') + file.write('\\end{document}\n') + print("bis hier funktioniert") +else: + print('"Kalibrierschein in ',lang, "en") + + + with open(ks,'w', encoding='utf-8') as file: + + file.write('\\listfiles\n') + file.write('\\documentclass[en,KK,noCMC]{kalibrierschein}\n ') + file.write(obj) + file.write(manufacturer) + file.write(typ) + file.write(serialNo) + file.write(applicant) + file.write(refNo) + file.write(calibMark) + file.write(calibDate) + file.write('\\byOrder{Dr. M.Bernien}\n') + file.write(examiner) + file.write(certificateDate) + + file.write('\\begin{document}\n') + + file.write('\\printFirstPage\n') + file.write(sectionDiscription_en) + + + + file.write(sectionProcedure_en) + file.write(sectionResult_en) + file.write(sectionU_en) + + + + file.write('\\pagebreak ') + + file.write('\\printLastPage') + file.write('\\end{document}\n') + print("bis hier funktioniert") + + + ####################Erstellung des cer-Dokuments ########################## + + + + ##### Doukument "cer" wird erstellt####### + + +MeasurementDateBegin = doc_cal["Calibration"]["Measurement"]["Date"][0]["Value"] +MeasurementDateBegin = MeasurementDateBegin[0] +MeasurementDateEnd = doc_cal["Calibration"]["Measurement"]["Date"][0]["Value"] +MeasurementDateEnd = MeasurementDateEnd[0] +DeviceClass= "TLA" + + +doc_cer["Certificate"]={"Meta":{"std": ["TL2"], + "id":[id_], + "kind" :[kind], + "gas": [gas], + "lang":lang, + "calibration_type":calibration_type, + "last_cert":last_cert}} + +doc_cer["Certificate"]["Titlepage"]={"CertificateDate" :CertificateDate, + "FullYear": "2024", + "ShortYear": "24", + "MeasurementDate": MeasurementDate, + "MeasurementDateBegin": MeasurementDateBegin, + "MeasurementDateEnd": MeasurementDateEnd, + "Certificate": Certificate, + "ReferenceNo": ReferenceNo, + "Customer": { + "Name": Name, + "AddName": AddName, + "Street": Street, + "Town": Town, + "Zipcode": Zipcode, + "Land": Land, + "CountryCode": Land }, + "ObjectOfCalibration": ObjectOfCalibration, + "Producer": Producer, + "Type": Type, + "Object": Object, + "Serial": Serial , + "Examiner": Examiner, + "DeviceClass": DeviceClass, + "ByOrder": ByOrder, + } + + +doc_cer["Certificate"]["Section"]= [{"Heading": "Description relating to calibration device","Paragraph":sectionDiscription}, + {"Heading": "Calibration procedure","Paragraph":sectionProcedure}, + {"Heading": "Measurement results","Paragraph":sectionResult}, + {"Heading": "Uncertainty of Calibration","Paragraph":sectionU}], + +doc_cer["Certificate"]["Formula"]={"NoOfMeasurements": NoOfMeasurements, + "FlowMol": FlowMol, + "FlowpV":FlowpV, + "TemperatureTL": TemperatureTL, + "LeakUncertainty": LeakUncertainty, + "MeasurementDate": MeasurementDate, + "PressureUpstream": PressureUpstream, + "PressureAtmosmin": PressureAtmosmin, + "PressureAtmosmax": PressureAtmosmax, + } + + + + # + # + # + +db.save(doc_cer) + + + + + + \ No newline at end of file diff --git a/writeLaTex-ks-TLV.py b/writeLaTex-ks-TLV.py index 4a0512113923f4abe5d3257840b83db15e743be9..4f31d8e5f108e0b787c9e4017546fe3abeb00e95 100644 --- a/writeLaTex-ks-TLV.py +++ b/writeLaTex-ks-TLV.py @@ -1,435 +1,435 @@ -# -*- coding: utf-8 -*- -""" -Created on Tue Aug 23 09:45:09 2022 - -@author: becker07 -""" - -import time -import couchdb -from datetime import date -couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') -db = couch['vl_db'] # existing - - -## Eingabe von: -# - Kalibrierscheinnummer -# - Jahr der Kalibrierung -# - laufende Nummer der Kalibrierung - -cal_cert = "75573" -year = "2024" -year_Mark=year[2:] -print(year_Mark) -no = "0001" -CertificateDate = str(date.today()) - - -json_file_cer = "cer-" + year + "-" + cal_cert - -print(json_file_cer) - - -id_cer = 0 - -mango = {'selector': {'_id':json_file_cer}} -for i in db.find(mango): - id_cer = 1 - -print(id_cer) - - -doc = {'_id': json_file_cer} - -if id_cer == 0: - db.save(doc) - print ( "Warten! 30 Sekunden" ) - time.sleep ( 30 ) - print ( json_file_cer," ist in der Couch angelegt" ) - -else: - print ( json_file_cer," ist bereits in der Couch angelegt" ) - - -id_ = "cal-" + year + "-fm1-kk-" + cal_cert + "_" + no -ks = "C:\\Users\\becker07\\kalibrierschein\\ks-" + cal_cert + "-" + year + ".tex" - -cer = "cer-" + year + "-" + cal_cert - -json_file_cal = id_ -json_file_cer = cer -doc_cal = db.get(json_file_cal) -doc_cer = db.get(json_file_cer) - - -print(json_file_cal) - - - -##### Meta ####### - -kind = doc_cal["Calibration"]["ToDo"]["Type"] -gas = doc_cal["Calibration"]["ToDo"]["Gas"] -lang = doc_cal["Calibration"]["Customer"]["Lang"] -calibration_type = "KK" -last_cert_no = doc_cal["Calibration"]["Presettings"] - - -###### überprüfen ob eine letztes Cal-Zeichen gibt ######################### - -if "LastCalibrationYear" in last_cert_no: - print("\"last_cert_no\" ist vorhanden.") - last_cert_no = doc_cal["Calibration"]["Presettings"]["LastCalibrationCertificate"] - last_cert_year = doc_cal["Calibration"]["Presettings"]["LastCalibrationYear"] - last_cert = last_cert_no + "\\,PTB\\," + last_cert_year[2:] - sectionDiscription_noyes= "yes" - print(last_cert) - -else: - print("\"last_cert_no\" ist nicht vorhanden.") - sectionDiscription_noyes= "no" - last_cert = "" - - - - - - -##### Titlepage ####### - - -MeasurementDateBegin = doc_cal["Calibration"]["Measurement"]["Date"][0]["Value"] -MeasurementDateBegin = MeasurementDateBegin[0] -MeasurementDateEnd = doc_cal["Calibration"]["Measurement"]["Date"][0]["Value"] -MeasurementDateEnd = MeasurementDateEnd[0] - - -CountryCode= lang -DeviceClass= "TLV" - -Standard = doc_cal["Calibration"]["ToDo"]["Standard"] -Land= doc_cal["Calibration"]["Customer"]["Address"]["Land"] - -##### Titlepage ####### -Certificate = str(doc_cal["Calibration"]["Certificate"]) -ReferenceNo = doc_cal["Calibration"]["Presettings"]["ReferenceNo"] -Name= doc_cal["Calibration"]["Customer"]["Name"] -AddName= doc_cal["Calibration"]["Customer"]["AddName"] -Street= doc_cal["Calibration"]["Customer"]["Address"]["Street"] -Town= doc_cal["Calibration"]["Customer"]["Address"]["Town"] -Zipcode= doc_cal["Calibration"]["Customer"]["Address"]["Zipcode"] -ObjectOfCalibration= doc_cal["Calibration"]["CustomerObject"]["Type"] -Producer= doc_cal["Calibration"]["CustomerObject"]["Device"]["Producer"] -Type= doc_cal["Calibration"]["CustomerObject"]["Device"]["Type"] ########## Type -Object= doc_cal["Calibration"]["CustomerObject"]["NameCer"] ########## Gegenstand/Object -Serial= doc_cal["Calibration"]["CustomerObject"]["Name"] ########## Kennummer -Examiner= doc_cal["Calibration"]["Measurement"]["Maintainer"] -ByOrder= "Dr. Matthias Bernien" -MeasurementDate= doc_cal["Calibration"]["Result"]["Formula"]["MeasurementDate"] -QMS= doc_cal["Calibration"]["Result"]["Formula"]["QMS"] - -print(MeasurementDate) - -obj ='\\object{'+ Object + '}\n' -manufacturer = '\\manufacturer{' + Producer +' }\n' -typ = '\\type{' + Type + '}\n' -serialNo = '\\serialNo{' + Serial + '}\n' -applicant = '\\applicant{{' + Name + '}\n {' + Street + '} \n {' + Zipcode +' ' + Town +'}\n {' + Land+'}}\n' -refNo = '\\refNo{ ' + ReferenceNo + '}\n' -calibMark = '\\calibMark{ ' + Certificate + ' PTB ' + year_Mark + '}\n' -print(calibMark) -calibDate = '\\calibDate{' + MeasurementDate + '}\n' -examiner = '\\examiner{' + Examiner + '}\n' -certificateDate = '\\certificateDate{' + CertificateDate + '}\n' - -##################section Beschreibung zum Kalibriergerät - - -if (sectionDiscription_noyes!= 'yes'): - - sectionDiscription_2= " Dies ist die erste von der PTB durchgeführte Kalibrierung." - sectionDiscription_2_en= "This is the first calibration at PTB." - print(" 1. durchgeführte Kalibrierung") - -else: - - sectionDiscription_2= " Die von der PTB zuletzt durchgeführten Kalibrierung ist im Kalibrierschein " + last_cert + " beschrieben." - sectionDiscription_2_en= " The previous calibration at PTB had been carried out " + last_cert_year + ' with the calibration mark ' + last_cert + " ." - - -TextDE= doc_cal["Calibration"]["CustomerObject"]["Text"]["description"]["de"] -TextEN= doc_cal["Calibration"]["CustomerObject"]["Text"]["description"]["en"] - -sectionText_title_de = 'Beschreibung zum Kalibriergerät ' -sectionText_title_en = 'Description relating to calibration device' -sectionTitleText_de = '\\section{' + sectionText_title_de + '\\linebreak {\\small \\emph{' + sectionText_title_en + 'Description relating to calibration device}}}\n' + TextDE + sectionDiscription_2+'\n' + '\\begin{english}' + TextEN + sectionDiscription_2_en +'\\end{english} \n' -sectionTitleText_en = '\\section{' + sectionText_title_en + ' }\n' + TextEN +sectionDiscription_2_en +'\n' - - - - - - - -######################### Messverfahren ######################################################################### - -sectionTitelProcedure = 'Kalibrierverfahren ' -sectionTitelProcedure_en = 'Calibration procedure' -sectionTitelProcedure_text_en = '\\section{' + sectionTitelProcedure_en + '}\n ' -sectionTitelProcedure_text = '\\section{' + sectionTitelProcedure + '\\linebreak {\\small \\emph{' + sectionTitelProcedure_en + '}}}\n ' - -sectionProcedure1='Der aus dem thermostatisierten Testleck TL austretende Gasfluss wird mit Hilfe eines Massenspektrometers mit einem annähernd gleich groß eingestellten Gasfluss \\(q_{\\text{mol, FM}}\\) verglichen, dessen Größe mit einem Durchflussmesser (Flowmeter FM) bestimmt wird. Die Durchflussmessung erfolgt bei konstantem Druck \\(p_\\text{FM}\\) und konstanter Temperatur \\(T_{\\text{FM}}\\).\n ' -sectionProcedure1_en ='The gas flow from the leak TL is compared with a gas flow \\(q_{\\text{mol, FM}}\\) of about the same flow rate from a flow meter FM by a mass spectrometer. The flow measurement is operated at constant pressure \\(p_{\\text{FM}}\\) and constant (absolute) temperature \\(T_{\\text{FM}}\\). \n' -sectionProcedureE1 = ' \\[ q_{\\text{mol, FM}} = p_{\\text{FM}} \\cdot C \\cdot \\frac{1}{R \\cdot T_{\\text{FM}}} \\] ' -sectionProcedure2=' Der Druck \\(p_{\\text{FM}}\\) wurde mit einem kapazitiven Membranvakuummeter gemessen. Dieses Gerät ist durch Vergleich mit einem Primärnormal der PTB kalibriert worden. Der Leitwert \\(C\\) wird aus der zeitlichen Volumenänderung (\\(\\Delta V/\\Delta t\\)) eines zusammendrückbaren, kalibrierten Federbalgs (\\(\\Delta V\\)) und einer elektronischen Uhr (\\(\\Delta t\\)) ermittelt. Die molare Gaskonstante \\(R\\) hat den Wert 83,145~\\(\\text{mbar}\\)~\\(\\text{l}\\)~\\(\\text{mol}^{-1}\\)~\\(\\text{K}^{-1}\\). \n ' -sectionProcedure2_en=' The pressure \\(p_{\\text{FM}}\\) is measured with a capacitance diaphragm gauge. This gauge is calibrated by comparison with a primary standard of PTB. The conductance \\(C\\) of the capillary integrated in the flow meter is obtained from the temporal volume change (\\(\\Delta V/\\Delta t\\)) that is needed to keep \\(p_\\text{FM}\\) constant. It is measured by means of a calibrated bellow and an electronic clock. The molar gas constant \\(R\\) has the value 83.145~\\(\\text{mbar}\\)~\\(\\text{l}\\)~\\(\\text{mol}^{-1}\\)~\\(\\text{K}^{-1}\\). ' -sectionProcedureE3 = ' \\[ q_{\\text{mol, TL}} = q_{\\text{mol, FM}} \\cdot \\frac{S_{\\text{TL}}}{S_{\\text{FM}}} \\] ' -sectionProcedure3=' Die Leckrate \\(q_{\\text{mol, TL}}\\) des Testlecks wird nach folgender Beziehung berechnet:' -sectionProcedure3_en=' The molar leak rate \\(q_{\\text{mol, TL}}\\) of the test leak can be calculated by the following equation:' -sectionProcedure4=' mit \\(S_\\text{TL}\\) dem Signal am Massenspektrometer für den Gasfluss des Testlecks und \\(S_\\text{FM}\\) dem Signal am Massenspektrometer für den eingestellten Vergleichsgasfluss.' -sectionProcedure4_en=' whereby \\(S_{\\text{TL}}\\) is the signal at the mass spectrometer for the gas flow from the test leak and \\(S_{\\text{FM}}\\) the signal at the mass spectrometer for the gas flow from the flow meter.' - - - -sectionProcedure_text= sectionProcedure1 + sectionProcedure2 +'\\begin{english}' + sectionProcedure1_en + sectionProcedure2_en + '\\end{english}' + sectionProcedureE1 + sectionProcedure3 + '\\begin{english}' + sectionProcedure3_en + '\\end{english} '+ sectionProcedureE3 + sectionProcedure4 + '\\begin{english}' + sectionProcedure4_en + '\\end{english} ' -sectionProcedure_text_en= sectionProcedure1_en + sectionProcedure2_en + sectionProcedureE1 + sectionProcedure3_en + sectionProcedureE3 + sectionProcedure4_en + '\n' - - - - -################## Ergebnisse ################################################### - -NoOfMeasurements= doc_cal["Calibration"]["Result"]["Formula"]["NoOfMeasurements"] -FlowMol= doc_cal["Calibration"]["Result"]["Formula"]["FlowMol"] -FlowpV23= doc_cal["Calibration"]["Result"]["Formula"]["FlowpV23"] -FlowpV2X= doc_cal["Calibration"]["Result"]["Formula"]["FlowpV2X"] -TemperatureTL= doc_cal["Calibration"]["Result"]["Formula"]["TemperatureTL"] -TemperatureTLx= doc_cal["Calibration"]["Result"]["Formula"]["TemperatureTLx"] - - -QMS= doc_cal["Calibration"]["Result"]["Formula"]["QMS"] -Gauge= doc_cal["Calibration"]["Result"]["Formula"]["Gauge"] -LeakUncertainty= doc_cal["Calibration"]["Result"]["Formula"]["LeakUncertainty"] -print("TLX= ",TemperatureTLx) - -sectionTitelMeasurement = 'Messergebnis ' -sectionTitelMeasurement_en = 'Measurement results' -sectionTitelMeasurement_text_en = '\\section{' + sectionTitelMeasurement_en + '}\n ' -sectionTitelMeasurement_text = '\\section{' + sectionTitelMeasurement + '\\linebreak {\\small \\emph{' + sectionTitelMeasurement_en + '}}}\n ' - - -sectionResultMol = 'Mit dem thermostatisierten Testleck wurden insgesamt ' + NoOfMeasurements + '~Leckratenbestimmungen bei einer Testlecktemperatur von \\( \\vartheta_\\text{TL}= \\SI{' + TemperatureTL + '}{\\degreeCelsius} \\) durchgeführt. Der Mittelwert ergab die (molare) Leckrate: ' -sectionResultMol_en = NoOfMeasurements + '~measurements were carried out at a leak temperature of \\( \\vartheta_\\text{TL}= \\SI{' + TemperatureTL + '}{\\degreeCelsius} \\) (thermostated). The mean leak rate (molar flow) was determined to: ' -sectionResultMol_pup_en = NoOfMeasurements + '~measurements were carried out at a leak temperature of \\( \\vartheta_\\text{TL}= \\SI{' + TemperatureTL + '}{\\degreeCelsius} \\) (thermostated). The mean leak rate (molar flow) for relativ pressure \\( p_{\\text{up}}=\\SI{0.0}{\\bar} \\) (leak indication) at the upstream pressure side was determined to: ' - -sectionResultMolVal= '\\[ q_\\text{mol}(\\vartheta_\\text{TL}) =\\SI{' + FlowMol + '}{\\mol\\per\\second} \\] ' -sectionResultMolVal_en= '\\( q_\\text{mol}(\\vartheta_\\text{TL}) =\\SI{' + FlowMol + '}{\\mol\\per\\second} \\) ' -sectionResultpV = 'Daraus kann für den Ort mit einer Temperatur \\(\\vartheta_\\text{Ch}\\) in \\si{\\degreeCelsius}, an dem sich der Prüfling befindet und mit \\(T_0 = \\SI{273.15}{\\kelvin}\\), der \\(pV\\)-Durchfluss nach folgender Beziehung berechnet werden.' -sectionResultpV_en = 'From this the \\(pV\\)-flow can be calculated for a place at a temperature \\(\\vartheta_\\text{Ch}\\) (in \\si{\\degreeCelsius}), where a device under test is mounted and \\(T_0 = \\SI{273.15}{\\kelvin}\\), by the equation:' -sectionResultpVVal = '\\[q_{pV}(\\vartheta_\\text{Ch}) = q_{\\text{mol}}(\\vartheta_\\text{TL})\\cdot R \\cdot (\\vartheta_\\text{Ch} + T_0)\\] ' - -sectionResultpV_T = 'Bei einer Kammertemperatur von \\( \\vartheta_\\text{TL}= \\SI{23}{\\degreeCelsius} \\) beträgt die Leckrate \\( q_{pV}(\\SI{23}{\\degreeCelsius}) \\):' -sectionResultpV_T_en = 'At a chamber temperature \\(\\vartheta_\\text{Ch}=\\SI{23}{\\degreeCelsius}\\) the leak rate \\(q_{pV}(\\SI{23}{\\degreeCelsius})\\) will be:' - -sectionResultpV_Tx = 'und bei einer Kammertemperatur von \\( \\vartheta_\\text{TL}= \\SI{'+ TemperatureTLx +'}{\\degreeCelsius} \\) beträgt die Leckrate \\( q_{pV}(\\SI{'+ TemperatureTLx +'}{\\degreeCelsius}) \\):' -sectionResultpV_Tx_en = 'and at a chamber temperature \\(\\vartheta_\\text{Ch}=\\SI{'+ TemperatureTLx +'}{\\degreeCelsius}\\) the leak rate \\(q_{pV}(\\SI{'+ TemperatureTLx +'}{\\degreeCelsius})\\) will be:' - -sectionResultpVVal_T23 = ' \\[q_{pV}(\\SI{23}{\\degreeCelsius})= \\num{' + FlowpV23 + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}\\]' -sectionResultpVVal_T23_en = '\\( q_{pV}(\\SI{23}{\\degreeCelsius})= \\num{' + FlowpV23 + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}\\)' -sectionResultpVVal_Tx = ' \\[q_{pV}(\\SI{' + TemperatureTLx + '}{\\degreeCelsius})= \\num{' + FlowpV2X + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}\\]' -sectionResultpVVal_Tx_en = ' \\( q_{pV}(\\SI{'+ TemperatureTLx +'}{\\degreeCelsius})= \\num{' + FlowpV2X + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}\\)' - - -sectionResultU = 'Die relative Unsicherheit \\(U\\) der angegebenen Leckraten beträgt \\( \\SI{'+ LeakUncertainty +'}{\\percent} \\).' -sectionResultU_en = 'The relative uncertainty \\(U\\) of the stated leak rate is \\( \\SI{'+ LeakUncertainty +'}{\\percent} \\). ' - - -sectionResult = sectionResultMol + sectionResultMolVal +'\\begin{english}' + sectionResultMol_en + sectionResultMolVal_en + '\\end{english}' + sectionResultpV + '\\begin{english}' + sectionResultpV_en +'\\end{english}' + sectionResultpVVal + '\\linebreak ' + sectionResultpV_T + sectionResultpVVal_T23 + '\\begin{english}' + sectionResultpV_T_en + sectionResultpVVal_T23_en + '\\end{english}' + sectionResultU + '\\begin{english}' + sectionResultU + '\\end{english}' -sectionResult_Tx = sectionResultMol + sectionResultMolVal +'\\begin{english}' + sectionResultMol_en + sectionResultMolVal_en + '\\end{english}' + sectionResultpV + '\\begin{english}' + sectionResultpV_en +'\\end{english}' + sectionResultpVVal + sectionResultpV_T + sectionResultpVVal_T23 + sectionResultpV_Tx + sectionResultpVVal_Tx + '\\begin{english}' + sectionResultpV_T_en + sectionResultpVVal_T23_en + sectionResultpV_Tx_en + sectionResultpVVal_Tx_en + '\\end{english}' + sectionResultU + '\\begin{english}' + sectionResultU + '\\end{english}' - - -sectionResult_en = sectionResultMol_en + sectionResultMolVal + sectionResultpV_en + sectionResultpVVal + sectionResultpV_T_en + sectionResultpVVal_T23 -#sectionResult_en = sectionResultMol_pup_en + sectionResultMolVal + sectionResultpV_en + sectionResultpVVal + sectionResultpV_T_en + sectionResultpVVal_T23 - -######################################## Unsicherheit ###################################################### - -sectionU = 'Angegeben ist die erweiterte Messunsicherheit \\(U\\), die sich aus der Standardmessunsicherheit durch Multiplikation mit dem Erweiterungsfaktor \\(k = 2\\) ergibt. Sie wurde gemäß dem „Guide to the Expression of Uncertainty in Measurement (GUM)“ ermittelt. Der Wert der Messgröße liegt dann im Regelfall mit einer Wahrscheinlichkeit von annähernd \\SI{95}{\\percent} im zugeordneten Überdeckungsintervall.\\n ' -sectionU_en = 'The uncertainty \\(U\\) stated is the expanded measurement uncertainty obtained by multiplying the standard measurement uncertainty by the coverage factor \\(k = 2\\). It has been determined in accordance with the “Guide to the Expression of Uncertainty in Measurement (GUM)”. The value of the measurand then normally lies, with a probability of approximately \\SI{95}{\\percent} within the attributed coverage interval.' - -sectionU_text = sectionU + '\\begin{english} ' + sectionU_en + '\\end{english}' -sectionU_text_en = sectionU_en - -sectionTitelUncertainty = 'Unsicherheit ' -sectionTitelUncertainty_en = 'Uncertainty of Calibration' -sectionTitelUncertainty_text_en = '\\section{' + sectionTitelUncertainty_en + '} ' -sectionTitelUncertainty_text = '\\section{' + sectionTitelUncertainty + '\\linebreak {\\small \\emph{' + sectionTitelUncertainty_en + '}}}' - - - - -if(lang!='en'): - print("de",lang) - with open(ks,'w', encoding='utf-8') as file: - - file.write('\\listfiles\n') - file.write('\\documentclass[de,KK,CMC]{kalibrierschein}\n ') - file.write(obj) - file.write(manufacturer) - file.write(typ) - file.write(serialNo) - file.write(applicant) - file.write(refNo) - file.write(calibMark) - file.write(calibDate) - file.write('\\byOrder{Dr. M.Bernien}\n') - file.write(examiner) - file.write(certificateDate) - - file.write('\\begin{document}\n') - - file.write('\\printFirstPage\n') - - file.write(sectionTitleText_de) - sectionText = sectionTitleText_de - - file.write(sectionTitelProcedure_text) - file.write(sectionProcedure_text) - file.write('\\pagebreak') - file.write(sectionTitelMeasurement_text) - - - if(TemperatureTLx!=23): - file.write(sectionResult_Tx) - print("nicht 23") - - else: - file.write(sectionResult) - print(" 23 ToDo", sectionResult) - - - - - file.write('\\section{Unsicherheit \\linebreak {\\small \\emph{Uncertainty of Calibration}}} ') - file.write(sectionU_text) - - file.write('\\printLastPage') - file.write('\\end{document}\\n') - - - - - - - -else: - print("en Kal",lang) - with open(ks,'w', encoding='utf-8') as file: - - file.write('\\listfiles\n') - file.write('\\documentclass[en,KK,CMC]{kalibrierschein}\n ') - file.write(obj) - file.write(manufacturer) - file.write(typ) - file.write(serialNo) - file.write(applicant) - file.write(refNo) - file.write(calibMark) - file.write(calibDate) - file.write('\\byOrder{Dr. M.Bernien}\n') - file.write(examiner) - file.write(certificateDate) - - file.write('\\begin{document}\n') - - file.write('\\printFirstPage\n') - - file.write(sectionTitleText_en) - sectionText = sectionTitleText_en - - file.write(sectionTitelProcedure_text_en) - file.write(sectionProcedure_text_en) - - file.write(sectionTitelMeasurement_text_en) - file.write(sectionResult_en) - file.write(sectionResultU_en) - - if(TemperatureTLx == 23): - file.write(sectionResult_Tx) - print("nicht 23",TemperatureTLx) - - else: - - print(" 23 ToDo") - - #file.write(sectionTitelUncertainty_text_en) - #file.write(sectionU_text_en) - - file.write('\\printLastPage') - file.write('\\end{document}') - - - - -doc_cer["Certificate"]={"Meta":{"std": ["FM1"], - "id":[id_], - "kind" :[kind], - "gas": [gas], - "lang":lang, - "calibration_type":calibration_type, - }} - - - -doc_cer["Certificate"]["Titlepage"]={"CertificateDate" :CertificateDate, - "FullYear": "2024", - "ShortYear": "24", - "MeasurementDate": MeasurementDate, - "MeasurementDateBegin": MeasurementDateBegin, - "MeasurementDateEnd": MeasurementDateEnd, - "Certificate": Certificate, - "ReferenceNo": ReferenceNo, - "Customer": { - "Name": Name, - "AddName": AddName, - "Street": Street, - "Town": Town, - "Zipcode": Zipcode, - "Land": Land, - "CountryCode": Land }, - "ObjectOfCalibration": ObjectOfCalibration, - "Producer": Producer, - "Type": Type, - "Object": Object, - "Serial": Serial , - "Examiner": Examiner, - "DeviceClass": DeviceClass, - "ByOrder": ByOrder, - } - - - - - -doc_cer["Certificate"]["Section"]= [{"Heading": "Description relating to calibration device","Paragraph":sectionText}, - {"Heading": "Calibration procedure","Paragraph":sectionProcedure_text}, - {"Heading": "Measurement results","Paragraph":sectionResult}, - {"Heading": "Uncertainty of Calibration","Paragraph":sectionU}], - -doc_cer["Certificate"]["Formula"]={"NoOfMeasurements": NoOfMeasurements, - "FlowMol": FlowMol, - "FlowpV23": FlowpV23, - "FlowpV2X":FlowpV2X, - "Gauge": Gauge, - "TemperatureTL": TemperatureTL, - "TemperatureTLx": TemperatureTLx, - "LeakUncertainty": LeakUncertainty, - "MeasurementDate": MeasurementDate, - "QMS": QMS, - - } -db.save(doc_cer) - - - - - +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 23 09:45:09 2022 + +@author: becker07 +""" + +import time +import couchdb +from datetime import date +couch = couchdb.Server('http://a73434.berlin.ptb.de:5984') +db = couch['vl_db'] # existing + + +## Eingabe von: +# - Kalibrierscheinnummer +# - Jahr der Kalibrierung +# - laufende Nummer der Kalibrierung + +cal_cert = "75552" +year = "2024" +year_Mark=year[2:] +print(year_Mark) +no = "0001" +CertificateDate = str(date.today()) + + +json_file_cer = "cer-" + year + "-" + cal_cert + +print(json_file_cer) + + +id_cer = 0 + +mango = {'selector': {'_id':json_file_cer}} +for i in db.find(mango): + id_cer = 1 + +print(id_cer) + + +doc = {'_id': json_file_cer} + +if id_cer == 0: + db.save(doc) + print ( "Warten! 30 Sekunden" ) + time.sleep ( 30 ) + print ( json_file_cer," ist in der Couch angelegt" ) + +else: + print ( json_file_cer," ist bereits in der Couch angelegt" ) + + +id_ = "cal-" + year + "-fm1-kk-" + cal_cert + "_" + no +ks = "C:\\Users\\becker07\\kalibrierschein\\ks-" + cal_cert + "-" + year + ".tex" + +cer = "cer-" + year + "-" + cal_cert + +json_file_cal = id_ +json_file_cer = cer +doc_cal = db.get(json_file_cal) +doc_cer = db.get(json_file_cer) + + +print(json_file_cal) + + + +##### Meta ####### + +kind = doc_cal["Calibration"]["ToDo"]["Type"] +gas = doc_cal["Calibration"]["ToDo"]["Gas"] +lang = doc_cal["Calibration"]["Customer"]["Lang"] +calibration_type = "KK" +last_cert_no = doc_cal["Calibration"]["Presettings"] + + +###### überprüfen ob eine letztes Cal-Zeichen gibt ######################### + +if "LastCalibrationYear" in last_cert_no: + print("\"last_cert_no\" ist vorhanden.") + last_cert_no = doc_cal["Calibration"]["Presettings"]["LastCalibrationCertificate"] + last_cert_year = doc_cal["Calibration"]["Presettings"]["LastCalibrationYear"] + last_cert = last_cert_no + "\\,PTB\\," + last_cert_year[2:] + sectionDiscription_noyes= "yes" + print(last_cert) + +else: + print("\"last_cert_no\" ist nicht vorhanden.") + sectionDiscription_noyes= "no" + last_cert = "" + + + + + + +##### Titlepage ####### + + +MeasurementDateBegin = doc_cal["Calibration"]["Measurement"]["Date"][0]["Value"] +MeasurementDateBegin = MeasurementDateBegin[0] +MeasurementDateEnd = doc_cal["Calibration"]["Measurement"]["Date"][0]["Value"] +MeasurementDateEnd = MeasurementDateEnd[0] + + +CountryCode= lang +DeviceClass= "TLV" + +Standard = doc_cal["Calibration"]["ToDo"]["Standard"] +Land= doc_cal["Calibration"]["Customer"]["Address"]["Land"] + +##### Titlepage ####### +Certificate = str(doc_cal["Calibration"]["Certificate"]) +ReferenceNo = doc_cal["Calibration"]["Presettings"]["ReferenceNo"] +Name= doc_cal["Calibration"]["Customer"]["Name"] +AddName= doc_cal["Calibration"]["Customer"]["AddName"] +Street= doc_cal["Calibration"]["Customer"]["Address"]["Street"] +Town= doc_cal["Calibration"]["Customer"]["Address"]["Town"] +Zipcode= doc_cal["Calibration"]["Customer"]["Address"]["Zipcode"] +ObjectOfCalibration= doc_cal["Calibration"]["CustomerObject"]["Type"] +Producer= doc_cal["Calibration"]["CustomerObject"]["Device"]["Producer"] +Type= doc_cal["Calibration"]["CustomerObject"]["Device"]["Type"] ########## Type +Object= doc_cal["Calibration"]["CustomerObject"]["NameCer"] ########## Gegenstand/Object +Serial= doc_cal["Calibration"]["CustomerObject"]["Name"] ########## Kennummer +Examiner= doc_cal["Calibration"]["Measurement"]["Maintainer"] +ByOrder= "Dr. Matthias Bernien" +MeasurementDate= doc_cal["Calibration"]["Result"]["Formula"]["MeasurementDate"] +QMS= doc_cal["Calibration"]["Result"]["Formula"]["QMS"] + +print(MeasurementDate) + +obj ='\\object{'+ Object + '}\n' +manufacturer = '\\manufacturer{' + Producer +' }\n' +typ = '\\type{' + Type + '}\n' +serialNo = '\\serialNo{' + Serial + '}\n' +applicant = '\\applicant{{' + Name + '}\n {' + Street + '} \n {' + Zipcode +' ' + Town +'}\n {' + Land+'}}\n' +refNo = '\\refNo{ ' + ReferenceNo + '}\n' +calibMark = '\\calibMark{ ' + Certificate + ' PTB ' + year_Mark + '}\n' +print(calibMark) +calibDate = '\\calibDate{' + MeasurementDate + '}\n' +examiner = '\\examiner{' + Examiner + '}\n' +certificateDate = '\\certificateDate{' + CertificateDate + '}\n' + +##################section Beschreibung zum Kalibriergerät + + +if (sectionDiscription_noyes!= 'yes'): + + sectionDiscription_2= " Dies ist die erste von der PTB durchgeführte Kalibrierung." + sectionDiscription_2_en= "This is the first calibration at PTB." + print(" 1. durchgeführte Kalibrierung") + +else: + + sectionDiscription_2= " Die von der PTB zuletzt durchgeführten Kalibrierung ist im Kalibrierschein " + last_cert + " beschrieben." + sectionDiscription_2_en= " The previous calibration at PTB had been carried out " + last_cert_year + ' with the calibration mark ' + last_cert + " ." + + +TextDE= doc_cal["Calibration"]["CustomerObject"]["Text"]["description"]["de"] +TextEN= doc_cal["Calibration"]["CustomerObject"]["Text"]["description"]["en"] + +sectionText_title_de = 'Beschreibung zum Kalibriergerät ' +sectionText_title_en = 'Description relating to calibration device' +sectionTitleText_de = '\\section{' + sectionText_title_de + '\\linebreak {\\small \\emph{' + sectionText_title_en + 'Description relating to calibration device}}}\n' + TextDE + sectionDiscription_2+'\n' + '\\begin{english}' + TextEN + sectionDiscription_2_en +'\\end{english} \n' +sectionTitleText_en = '\\section{' + sectionText_title_en + ' }\n' + TextEN +sectionDiscription_2_en +'\n' + + + + + + + +######################### Messverfahren ######################################################################### + +sectionTitelProcedure = 'Kalibrierverfahren ' +sectionTitelProcedure_en = 'Calibration procedure' +sectionTitelProcedure_text_en = '\\section{' + sectionTitelProcedure_en + '}\n ' +sectionTitelProcedure_text = '\\section{' + sectionTitelProcedure + '\\linebreak {\\small \\emph{' + sectionTitelProcedure_en + '}}}\n ' + +sectionProcedure1='Der aus dem thermostatisierten Testleck TL austretende Gasfluss wird mit Hilfe eines Massenspektrometers mit einem annähernd gleich groß eingestellten Gasfluss \\(q_{\\text{mol, FM}}\\) verglichen, dessen Größe mit einem Durchflussmesser (Flowmeter FM) bestimmt wird. Die Durchflussmessung erfolgt bei konstantem Druck \\(p_\\text{FM}\\) und konstanter Temperatur \\(T_{\\text{FM}}\\).\n ' +sectionProcedure1_en ='The gas flow from the leak TL is compared with a gas flow \\(q_{\\text{mol, FM}}\\) of about the same flow rate from a flow meter FM by a mass spectrometer. The flow measurement is operated at constant pressure \\(p_{\\text{FM}}\\) and constant (absolute) temperature \\(T_{\\text{FM}}\\). \n' +sectionProcedureE1 = ' \\[ q_{\\text{mol, FM}} = p_{\\text{FM}} \\cdot C \\cdot \\frac{1}{R \\cdot T_{\\text{FM}}} \\] ' +sectionProcedure2=' Der Druck \\(p_{\\text{FM}}\\) wurde mit einem kapazitiven Membranvakuummeter gemessen. Dieses Gerät ist durch Vergleich mit einem Primärnormal der PTB kalibriert worden. Der Leitwert \\(C\\) wird aus der zeitlichen Volumenänderung (\\(\\Delta V/\\Delta t\\)) eines zusammendrückbaren, kalibrierten Federbalgs (\\(\\Delta V\\)) und einer elektronischen Uhr (\\(\\Delta t\\)) ermittelt. Die molare Gaskonstante \\(R\\) hat den Wert 83,145~\\(\\text{mbar}\\)~\\(\\text{l}\\)~\\(\\text{mol}^{-1}\\)~\\(\\text{K}^{-1}\\). \n ' +sectionProcedure2_en=' The pressure \\(p_{\\text{FM}}\\) is measured with a capacitance diaphragm gauge. This gauge is calibrated by comparison with a primary standard of PTB. The conductance \\(C\\) of the capillary integrated in the flow meter is obtained from the temporal volume change (\\(\\Delta V/\\Delta t\\)) that is needed to keep \\(p_\\text{FM}\\) constant. It is measured by means of a calibrated bellow and an electronic clock. The molar gas constant \\(R\\) has the value 83.145~\\(\\text{mbar}\\)~\\(\\text{l}\\)~\\(\\text{mol}^{-1}\\)~\\(\\text{K}^{-1}\\). ' +sectionProcedureE3 = ' \\[ q_{\\text{mol, TL}} = q_{\\text{mol, FM}} \\cdot \\frac{S_{\\text{TL}}}{S_{\\text{FM}}} \\] ' +sectionProcedure3=' Die Leckrate \\(q_{\\text{mol, TL}}\\) des Testlecks wird nach folgender Beziehung berechnet:' +sectionProcedure3_en=' The molar leak rate \\(q_{\\text{mol, TL}}\\) of the test leak can be calculated by the following equation:' +sectionProcedure4=' mit \\(S_\\text{TL}\\) dem Signal am Massenspektrometer für den Gasfluss des Testlecks und \\(S_\\text{FM}\\) dem Signal am Massenspektrometer für den eingestellten Vergleichsgasfluss.' +sectionProcedure4_en=' whereby \\(S_{\\text{TL}}\\) is the signal at the mass spectrometer for the gas flow from the test leak and \\(S_{\\text{FM}}\\) the signal at the mass spectrometer for the gas flow from the flow meter.' + + + +sectionProcedure_text= sectionProcedure1 + sectionProcedure2 +'\\begin{english}' + sectionProcedure1_en + sectionProcedure2_en + '\\end{english}' + sectionProcedureE1 + sectionProcedure3 + '\\begin{english}' + sectionProcedure3_en + '\\end{english} '+ sectionProcedureE3 + sectionProcedure4 + '\\begin{english}' + sectionProcedure4_en + '\\end{english} ' +sectionProcedure_text_en= sectionProcedure1_en + sectionProcedure2_en + sectionProcedureE1 + sectionProcedure3_en + sectionProcedureE3 + sectionProcedure4_en + '\n' + + + + +################## Ergebnisse ################################################### + +NoOfMeasurements= doc_cal["Calibration"]["Result"]["Formula"]["NoOfMeasurements"] +FlowMol= doc_cal["Calibration"]["Result"]["Formula"]["FlowMol"] +FlowpV23= doc_cal["Calibration"]["Result"]["Formula"]["FlowpV23"] +FlowpV2X= doc_cal["Calibration"]["Result"]["Formula"]["FlowpV2X"] +TemperatureTL= doc_cal["Calibration"]["Result"]["Formula"]["TemperatureTL"] +TemperatureTLx= doc_cal["Calibration"]["Result"]["Formula"]["TemperatureTLx"] + + +QMS= doc_cal["Calibration"]["Result"]["Formula"]["QMS"] +Gauge= doc_cal["Calibration"]["Result"]["Formula"]["Gauge"] +LeakUncertainty= doc_cal["Calibration"]["Result"]["Formula"]["LeakUncertainty"] +print("TLX= ",TemperatureTLx) + +sectionTitelMeasurement = 'Messergebnis ' +sectionTitelMeasurement_en = 'Measurement results' +sectionTitelMeasurement_text_en = '\\section{' + sectionTitelMeasurement_en + '}\n ' +sectionTitelMeasurement_text = '\\section{' + sectionTitelMeasurement + '\\linebreak {\\small \\emph{' + sectionTitelMeasurement_en + '}}}\n ' + + +sectionResultMol = 'Mit dem thermostatisierten Testleck wurden insgesamt ' + NoOfMeasurements + '~Leckratenbestimmungen bei einer Testlecktemperatur von \\( \\vartheta_\\text{TL}= \\SI{' + TemperatureTL + '}{\\degreeCelsius} \\) durchgeführt. Der Mittelwert ergab die (molare) Leckrate: ' +sectionResultMol_en = NoOfMeasurements + '~measurements were carried out at a leak temperature of \\( \\vartheta_\\text{TL}= \\SI{' + TemperatureTL + '}{\\degreeCelsius} \\) (thermostated). The mean leak rate (molar flow) was determined to: ' +sectionResultMol_pup_en = NoOfMeasurements + '~measurements were carried out at a leak temperature of \\( \\vartheta_\\text{TL}= \\SI{' + TemperatureTL + '}{\\degreeCelsius} \\) (thermostated). The mean leak rate (molar flow) for relativ pressure \\( p_{\\text{up}}=\\SI{0.0}{\\bar} \\) (leak indication) at the upstream pressure side was determined to: ' + +sectionResultMolVal= '\\[ q_\\text{mol}(\\vartheta_\\text{TL}) =\\SI{' + FlowMol + '}{\\mol\\per\\second} \\] ' +sectionResultMolVal_en= '\\( q_\\text{mol}(\\vartheta_\\text{TL}) =\\SI{' + FlowMol + '}{\\mol\\per\\second} \\) ' +sectionResultpV = 'Daraus kann für den Ort mit einer Temperatur \\(\\vartheta_\\text{Ch}\\) in \\si{\\degreeCelsius}, an dem sich der Prüfling befindet und mit \\(T_0 = \\SI{273.15}{\\kelvin}\\), der \\(pV\\)-Durchfluss nach folgender Beziehung berechnet werden.' +sectionResultpV_en = 'From this the \\(pV\\)-flow can be calculated for a place at a temperature \\(\\vartheta_\\text{Ch}\\) (in \\si{\\degreeCelsius}), where a device under test is mounted and \\(T_0 = \\SI{273.15}{\\kelvin}\\), by the equation:' +sectionResultpVVal = '\\[q_{pV}(\\vartheta_\\text{Ch}) = q_{\\text{mol}}(\\vartheta_\\text{TL})\\cdot R \\cdot (\\vartheta_\\text{Ch} + T_0)\\] ' + +sectionResultpV_T = 'Bei einer Kammertemperatur von \\( \\vartheta_\\text{TL}= \\SI{23}{\\degreeCelsius} \\) beträgt die Leckrate \\( q_{pV}(\\SI{23}{\\degreeCelsius}) \\):' +sectionResultpV_T_en = 'At a chamber temperature \\(\\vartheta_\\text{Ch}=\\SI{23}{\\degreeCelsius}\\) the leak rate \\(q_{pV}(\\SI{23}{\\degreeCelsius})\\) will be:' + +sectionResultpV_Tx = 'und bei einer Kammertemperatur von \\( \\vartheta_\\text{TL}= \\SI{'+ TemperatureTLx +'}{\\degreeCelsius} \\) beträgt die Leckrate \\( q_{pV}(\\SI{'+ TemperatureTLx +'}{\\degreeCelsius}) \\):' +sectionResultpV_Tx_en = 'and at a chamber temperature \\(\\vartheta_\\text{Ch}=\\SI{'+ TemperatureTLx +'}{\\degreeCelsius}\\) the leak rate \\(q_{pV}(\\SI{'+ TemperatureTLx +'}{\\degreeCelsius})\\) will be:' + +sectionResultpVVal_T23 = ' \\[q_{pV}(\\SI{23}{\\degreeCelsius})= \\num{' + FlowpV23 + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}\\]' +sectionResultpVVal_T23_en = '\\( q_{pV}(\\SI{23}{\\degreeCelsius})= \\num{' + FlowpV23 + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}\\)' +sectionResultpVVal_Tx = ' \\[q_{pV}(\\SI{' + TemperatureTLx + '}{\\degreeCelsius})= \\num{' + FlowpV2X + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}\\]' +sectionResultpVVal_Tx_en = ' \\( q_{pV}(\\SI{'+ TemperatureTLx +'}{\\degreeCelsius})= \\num{' + FlowpV2X + '} ~\\text{Pa}~\\text{m}^3~\\text{s}^{-1}\\)' + + +sectionResultU = 'Die relative Unsicherheit \\(U\\) der angegebenen Leckraten beträgt \\( \\SI{'+ LeakUncertainty +'}{\\percent} \\).' +sectionResultU_en = 'The relative uncertainty \\(U\\) of the stated leak rate is \\( \\SI{'+ LeakUncertainty +'}{\\percent} \\). ' + + +sectionResult = sectionResultMol + sectionResultMolVal +'\\begin{english}' + sectionResultMol_en + sectionResultMolVal_en + '\\end{english}' + sectionResultpV + '\\begin{english}' + sectionResultpV_en +'\\end{english}' + sectionResultpVVal + '\\linebreak ' + sectionResultpV_T + sectionResultpVVal_T23 + '\\begin{english}' + sectionResultpV_T_en + sectionResultpVVal_T23_en + '\\end{english}' + sectionResultU + '\\begin{english}' + sectionResultU + '\\end{english}' +sectionResult_Tx = sectionResultMol + sectionResultMolVal +'\\begin{english}' + sectionResultMol_en + sectionResultMolVal_en + '\\end{english}' + sectionResultpV + '\\begin{english}' + sectionResultpV_en +'\\end{english}' + sectionResultpVVal + sectionResultpV_T + sectionResultpVVal_T23 + sectionResultpV_Tx + sectionResultpVVal_Tx + '\\begin{english}' + sectionResultpV_T_en + sectionResultpVVal_T23_en + sectionResultpV_Tx_en + sectionResultpVVal_Tx_en + '\\end{english}' + sectionResultU + '\\begin{english}' + sectionResultU + '\\end{english}' + + +sectionResult_en = sectionResultMol_en + sectionResultMolVal + sectionResultpV_en + sectionResultpVVal + sectionResultpV_T_en + sectionResultpVVal_T23 +#sectionResult_en = sectionResultMol_pup_en + sectionResultMolVal + sectionResultpV_en + sectionResultpVVal + sectionResultpV_T_en + sectionResultpVVal_T23 + +######################################## Unsicherheit ###################################################### + +sectionU = 'Angegeben ist die erweiterte Messunsicherheit \\(U\\), die sich aus der Standardmessunsicherheit durch Multiplikation mit dem Erweiterungsfaktor \\(k = 2\\) ergibt. Sie wurde gemäß dem „Guide to the Expression of Uncertainty in Measurement (GUM)“ ermittelt. Der Wert der Messgröße liegt dann im Regelfall mit einer Wahrscheinlichkeit von annähernd \\SI{95}{\\percent} im zugeordneten Überdeckungsintervall.\\n ' +sectionU_en = 'The uncertainty \\(U\\) stated is the expanded measurement uncertainty obtained by multiplying the standard measurement uncertainty by the coverage factor \\(k = 2\\). It has been determined in accordance with the “Guide to the Expression of Uncertainty in Measurement (GUM)”. The value of the measurand then normally lies, with a probability of approximately \\SI{95}{\\percent} within the attributed coverage interval.' + +sectionU_text = sectionU + '\\begin{english} ' + sectionU_en + '\\end{english}' +sectionU_text_en = sectionU_en + +sectionTitelUncertainty = 'Unsicherheit ' +sectionTitelUncertainty_en = 'Uncertainty of Calibration' +sectionTitelUncertainty_text_en = '\\section{' + sectionTitelUncertainty_en + '} ' +sectionTitelUncertainty_text = '\\section{' + sectionTitelUncertainty + '\\linebreak {\\small \\emph{' + sectionTitelUncertainty_en + '}}}' + + + + +if(lang!='en'): + print("de",lang) + with open(ks,'w', encoding='utf-8') as file: + + file.write('\\listfiles\n') + file.write('\\documentclass[de,KK,CMC]{kalibrierschein}\n ') + file.write(obj) + file.write(manufacturer) + file.write(typ) + file.write(serialNo) + file.write(applicant) + file.write(refNo) + file.write(calibMark) + file.write(calibDate) + file.write('\\byOrder{Dr. M.Bernien}\n') + file.write(examiner) + file.write(certificateDate) + + file.write('\\begin{document}\n') + + file.write('\\printFirstPage\n') + + file.write(sectionTitleText_de) + sectionText = sectionTitleText_de + + file.write(sectionTitelProcedure_text) + file.write(sectionProcedure_text) + file.write('\\pagebreak') + file.write(sectionTitelMeasurement_text) + + + if(TemperatureTLx!=23): + file.write(sectionResult_Tx) + print("nicht 23") + + else: + file.write(sectionResult) + print(" 23 ToDo", sectionResult) + + + + + file.write('\\section{Unsicherheit \\linebreak {\\small \\emph{Uncertainty of Calibration}}} ') + file.write(sectionU_text) + + file.write('\\printLastPage') + file.write('\\end{document}\\n') + + + + + + + +else: + print("en Kal",lang) + with open(ks,'w', encoding='utf-8') as file: + + file.write('\\listfiles\n') + file.write('\\documentclass[en,KK,CMC]{kalibrierschein}\n ') + file.write(obj) + file.write(manufacturer) + file.write(typ) + file.write(serialNo) + file.write(applicant) + file.write(refNo) + file.write(calibMark) + file.write(calibDate) + file.write('\\byOrder{Dr. M.Bernien}\n') + file.write(examiner) + file.write(certificateDate) + + file.write('\\begin{document}\n') + + file.write('\\printFirstPage\n') + + file.write(sectionTitleText_en) + sectionText = sectionTitleText_en + + file.write(sectionTitelProcedure_text_en) + file.write(sectionProcedure_text_en) + + file.write(sectionTitelMeasurement_text_en) + file.write(sectionResult_en) + file.write(sectionResultU_en) + + if(TemperatureTLx == 23): + file.write(sectionResult_Tx) + print("nicht 23",TemperatureTLx) + + else: + + print(" 23 ToDo") + + #file.write(sectionTitelUncertainty_text_en) + #file.write(sectionU_text_en) + + file.write('\\printLastPage') + file.write('\\end{document}') + + + + +doc_cer["Certificate"]={"Meta":{"std": ["FM1"], + "id":[id_], + "kind" :[kind], + "gas": [gas], + "lang":lang, + "calibration_type":calibration_type, + }} + + + +doc_cer["Certificate"]["Titlepage"]={"CertificateDate" :CertificateDate, + "FullYear": "2024", + "ShortYear": "24", + "MeasurementDate": MeasurementDate, + "MeasurementDateBegin": MeasurementDateBegin, + "MeasurementDateEnd": MeasurementDateEnd, + "Certificate": Certificate, + "ReferenceNo": ReferenceNo, + "Customer": { + "Name": Name, + "AddName": AddName, + "Street": Street, + "Town": Town, + "Zipcode": Zipcode, + "Land": Land, + "CountryCode": Land }, + "ObjectOfCalibration": ObjectOfCalibration, + "Producer": Producer, + "Type": Type, + "Object": Object, + "Serial": Serial , + "Examiner": Examiner, + "DeviceClass": DeviceClass, + "ByOrder": ByOrder, + } + + + + + +doc_cer["Certificate"]["Section"]= [{"Heading": "Description relating to calibration device","Paragraph":sectionText}, + {"Heading": "Calibration procedure","Paragraph":sectionProcedure_text}, + {"Heading": "Measurement results","Paragraph":sectionResult}, + {"Heading": "Uncertainty of Calibration","Paragraph":sectionU}], + +doc_cer["Certificate"]["Formula"]={"NoOfMeasurements": NoOfMeasurements, + "FlowMol": FlowMol, + "FlowpV23": FlowpV23, + "FlowpV2X":FlowpV2X, + "Gauge": Gauge, + "TemperatureTL": TemperatureTL, + "TemperatureTLx": TemperatureTLx, + "LeakUncertainty": LeakUncertainty, + "MeasurementDate": MeasurementDate, + "QMS": QMS, + + } +db.save(doc_cer) + + + + +