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

start with save results

parent 9ab309c3
No related branches found
No related tags found
No related merge requests found
......@@ -153,6 +153,9 @@ class Anselm(System):
def end_task(self, line):
self.add_widget_to_grid(self.make_result_label(line = line), line, self.result_col)
if self.aget('save', 0) == "yes":
self.db.save_results()
self.log.info("end task at line {}".format(line))
......@@ -351,7 +354,7 @@ class Anselm(System):
def cal_id_selected(self, combo, line):
cal_id = combo.currentText()
self.aset('calid', line, cal_id)
self.aset('cal_id', line, cal_id)
self.log.info("select calibration id {}".format( cal_id ))
def fullscale_selected(self, combo, line):
......
......@@ -114,6 +114,11 @@ class DB(System):
self.log.error("document with id: {} does not exist".format(id))
return None
def set_doc(self, doc):
self.log.info("try to save document")
res = self.db.save(doc)
self.log.info(res)
def replace_defaults(self, task, defaults):
strtask = json.dumps(task)
if isinstance(defaults, dict):
......@@ -157,4 +162,28 @@ class DB(System):
self.aset('task', line, task)
self.aset('task_db', line, task_db)
else:
self.log.error("line {} contains no doc_id")
\ No newline at end of file
self.log.error("line {} contains no doc_id")
def save_results(self):
cal_keys = self.r.keys("cal_id@*")
for cal_key in cal_keys:
_, line = cal_key.split(self.keysep)
doc_path = self.aget("doc_path", line)
results = self.dget("result", line)
self.log.debug("try to save results: {}".format(results))
if doc_path and results:
doc_path_array = doc_path.split(".")
cal_id = self.aget("cal_id", line)
doc = self.get_doc(cal_id)
for result in results:
self.log.debug("save components are cal_id {}, doc_path_array: {}, result: {}".format(cal_id, doc_path_array, result))
self.doc_write_result(doc, doc_path_array, result)
self.set_doc(doc)
def doc_write_result(self, doc, doc_path_array, result):
for key in doc_path_array[:-1]:
doc = doc.setdefault(key, {})
if not doc_path_array[-1] in doc:
doc[doc_path_array[-1]] = []
doc[doc_path_array[-1]].append(result)
......@@ -48,6 +48,9 @@ class Worker(System):
req = requests.post(self.relay_url, data=json.dumps(task), headers = self.headers)
res = req.json()
if 'DocPath' in task:
self.aset('doc_path', line, task['DocPath'], expire=False)
if 'Result' in res:
self.aset('result', line, res['Result'], expire=False)
......
......@@ -22,14 +22,14 @@ def home():
@app.route('/cal_ids')
def calids():
keys = s.r.keys('calid@*')
calids = []
keys = s.r.keys('cal_id@*')
cal_ids = []
for key in keys:
calids.append(s.r.get(key))
cal_ids.append(s.r.get(key))
s.log.info("request cal ids")
return jsonify({"ids":calids })
return jsonify({"ids":cal_ids })
@app.route('/dut_max', methods=['GET'])
def dut_max():
......@@ -89,7 +89,7 @@ def dut_max():
@app.route('/target_pressures', methods=['GET'])
def target_pressure():
s.log.info("request to target pressures")
keys = s.r.keys('calid@*')
keys = s.r.keys('cal_id@*')
target_pressure_values = []
res = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment