Skip to content
Snippets Groups Projects
Commit f020cfcf authored by wactbprot's avatar wactbprot
Browse files

endpoints / and /target_pressures

parent 78ccb68a
No related branches found
No related tags found
No related merge requests found
......@@ -25,18 +25,18 @@ class Observe(QThread, System):
class Anselm(System):
fullscale_list = [
{"Unit":"mbar", "Display":"SRG" , "Value":0.02},
{"Unit":"mbar", "Display":"0.1mbar" , "Value":0.1},
{"Unit":"mbar", "Display":"0.25mbar", "Value":0.25},
{"Unit":"mbar", "Display":"1mbar" , "Value":1.0},
{"Unit":"mbar", "Display":"10mbar" , "Value":10.0},
{"Unit":"mbar", "Display":"100mbar" , "Value":100.0},
{"Unit":"mbar", "Display":"1000mbar", "Value":1000.0},
{"Unit":"mbar", "Display":"0.1Torr" , "Value":0.133},
{"Unit":"mbar", "Display":"1Torr" , "Value":1.33},
{"Unit":"mbar", "Display":"10Torr" , "Value":13.3},
{"Unit":"mbar", "Display":"100Torr" , "Value":133.0},
{"Unit":"mbar", "Display":"1000Torr", "Value":1330.0},
{"Unit":"Pa", "Display":"SRG" , "Value":2.0},
{"Unit":"Pa", "Display":"0.1mbar" , "Value":10.0},
{"Unit":"Pa", "Display":"0.25mbar", "Value":25.0},
{"Unit":"Pa", "Display":"1mbar" , "Value":100},
{"Unit":"Pa", "Display":"10mbar" , "Value":1000.0},
{"Unit":"Pa", "Display":"100mbar" , "Value":10000.},
{"Unit":"Pa", "Display":"1000mbar", "Value":100000.0},
{"Unit":"Pa", "Display":"0.1Torr" , "Value":13.3},
{"Unit":"Pa", "Display":"1Torr" , "Value":133.0},
{"Unit":"Pa", "Display":"10Torr" , "Value":1330.0},
{"Unit":"Pa", "Display":"100Torr" , "Value":13300.0},
{"Unit":"Pa", "Display":"1000Torr", "Value":133000.0},
]
std_select = ["SE3", "CE3", "FRS5", "DKM_PPC4"]
year_select = ["2019", "2018", "2017"]
......
......@@ -86,14 +86,14 @@ class DB(System):
self.log.error("no doc with id {}".format(doc_id))
return []
def get_auxobj(self, id):
def get_doc(self, id):
doc = self.db[id]
if doc:
return doc
else:
self.log.error("document with id: {} does not exist".format(id))
return None
def replace_defaults(self, task, defaults):
strtask = json.dumps(task)
if isinstance(defaults, dict):
......
from flask import Flask, jsonify, request
from anselm.system import System
from anselm.db import DB
app = Flask(__name__)
s = System()
db = DB()
@app.route('/calids')
@app.route('/')
def home():
return jsonify({"routes":[
"/cal_ids",
"/dut_max",
"/target_pressures",
] })
@app.route('/cal_ids')
def calids():
keys = s.r.keys('calid@*')
calids = []
......@@ -20,25 +29,24 @@ def calids():
def dut_max():
s.log.info("request max values for dut branchs")
keys = s.r.keys('calid@*')
res = {
"Dut_A": {
"Value": 0.0,
"Type": "dut_max_a",
"Unit": "mbar"
"Unit": "Pa"
},
"Dut_B": {
"Value": 0.0,
"Type": "dut_max_b",
"Unit": "mbar"
"Unit": "Pa"
},
"Dut_C": {
"Value": 0.0,
"Type": "dut_max_c",
"Unit": "mbar"
"Unit": "Pa"
}
}
keys = s.r.keys('calid@*')
for key in keys:
calid = s.r.get(key)
_ , line = key.split(s.keysep)
......@@ -71,3 +79,57 @@ def dut_max():
return jsonify({'ToExchange':res})
else:
return jsonify(res)
@app.route('/target_pressures', methods=['GET'])
def target_pressure():
s.log.info("request to target pressures")
res = {
"Pressure_target": {
"Caption": "target pressure",
"Selected": "1",
"Select": []
}
}
keys = s.r.keys('calid@*')
target_pressure_values = []
target_pressure_unit = "Pa"
for key in keys:
calid = s.r.get(key)
caldoc = db.get_doc(calid)
todo_pressure = caldoc.get('Calibration', {}).get('ToDo',{}).get('Values',{}).get('Pressure')
if todo_pressure:
if todo_pressure.get('Unit') == "mbar":
conv_factor = 100
if todo_pressure.get('Unit') == "Pa":
conv_factor = 1
for v in todo_pressure.get('Value'):
val = float(v) * conv_factor
if not val in target_pressure_values:
target_pressure_values.append(val)
else:
s.log.warn("calibration {} contains no target pressures".format(calid))
if len(target_pressure_values) > 0:
first = True
for v in sorted(target_pressure_values):
formated_val = '{:.1e}'.format(v)
if first:
res['Pressure_target']['Selected'] = formated_val
first = False
res['Pressure_target']['Select'].append({'value':formated_val , 'display': "{} Pa".format( formated_val) })
else:
msg = "no target values found"
s.log.error(msg)
res['error'] = msg
if not 'error' in res:
return jsonify({'ToExchange':res})
else:
return jsonify(res)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment