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

save_dut endpoint, / json home with method and data to post

parent 7c0a4e16
No related branches found
No related tags found
No related merge requests found
...@@ -40,12 +40,17 @@ install and run ...@@ -40,12 +40,17 @@ install and run
> >
> ./anselm.sh & ./srv.sh > ./anselm.sh & ./srv.sh
relayServer curl
=========== ====
.. code-block:: shell .. code-block:: shell
curl -d '{"Action":"HTTP","Url":"http://localhost:50005/dut_max"}' http://localhost:55555 curl http://localhost:50005/dut_max
curl -d '{"Action":"HTTP","Url":"http://localhost:50005/target_pressures"}' http://localhost:55555 curl http://localhost:50005/target_pressures
curl -d '{"Action":"HTTP","Url":"http://localhost:50005/offset_sequences"}' http://localhost:55555 curl http://localhost:50005/offset_sequences
\ No newline at end of file curl -H "Content-Type: application/json" -d '{"Target_pressure_value":"1","Target_pressure_unit":"Pa"}' -X 'POST' http://localhost:50005/offset
curl -H "Content-Type: application/json" -d '{"Target_pressure_value":"1","Target_pressure_unit":"Pa"}' -X 'POST' http://localhost:50005/ind
curl -H "Content-Type: application/json" -d '{"DocPath":"Calibration.Measurement.AuxValues.Branch"}' -X 'POST' http://localhost:50005/save_dut
\ No newline at end of file
...@@ -68,11 +68,11 @@ class Anselm(System): ...@@ -68,11 +68,11 @@ class Anselm(System):
{"Unit":self.unit, "Display":"1000Torr", "Value":133000.0}, {"Unit":self.unit, "Display":"1000Torr", "Value":133000.0},
] ]
self.range_exprs = { self.range_exprs = {
'fullscale' :1, "fullscale" :1,
'fullscale/10' :0.1, "fullscale/10" :0.1,
'fullscale/100' :0.01, "fullscale/100" :0.01,
'fullscale/10000' :0.0001, "fullscale/10000" :0.0001,
'fullscale/100000' :0.00001 "fullscale/100000" :0.00001,
} }
self.db = DB() self.db = DB()
......
...@@ -12,15 +12,16 @@ db = DB() ...@@ -12,15 +12,16 @@ db = DB()
@app.route('/') @app.route('/')
def home(): def home():
return jsonify({"routes":[ return jsonify({"routes":[
"/cal_ids", {"route": "/cal_ids", "method":['GET']},
"/dut_max", {"route": "/dut_max","method":['GET']},
"/target_pressures", {"route": "/save_dut","method":['POST'],"data":['DocPath']},
"/offset_sequences" {"route": "/target_pressures","method":['GET']},
"/offset", {"route": "/offset_sequences","method":['GET','POST'],"data":['Target_pressure_value', "Target_pressure_unit"]},
"/ind" {"route": "/offset","method":['POST'],"data":['Target_pressure_value', "Target_pressure_unit"]},
{"route": "/ind","method":['POST'],"data":['Target_pressure_value', "Target_pressure_unit"]},
] }) ] })
@app.route('/cal_ids') @app.route('/cal_ids', methods=['GET'])
def calids(): def calids():
keys = s.get_keys('cal_id') keys = s.get_keys('cal_id')
cal_ids = [] cal_ids = []
...@@ -31,9 +32,28 @@ def calids(): ...@@ -31,9 +32,28 @@ def calids():
return jsonify({"ids":cal_ids }) return jsonify({"ids":cal_ids })
@app.route('/save_dut', methods=['POST'])
def save_dut():
s.log.info("request dut branch")
res = {"ok":True}
req = request.get_json()
if 'DocPath' in req:
doc_path = req.get('DocPath')
lines = s.get_lines("cal_id")
for line in lines:
s.aset("result", line, [s.aget("dut_branch", line)])
s.aset("doc_path", line, doc_path)
db.save_results()
else:
msg = "missing DocPath"
res['error'] = msg
s.log.error(msg)
return jsonify(res)
@app.route('/dut_max', methods=['GET']) @app.route('/dut_max', methods=['GET'])
def dut_max(): def dut_max():
s.log.info("request max values for dut branchs") s.log.info("request max values for dut branch")
res = { res = {
"Dut_A": { "Dut_A": {
...@@ -52,16 +72,13 @@ def dut_max(): ...@@ -52,16 +72,13 @@ def dut_max():
"Unit": s.unit "Unit": s.unit
} }
} }
keys = s.r.keys('calid@*') lines = s.get_lines('cal_id')
for key in keys: for line in lines:
calid = s.r.get(key)
_ , line = key.split(s.keysep)
fullscale_value = s.fget("fullscale_value", line) fullscale_value = s.fget("fullscale_value", line)
fullscale_unit = s.aget("fullscale_unit", line) fullscale_unit = s.aget("fullscale_unit", line)
dut_branch = s.aget("dut_branch", line) dut_branch = s.aget("dut_branch", line)
if calid and fullscale_value and dut_branch: if fullscale_value and dut_branch:
if dut_branch == "dut_a" and res.get('Dut_A').get('Value') < fullscale_value: if dut_branch == "dut_a" and res.get('Dut_A').get('Value') < fullscale_value:
res['Dut_A']['Value'] = fullscale_value res['Dut_A']['Value'] = fullscale_value
...@@ -76,7 +93,7 @@ def dut_max(): ...@@ -76,7 +93,7 @@ def dut_max():
res['Dut_C']['Unit'] = fullscale_unit res['Dut_C']['Unit'] = fullscale_unit
else: else:
msg = "missing setup for {}".format(calid) msg = "missing setup for line {}".format(line)
res['error'] = msg res['error'] = msg
s.log.error(msg) s.log.error(msg)
break break
...@@ -89,7 +106,7 @@ def dut_max(): ...@@ -89,7 +106,7 @@ def dut_max():
@app.route('/target_pressures', methods=['GET']) @app.route('/target_pressures', methods=['GET'])
def target_pressure(): def target_pressure():
s.log.info("request to target pressures") s.log.info("request to target pressures")
keys = s.r.keys('cal_id@*') keys = s.get_keys('cal_id')
target_pressure_values = [] target_pressure_values = []
res = { res = {
...@@ -145,10 +162,9 @@ def target_pressure(): ...@@ -145,10 +162,9 @@ def target_pressure():
@app.route('/offset_sequences', methods=['GET','POST']) @app.route('/offset_sequences', methods=['GET','POST'])
def offset_sequences(): def offset_sequences():
s.log.info("request to offset sequence") s.log.info("request to offset sequence")
keys = s.r.keys('offset_all_sequence@*') lines = s.get_lines('offset_all_sequence')
seq_array = [] seq_array = []
for key in keys: for line in lines:
_ , line = key.split(s.keysep)
sequence = s.dget('offset_all_sequence', line) sequence = s.dget('offset_all_sequence', line)
for task in sequence: for task in sequence:
seq_array.append("{}-{}".format(task.get('TaskName'), line)) seq_array.append("{}-{}".format(task.get('TaskName'), line))
...@@ -164,7 +180,6 @@ def offset(): ...@@ -164,7 +180,6 @@ def offset():
res = {"ok":True} res = {"ok":True}
s.log.info("request to endpoint /offset") s.log.info("request to endpoint /offset")
req = request.get_json() req = request.get_json()
s.log.debug("receive request with body {}".format(req)) s.log.debug("receive request with body {}".format(req))
if 'Target_pressure_value' in req and 'Target_pressure_unit' in req: if 'Target_pressure_value' in req and 'Target_pressure_unit' in req:
seq_array = [] seq_array = []
...@@ -172,7 +187,7 @@ def offset(): ...@@ -172,7 +187,7 @@ def offset():
target_unit = req.get('Target_pressure_unit') target_unit = req.get('Target_pressure_unit')
if target_unit == s.unit: if target_unit == s.unit:
fs_val_keys = s.r.keys('fullscale_value@*') fs_val_keys = s.get_keys('fullscale_value')
for key in fs_val_keys: for key in fs_val_keys:
_, line = key.split(s.keysep) _, line = key.split(s.keysep)
...@@ -183,8 +198,10 @@ def offset(): ...@@ -183,8 +198,10 @@ def offset():
auto_init_tasks = s.dget('auto_init_tasks', line) auto_init_tasks = s.dget('auto_init_tasks', line)
s.log.debug("found {} auto init tasks".format(len(auto_init_tasks))) s.log.debug("found {} auto init tasks".format(len(auto_init_tasks)))
offset_sequence = [] offset_sequence = []
for task in auto_init_tasks: for task in auto_init_tasks:
if 'From' in task and 'To' in task and target_value >= task.get('From') and target_value < task.get('To'): if 'From' in task and 'To' in task and target_value >= task.get('From') and target_value < task.get('To'):
s.log.debug("append for execution task: {} ".format(task)) s.log.debug("append for execution task: {} ".format(task))
offset_sequence.append(task) offset_sequence.append(task)
seq_array.append("{}-{}".format(task.get('TaskName'), line)) seq_array.append("{}-{}".format(task.get('TaskName'), line))
...@@ -241,16 +258,18 @@ def ind(): ...@@ -241,16 +258,18 @@ def ind():
if target_value < fullscale_value: if target_value < fullscale_value:
auto_init_tasks = s.dget('auto_init_tasks', line) auto_init_tasks = s.dget('auto_init_tasks', line)
s.log.debug("found {} auto init tasks".format(len(auto_init_tasks))) s.log.debug("found {} auto init tasks".format(len(auto_init_tasks)))
ind_sequence = [] ind_sequence = []
for task in auto_init_tasks: for task in auto_init_tasks:
if 'From' in task and 'To' in task and target_value >= task.get('From') and target_value < task.get('To'): if 'From' in task and 'To' in task and target_value >= task.get('From') and target_value < task.get('To'):
s.log.debug("append for execution task: {} ".format(task)) s.log.debug("append for execution task: {} ".format(task))
ind_sequence.append(task) ind_sequence.append(task)
seq_array.append("{}-{}".format(task.get('TaskName'), line)) seq_array.append("{}-{}".format(task.get('TaskName'), line))
# append the ind task # append the ind task
ind_task = s.dget("ind_task", line) ind_task = s.dget("ind_task", line)
if ind_task and 'TaskName' in task: if ind_task and 'TaskName' in task:
ind_task_name = ind_task.get('TaskName') ind_task_name = ind_task.get('TaskName')
ind_sequence.append(ind_task) ind_sequence.append(ind_task)
seq_array.append("{}-{}".format(ind_task_name, line)) seq_array.append("{}-{}".format(ind_task_name, line))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment