From 7f67736f4e20ae19278d2fea64523f3599252a1f Mon Sep 17 00:00:00 2001
From: Ute Becker <ute.becker@ptb.de>
Date: Tue, 30 Apr 2024 14:57:05 +0200
Subject: [PATCH] =?UTF-8?q?Die=20Werte=20aus=20dem=20Messprogramm=20TL1=20?=
 =?UTF-8?q?werden=20in=20das=20cal-dokument=20=C3=BCbertragen?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 file-to-couchdb_tl1.py | 688 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 688 insertions(+)
 create mode 100644 file-to-couchdb_tl1.py

diff --git a/file-to-couchdb_tl1.py b/file-to-couchdb_tl1.py
new file mode 100644
index 0000000..9912909
--- /dev/null
+++ b/file-to-couchdb_tl1.py
@@ -0,0 +1,688 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Jul  1 12:12:37 2022
+
+@author: becker07
+"""
+import sys
+import numpy as np
+import couchdb 
+import pandas as pd
+import json
+import csv
+import re
+from matplotlib import pyplot as plt
+import pathlib
+
+try:
+    from configparser import ConfigParser
+except ImportError:
+    from ConfigParser import ConfigParser  # ver. < 3.0
+
+
+configtl = ConfigParser()
+ini_values = ConfigParser()
+# parse existing file
+configtl.read('tl.ini')
+ini_values.read('inputs.ini')
+
+server=configtl.get('couch', 'couch')
+db_vl=configtl.get('couch', 'db')
+
+couch = couchdb.Server(server)
+db = couch[db_vl] # existing
+
+
+## Eingabe von:
+#    - Kalibrierscheinnummer
+#    - Jahr der Kalibrierung 
+#    - laufende Nummer der Kalibrierung
+
+path=configtl.get('path', 'path_files')
+
+
+
+cal_cert = ini_values.get('input_cer', 'cal_cert')
+year = ini_values.get('input_gen', 'year')
+no = ini_values.get('input_gen', 'no')
+QMS="ja"   ######### ja beim Scan
+kk_ik_pn= "kk" ######## kk,ik oder pn
+
+
+
+json_file = "cal-" + year + "-fm1-kk-" + cal_cert + "_" + no
+doc = db.get(json_file) 
+print(json_file)
+
+#path='C:\\Users\\becker07\\python\\TL1\\'
+
+dateiTab =  path + cal_cert + "_" + no
+#dateiTab='C:\\Users\\becker07\\python\\TL1\\75561'
+print(dateiTab)
+
+
+dateiTab=pd.read_csv(dateiTab,  sep="\t", decimal = ',' )
+
+L_ar=dateiTab["C "]
+print('Leitwert j= 1, nein = 0 :: ', L_ar)
+
+L=L_ar[0]
+print('Leitwert : ',L)
+
+
+gauge = float(doc["Calibration"]["CustomerObject"]["Setup"]["CDG"])
+print(gauge)
+
+fileQMS = path + "QMS" +  cal_cert + "_" + no + ".txt" 
+dateiQMS =fileQMS
+ScanQMS= path + "Scan"+ cal_cert + "_" + no+ ".txt"
+ScanOffsQMS= path + "ScanOffs"+cal_cert + "_" + no+ ".txt"
+print(ScanQMS)
+
+# Die Daten aus dem File mit der entsprechenden Kalibrierscheinnummer werden eingelesen:
+# datum, time, p_up und alle Temperaturen, 
+
+
+#datei = "N:\Abt_7\Fb75\Vakuum\Messplaetze\TL1\Kalibrierungen\\22\\TP7464.txt"
+
+if L == 1 :
+    
+    
+    m1=dateiTab["m1"]
+    m2=dateiTab["m2"]
+    m3=dateiTab["m3"]
+    m4=dateiTab["m4"]
+
+    t1=dateiTab["t1"]
+    t2=dateiTab["t2"]
+    t3=dateiTab["t3"]
+    t4=dateiTab["t4"]
+    time1=dateiTab["time1"]
+    time2=dateiTab["time2"]
+    time3=dateiTab["time3"]
+
+    pmean=dateiTab["p-mean"]*100
+    pmin=dateiTab["p-min"]*100
+    pmax=dateiTab["p-max"]*100
+    
+
+    h=dateiTab["distance"]
+    
+       
+    print("Constantes Volumen",h)
+    
+                               
+                                                                
+else:
+    print("Constanter Leitwert")
+
+
+datum=dateiTab["Datum"]
+time=dateiTab["Zeit"]
+gas=dateiTab["Gasart"]
+
+if gauge== 0.01 :
+    p_offs_01=dateiTab["p-offset"]*100
+    p_fill_01=dateiTab["p-fill "]*100
+    p_fill_srg=dateiTab["p-max"]
+    p_offs_srg=dateiTab["p-min"]
+    
+else :
+    p_offs=dateiTab["p-offset"]*100
+    p_fill=dateiTab["p-fill "]*100
+#p_fill=np.genfromtxt(dateiTab,skip_header=1,delimiter='\t',usecols=(5))
+
+p_ig=dateiTab["Kommentar"]
+T_room=dateiTab["T-Raum"]
+T_fm=dateiTab["T-FM"]
+T_tl1=dateiTab["T-TL1"]
+T_tl2=dateiTab["T-TL2"]
+T_tl3=dateiTab["T-TL3"]
+T_tl4=dateiTab["T-TL4"]
+
+#print(T_fm,T_room,T_tl1, T_tl2,T_tl3,T_tl4)
+
+
+I_TL_time=dateiTab["Time-TL"]
+I_Offs_time=dateiTab["Time-offset"]
+I_FM_time=dateiTab["Time-FM"]
+
+#print(I_TL_time,I_Offs_time,I_FM_time)
+
+Valve=dateiTab["Ventil"]
+
+
+if QMS == "ja" :
+    I_TL_time=dateiTab["Time-TL"]
+    I_Offs_time=dateiTab["Time-offset"]
+    I_FM_time=dateiTab["Time-FM"]
+
+    #print(I_TL_time,I_Offs_time,I_FM_time)
+
+
+####################### Der Scan des QMS ##############################################################################
+
+
+
+##############  die leeren Zeilen und Überschriften werden gelöscht  ###################
+
+    with open(ScanQMS, "r") as fp:
+        tab=fp.read()
+
+    with open('ScanQMS.txt', 'w') as fp:
+        fp.write(tab) 
+        
+    with open(ScanOffsQMS, "r") as fp:
+        tab=fp.read()
+
+    with open('ScanOffsQMS.txt', 'w') as fp:
+        fp.write(tab)
+
+
+    del_def = []
+    with open('ScanQMS.txt', "r") as fp:
+        del_def = fp.readlines()
+        with open('ScanQMS.txt', "w") as fp:
+            for number, line in enumerate(del_def):
+                if number not in [0, 1,6,7,22,23,24,25,47,48]:
+                    fp.write(line)
+            
+            del_def = []
+            with open('ScanOffsQMS.txt', "r") as fp:
+                del_def = fp.readlines()
+                with open('ScanOffsQMS.txt', "w") as fp:
+                    for number, line in enumerate(del_def):
+                        if number not in [0, 1,6,7,22,23,24,25,47,48]:
+                            fp.write(line)
+
+
+
+
+###########  Scan #####################
+
+    with open('ScanQMS.txt','r') as file:
+        tab=file.read()
+        lstdef=tab.rfind("Channel count")+16
+        lsttab=tab.rfind("Scan Data (Pressures in mbar)")+32
+        filetab=tab[lsttab:]                                       ### Das File wird getrennt und die Tabelle mit den Messwerten in das filetab übergeben
+        filedef=tab[:lstdef]                                       ### Das File wird getrennt und die Einstellungen und Infos in filedef übergeben
+    
+    
+    with open('QMS-Def.txt', 'w') as f:
+        f.write(filedef)
+    
+    
+    df_tab = pd.read_csv("QMS-Def.txt",
+                         sep="\t",
+                         #usecols=["Time"]
+                         header=None,
+                         )
+
+    def_key=np.array(df_tab[0])
+    l=len(def_key)
+    print(l)
+    #def_key=np.delete(def_key, l-1)
+    def_value=np.array(df_tab[1], dtype=str)
+    #def_value=np.delete(def_value, l-1)
+    
+
+   
+    with open('QMS-Scan.txt', 'w') as f:
+        f.write(filetab)    
+        df = pd.read_csv("QMS-Scan.txt",
+                         sep="\t",
+                         #usecols=["Time"]
+                         header=None,
+                         )
+        df=df.replace(np.nan, 0)
+
+
+    l=len(df)
+
+    print(l)
+
+    mass_no=np.array(df[0:1])
+    mass_unit=mass_no[0]
+    
+    
+   
+
+    if l == 3:
+        mass_value=np.array(df[1:2])
+        mass_value=mass_value[0]
+        print(mass_value())
+    else:
+        mass_value=np.array(df[l-2:l-1])
+        mass_value=mass_value[0]
+        
+
+    
+#############################################################################################################
+###########  Scan Offset   #####################
+
+    with open('ScanOffsQMS.txt','r') as file:
+        tab_offs=file.read()
+        lstdef_offs=tab_offs.rfind("Channel count")+16
+        lsttab_offs=tab_offs.rfind("Scan Data (Pressures in mbar)")+32
+        filetab_offs=tab_offs[lsttab_offs:]                                       ### Das File wird getrennt und die Tabelle mit den Messwerten in das filetab übergeben
+        filedef_offs=tab_offs[:lstdef_offs]                                       ### Das File wird getrennt und die Einstellungen und Infos in filedef übergeben
+    
+    
+    with open('QMS_Offs-Def.txt', 'w') as f:
+        f.write(filedef_offs)
+    
+    
+    df_tab_offs = pd.read_csv("QMS_Offs-Def.txt",
+                         sep="\t",
+                         #usecols=["Time"]
+                         header=None,
+                         )
+
+    def_key_offs=np.array(df_tab_offs[0])
+    l=len(def_key_offs)
+    def_value_offs=np.array(df_tab_offs[1], dtype=str)
+    #def_value=np.delete(def_value, l-1)
+    
+
+   
+    with open('QMS_Offs-Scan.txt', 'w') as f:
+        f.write(filetab_offs)    
+        df_offs = pd.read_csv("QMS_Offs-Scan.txt",
+                         sep="\t",
+                         #usecols=["Time"]
+                         header=None,
+                         )
+        df_offs=df_offs.replace(np.nan, 0)
+
+
+    l=len(df_offs)
+
+    print(l)
+
+       
+
+    if l == 3:
+        mass_value_offs=np.array(df_offs[1:2])
+        mass_value_off=mass_value_offs[0]
+        print(mass_value_offs())
+    else:
+        mass_value_offs=np.array(df_offs[l-2:l-1])
+        mass_value_off=mass_value_offs[0]
+    
+
+#############################################################################################################
+
+###################### Plot der Scans werden abgebildet und den json-dokument hinzugefügt #####################
+I_Scan=np.float64(mass_value[2:-2])
+I_Scan_Offs=np.float64(mass_value_off[2:-2])
+Mass_Scan=mass_no[0]
+Mass_Scan=Mass_Scan[2:-2]
+
+for i in range(len(Mass_Scan)):
+    Mass_Scan[i] = re.sub(r"Mass ", "", Mass_Scan[i]).strip()
+   
+   
+Mass_Scan=np.float64(Mass_Scan)
+
+fig=plt.figure()
+ax=fig.add_axes([0,0,4,2])
+ax.set_xlabel('Masse')
+ax.set_ylabel('QMS-Signal')
+ax.set_yscale('log')
+#plt.plot(1010,4.65e-10, 'bo')
+plt.plot(Mass_Scan,I_Scan, label=r'Floww')
+plt.plot(Mass_Scan,I_Scan_Offs,label=r'Offset' )
+plt.legend()
+
+
+plt.grid()
+
+fig.savefig("Scan.pdf", bbox_inches='tight')
+
+
+
+#############################################################################################################
+
+from collections import OrderedDict
+
+def getMassAverage(filename, tbegin = None, tend = None, trange = None):
+    def error_exit(x):
+        print('ERROR: ', str(x), file=sys.stderr)
+        sys.exit(1)
+    if not trange and (not tbegin or not tend):
+        error_exit('Missing time range')
+    try:
+        d = {}
+        with open(filename, 'r') as f:
+            line = f.readline()
+            dataValid = False
+            while line:
+                if dataValid:
+                    # Ende der Daten
+                    if line.startswith('"[Annotations/User Records'):
+                        dataValid = False
+                    else:
+                        l = line.strip()
+                        a = l.split('\t')# An Tabulatoren trennen
+                        # a[0] = "Time", a[1] = "Scan", a[2] = "Mass 4", a[3] = "Sum Scanned Masses"
+                        if a[0]:
+                            key = a[0].strip('"')
+                            # Timestamp als key für Dictionary
+                            d[key] = a[2]
+                else:
+                    # Beginn der Daten
+                    if line.startswith('"Time"'):
+                        dataValid = True
+                line = f.readline()            
+    except:
+        error_exit("Can't read file: " +  filename)
+    finally:
+        f.close()
+    # Sortieren bei neueren Python-Versionen unnötig?    
+    data = OrderedDict(sorted(d.items()))
+    
+    def doAverage(beg, end):
+        sum = 0.0
+        cnt = 0
+        for key in data:
+            if key >= beg and key < end:
+              #print(key, '-->', data[key])
+              cnt += 1
+              sum += float(data[key])
+        return sum / cnt
+    
+    tb = []
+    te = []
+    res = []
+    
+    if trange:
+        if not isinstance(trange,list):
+            trange = [trange]# Einzelwert zu Array machen
+        for x in trange:
+            a = x.split(' -')
+            tb.append(a[0].strip())
+            te.append(a[1].strip())
+    else:
+        if not isinstance(tbegin,list):
+            tb = [tbegin]# Einzelwert zu Array machen
+        if not isinstance(tend,list):
+            te = [tend]# Einzelwert zu Array machen
+    
+    i = 0
+    while i < len(tb):
+        s = doAverage(tb[i], te[i])
+        res.append(s)
+        i += 1
+    if len(res) == 1:
+        return res[0]# Bei nur einem Wert: kein Array
+    else:
+        return res
+
+trangeArrayTL=list(I_TL_time)
+trangeArrayFM=list(I_FM_time)
+trangeArrayOff=list(I_Offs_time)
+
+xtrangeArray = [
+              '28.07.2022 09:19:19 -28.07.2022 09:21:18 '
+                            
+            ]
+#trangeArray = I_TL_time
+
+x1 = getMassAverage(filename=dateiQMS,trange=trangeArrayTL )
+i = 0
+while i < len(x1):
+    print(i, 'Mass Avarage: ', x1[i])
+    i += 1
+print(x1)
+
+x2 = getMassAverage(filename=dateiQMS,trange=trangeArrayFM )
+i = 0
+while i < len(x2):
+    print(i, 'Mass Avarage: ', x2[i])
+    i += 1
+print(x2)
+
+x3 = getMassAverage(filename=dateiQMS,trange=trangeArrayOff)
+i = 0
+while i < len(x3):
+    print(i, 'Mass Avarage: ', x3[i])
+    i += 1
+print(x3)
+I_TL=np.array(x1)
+I_FM=np.array(x2)
+I_Offs=np.array(x3)
+
+########################################################################################################################################
+
+
+# Temperatur
+lis_T_fm = T_fm.tolist()
+lis_T_room = T_room.tolist()
+lis_T_tl1 = T_tl1.tolist()
+lis_T_tl2 = T_tl2.tolist()
+lis_T_tl3 = T_tl3.tolist()
+lis_T_tl4 = T_tl4.tolist()
+
+
+# Druck
+
+if gauge == 0.01 :
+    lis_p_offs_01 = p_offs_01.tolist()
+    lis_p_fill_01 = p_fill_01.tolist()
+    lis_p_offs_srg = p_offs_srg.tolist()
+    lis_p_fill_srg = p_fill_srg.tolist()
+    
+    
+    
+else:
+    lis_p_offs = p_offs.tolist()
+    lis_p_fill = p_fill.tolist()
+    
+    
+    
+
+
+
+lis_p_ig = p_ig.tolist()
+# I-QMS
+lis_I_TL_time = I_TL_time.tolist()
+lis_I_Offs_time = I_Offs_time.tolist()
+lis_I_FM_time = I_FM_time.tolist()
+# I-QMS
+lis_I_TL = I_TL.tolist()
+lis_I_Offs = I_Offs.tolist()
+lis_I_FM = I_FM.tolist()
+# Datum
+# Datum
+lis_datum = datum.tolist()
+lis_time = time.tolist()
+
+# Ventil
+lis_valve = Valve.tolist()
+
+
+datum_meas = lis_datum[0:1]
+
+
+
+
+if L == 1 :
+    #Leitwert
+    lis_c = L_ar.tolist()
+
+    # Steigung SZ
+    lis_m1 = m1.tolist()
+    lis_m2 = m2.tolist()
+    lis_m3 = m3.tolist()
+    lis_m4 = m4.tolist()
+
+    # Zeitpunkte
+    lis_t1 = t1.tolist()
+    lis_t2 = t2.tolist()
+    lis_t3 = t3.tolist()
+    lis_t4 = t4.tolist()
+
+    # Zeit pro SZ
+    lis_time1 = time1.tolist()
+    lis_time2 = time2.tolist()
+    lis_time3 = time3.tolist()
+
+    # Druck der SZ
+    lis_pmean = pmean.tolist()
+    lis_pmin = pmin.tolist()
+    lis_pmax= pmax.tolist()
+
+    # Druck der SZ
+    lis_h = h.tolist()
+    
+    
+    doc["Calibration"]["Measurement"]["Values"]={"Temperature": [{"Unit": "C","Type": "T-FM","Comment":"Temperatur T ","Value": lis_T_fm},
+                                                                {"Unit": "C","Type": "T-Room","Comment":"Temperatur T","Value": lis_T_room},
+                                                                {"Unit": "C","Type": "T-TL1","Comment":"Temperatur T","Value": lis_T_tl1},
+                                                               {"Unit": "C","Type": "T-TL2","Comment":"Temperatur T","Value":lis_T_tl2},
+                                                               {"Unit": "C","Type": "T-TL2","Comment":"Temperatur T","Value":lis_T_tl3},
+                                                               {"Unit": "C","Type": "T-TL3","Comment":"Temperatur T","Value": lis_T_tl4}],
+                                                "Pressure": [{"Unit": "Pa","Type": "Offset pressure","Value":lis_p_offs},
+                                                             {"Unit": "Pa","Type": "pressure mean","Value":lis_p_fill},
+                                                             {"Unit": "bar","Type": "TL1 pressure ","Value":lis_p_ig}],
+                                                "Date": [{"Unit": "year-month-day","Type": "Datum","Value":lis_datum},
+                                                             {"Unit": "hh:mm:ss","Type": "Messzeit","Value":lis_time}],
+                                                "Valve": [{"Unit": "1","Type": "Connection", "Comment":"Connection of the leak" ,"Value":lis_valve}],
+                                                "Current": [{"Unit": "mbar","Type": "I-TL","Value": lis_I_TL},
+                                                          {"Unit": "mbar","Type": "I-FM","Value": lis_I_FM}, 
+                                                          {"Unit": "mbar","Type": "I-Offs","Value": lis_I_Offs}],
+                                                                                         
+                                               "CurrentTime": [{"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-TL","Value": lis_I_TL_time},
+                                                          {"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-FM","Value": lis_I_FM_time}, 
+                                                         {"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-Offs","Value": lis_I_Offs_time}]
+                                               
+                                     }
+    doc["Calibration"]["Measurement"]["Date"]=[{"Type": "measurement","Value": datum_meas}]
+
+    doc["Calibration"]["Measurement"]["Values"]["Conductance"]={"t": [{"Unit": "s","Type": "t1","Comment":"Zeitpunkt t1 des 1.SZ","Value": lis_t1},
+                                                                            {"Unit": "s","Type": "t2","Comment":"Zeitpunkt t2 des 2.SZ","Value": lis_t2}, 
+                                                                            {"Unit": "s","Type": "t3","Comment":"Zeitpunkt t3 des 3.SZ","Value": lis_t3},
+                                                                           {"Unit": "s","Type": "t4","Comment":"Zeitpunkt t4 des 4.SZ","Value": lis_t4}],
+                                                                "time": [{"Unit": "s","Type": "time1","Comment":"Zeit t2-t1 von SZ","Value": lis_time1},
+                                                                       {"Unit": "s","Type": "time2","Comment":"Zeit t3-t2 von SZ","Value": lis_time2}, 
+                                                                      {"Unit": "s","Type": "time3","Comment":"Zeit t4-t3 von SZ","Value": lis_time3}],
+                                                                "m": [{"Unit": "Pa/s","Type": "m1","Comment":"Steigung m1 des 1.SZ","Value": lis_m1},
+                                                                       {"Unit": "Pa/s","Type": "m2","Comment":"Steigung m1 des 2.SZ","Value": lis_m2}, 
+                                                                      {"Unit": "Pa/s","Type": "m3","Comment":"Steigung m1 des 3.SZ","Value": lis_m3},
+                                                                       {"Unit": "Pa/s","Type": "m3","Comment":"Steigung m1 des 4.SZ","Value": lis_m3}],
+                                                               "pressure": [{"Unit": "Pa","Type": "pmean","Comment":"Mittelwert von p","Value": lis_pmean},
+                                                                      {"Unit": "Pa","Type": "pmin","Comment":"p_min des SZ","Value": lis_pmin}, 
+                                                                      {"Unit": "Pa","Type": "pmax","Comment":"p_max des SZ","Value": lis_pmax}],
+                                                               "l": [{"Unit": "mm","Type": "l","Comment":"Hub des Verdrängers","Value": lis_h}],
+                                                               "C": [{"Unit": "m^3/s","Type": "Constanter Leitwert ","Value": lis_c}]
+                                                               
+                                                                }
+
+
+
+    
+    
+    print("Constantes Volumen")
+    
+                               
+                                                                
+else:
+    
+    lis_c = L_ar.tolist()
+    if gauge == 0.01 :
+        doc["Calibration"]["Measurement"]["Values"]={"Temperature": [{"Unit": "C","Type": "T-FM ","Comment":"Temperatur T ","Value": lis_T_fm},
+                                                                    {"Unit": "C","Type": "T-Room","Comment":"Temperatur T","Value": lis_T_room},
+                                                                    {"Unit": "C","Type": "T-TL1","Comment":"Temperatur T","Value": lis_T_tl1},
+                                                                   {"Unit": "C","Type": "T-TL2","Comment":"Temperatur T","Value":lis_T_tl2},
+                                                                   {"Unit": "C","Type": "T-TL2","Comment":"Temperatur T","Value":lis_T_tl3},
+                                                                   {"Unit": "C","Type": "T-TL3","Comment":"Temperatur T","Value": lis_T_tl4}],
+                                                    "Pressure": [{"Unit": "DCR","Type": "Offset pressure SRG","Value":lis_p_offs_srg},
+                                                                 {"Unit": "DCR","Type": "Fill pressure SRG ","Value":lis_p_fill_srg},
+                                                                 {"Unit": "Pa","Type": "Offset pressure 01Torr","Value":lis_p_offs_01},
+                                                                 {"Unit": "Pa","Type": "Fill pressure 01Torr","Value":lis_p_fill_01},
+                                                                 {"Unit": "mbar","Type": "TL1 pressure ","Value":lis_p_ig}],
+                                                    "Date": [{"Unit": "year-month-day","Type": "Datum","Value":lis_datum},
+                                                                 {"Unit": "hh:mm:ss","Type": "Messzeit","Value":lis_time}],
+                                                    "Valve": [{"Unit": "1","Type": "Connection", "Comment":"Connection of the leak" ,"Value":lis_valve}],
+                                                    "Current": [{"Unit": "mbar","Type": "I-TL","Value": lis_I_TL},
+                                                              {"Unit": "mbar","Type": "I-FM","Value": lis_I_FM}, 
+                                                              {"Unit": "mbar","Type": "I-Offs","Value": lis_I_Offs}],
+                                                                                             
+                                                   "CurrentTime": [{"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-TL","Value": lis_I_TL_time},
+                                                              {"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-FM","Value": lis_I_FM_time}, 
+                                                             {"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-Offs","Value": lis_I_Offs_time}]
+                                                   }
+        print("SRG")
+        
+    else:
+        doc["Calibration"]["Measurement"]["Values"]={"Temperature": [{"Unit": "C","Type": "T-FM","Comment":"Temperatur T ","Value": lis_T_fm},
+                                                                    {"Unit": "C","Type": "T-Room","Comment":"Temperatur T","Value": lis_T_room},
+                                                                    {"Unit": "C","Type": "T-TL1","Comment":"Temperatur T","Value": lis_T_tl1},
+                                                                   {"Unit": "C","Type": "T-TL2","Comment":"Temperatur T","Value":lis_T_tl2},
+                                                                   {"Unit": "C","Type": "T-TL2","Comment":"Temperatur T","Value":lis_T_tl3},
+                                                                   {"Unit": "C","Type": "T-TL3","Comment":"Temperatur T","Value": lis_T_tl4}],
+                                                    "Pressure": [{"Unit": "Pa","Type": "Offset pressure","Value":lis_p_offs},
+                                                                 {"Unit": "Pa","Type": " pressure fill","Value":lis_p_fill},
+                                                                
+                                                                 {"Unit": "mbar","Type": "TL1 pressure","Value":lis_p_ig}],
+                                                    "Date": [{"Unit": "year-month-day","Type": "Datum","Value":lis_datum},
+                                                                 {"Unit": "hh:mm:ss","Type": "Messzeit","Value":lis_time}],
+                                                    "Valve": [{"Unit": "1","Type": "Connection", "Comment":"Connection of the leak" ,"Value":lis_valve}],
+                                                    "Current": [{"Unit": "mbar","Type": "I-TL","Value": lis_I_TL},
+                                                              {"Unit": "mbar","Type": "I-FM","Value": lis_I_FM}, 
+                                                              {"Unit": "mbar","Type": "I-Offs","Value": lis_I_Offs}],
+                                                                                             
+                                                   "CurrentTime": [{"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-TL","Value": lis_I_TL_time},
+                                                              {"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-FM","Value": lis_I_FM_time}, 
+                                                             {"Unit": "dd.mm.yy hh:mm:ss -dd.mm.yy hh:mm:ss","Type": "I-Offs","Value": lis_I_Offs_time}]
+                                                   }
+        doc["Calibration"]["Measurement"]["Values"]["Conductance"]={  "C": [{"Unit": "m^3/s","Type": "Constanter Leitwert","Value": lis_c}]}
+    print("Constanter Leitwert")
+    
+                                                            
+    
+        
+    
+    
+    
+doc["Calibration"]["Measurement"]["Date"]=[{"Type": "measurement","Value": datum_meas}]
+
+
+    
+
+
+
+lis_mass_no = mass_no.tolist()[0]
+lis_mass_value = mass_value.tolist()
+lis_mass_value_offs = mass_value_offs.tolist()[0]
+
+
+
+
+key_value=dict(zip(def_key, def_value))
+key_value_offs=dict(zip(def_key_offs, def_value_offs))
+
+
+
+doc["Calibration"]["Measurement"]["AuxValues"]={"ScanQMS": [{"Unit": "Mass","Type": "QMS","Comment":"Masse ","Value":lis_mass_no},
+                                                            {"Unit": "mbar","Type": "Current","Comment":"Wert / Masse","Value": lis_mass_value},
+                                                            {"Unit": "mbar","Type": "Current Offset","Comment":"Wert / Masse","Value": lis_mass_value_offs}],
+                                                "DefQMS": [{"Type": "Scan QMS","Value":key_value},
+                                                           {"Type": "Scan Offset QMS","Value": key_value_offs}]}
+
+
+#doc["Calibration"]["Measurement"]["AuxValues"]={"ScanQMS": [{"Unit": "Mass","Type": "QMS ","Comment":"Masse ","Value":lis_mass_no},
+#                                                            {"Unit": "mbar","Type": "Current","Comment":"Wert / Masse","Value": lis_mass_value},
+##                                                            {"Unit": "mbar","Type": "Current Offset","Comment":"Wert / Masse","Value": lis_mass_value_offs}],
+#                                                "DefQMS": [{"Type": "Scan QMS ","Value":key_value},
+#                                                           {"Type": "Scan Offset QMS","Value": key_value_offs}]}
+
+#db.save(doc)
+
+content=pathlib.Path('Scan.pdf').read_bytes() 
+
+db.put_attachment(doc, content, "Scan.pdf" , content_type="'application/pdf")
+
+
+
+
-- 
GitLab