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

next: overwrite on len(Value) > 1

parent 99434d1b
No related branches found
No related tags found
No related merge requests found
......@@ -4,9 +4,10 @@ import json
from anselm.system import System # pylint: disable=E0611
from anselm.db import DB # pylint: disable=E0611
from anselm.worker import Worker # pylint: disable=E0611
from PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication, QPushButton, QComboBox, QGridLayout, QPlainTextEdit, QLabel, QLineEdit
from PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication, QPushButton
from PyQt5.QtWidgets import QComboBox, QGridLayout, QPlainTextEdit, QLabel, QLineEdit
from PyQt5.QtCore import QThread, pyqtSignal , Qt
import sys
class Observe(QThread, System):
signal = pyqtSignal('PyQt_PyObject')
......@@ -40,7 +41,7 @@ class Anselm(System):
cal_id_col = 2
fullscale_col = 3
dut_branch_col = 4
custobj_col = 5
devices_col = 5
task_col = 6
run_btn_col = 7
result_col= 1
......@@ -66,6 +67,14 @@ class Anselm(System):
{"Unit":self.unit, "Display":"100Torr" , "Value":13300.0},
{"Unit":self.unit, "Display":"1000Torr", "Value":133000.0},
]
self.range_exprs = {
'fullscale' :1,
'fullscale/10' :0.1,
'fullscale/100' :0.01,
'fullscale/10000' :0.0001,
'fullscale/100000' :0.00001
}
self.db = DB()
self.worker = Worker()
self.observer_thread = Observe()
......@@ -164,7 +173,7 @@ class Anselm(System):
line = self.current_grid_line
self.add_widget_to_grid(self.make_cal_id_combo(line = line), line, self.cal_id_col)
self.add_widget_to_grid(self.make_custobj_combo(line = line), line, self.custobj_col)
self.add_widget_to_grid(self.make_device_combo(line = line), line, self.devices_col)
self.add_widget_to_grid(self.make_fullscale_combo(line = line), line, self.fullscale_col)
self.add_widget_to_grid(self.make_dut_branch_combo(line = line), line, self.dut_branch_col)
self.add_widget_to_grid(self.make_result_label(line = line), line, self.result_col)
......@@ -230,55 +239,50 @@ class Anselm(System):
return c
def make_custobj_combo(self, line):
def make_device_combo(self, line):
cust_obj_ids = self.db.get_custobj_ids()
device_ids = self.db.get_device_ids()
self.log.debug("found following custobj ids {}".format(cust_obj_ids))
self.log.debug("found following devices ids {}".format(device_ids))
c = self.make_combo(cust_obj_ids, first_item="select read out device", last_item=False)
c.currentIndexChanged.connect(lambda: self.custobj_selected(c, line))
c = self.make_combo(device_ids, first_item="select read out device", last_item=False)
c.currentIndexChanged.connect(lambda: self.device_selected(c, line))
return c
def make_task_combo(self, doc_id, line):
ok = False
tasks = self.db.get_tasks(doc_id = doc_id)
self.log.debug("found {} tasks ".format(len(tasks)))
ok = self.evaluate_auto_tasks(tasks, line)
if tasks:
self.log.debug("found {} tasks ".format(len(tasks)))
ok = self.evaluate_auto_tasks(tasks, line)
if ok:
first_item = "tasks ok"
if ok:
first_item = "tasks ok"
c = self.make_combo([task.get('TaskName') for task in tasks], first_item=first_item, last_item=False)
c.currentIndexChanged.connect(lambda: self.task_selected(c, line))
else:
first_item = "task name problem"
c = self.make_combo([task.get('TaskName') for task in tasks], first_item=first_item, last_item=False)
else:
first_item = "task name problem"
c = self.make_combo([task.get('TaskName') for task in tasks], first_item=first_item, last_item=False)
c.currentIndexChanged.connect(lambda: self.task_selected(c, line))
c = self.make_combo([], first_item=first_item, last_item=False)
return c
def get_pressure_from_range_expr(self, range_expr, line):
value = None
unit = None
q = {
'@fullscale' :1,
'@fullscale/10' :0.1,
'@fullscale/100' :0.01,
'@fullscale/1000' :0.001,
'@fullscale/10000' :0.0001,
'@fullscale/100000' :0.00001
}
if range_expr in q:
value = self.fget("fullscale_value", line)*q[range_expr]
unit = self.aget("fullscale_unit", line)
self.log.debug("replaced {} {}".format(value, unit))
value = self.fget("fullscale_value", line)
unit = self.aget("fullscale_unit", line)
if unit and value and range_expr in self.range_exprs:
value = value * self.range_exprs[range_expr]
self.log.debug("found {} {}".format(value, unit))
return value, unit
else:
msg = "unknown range expression"
self.log.error(msg)
return value, unit
return None, None
def evaluate_auto_tasks(self, tasks, line):
offset_all_sequence = []
......@@ -333,7 +337,7 @@ class Anselm(System):
self.log.info("task with name {} selected at line {}".format(task_name, line))
def custobj_selected(self, combo, line):
def device_selected(self, combo, line):
doc_id = combo.currentText()
self.aset('doc_id', line, doc_id)
......
......@@ -2,9 +2,9 @@
"couchdb": {
"host": "localhost",
"port": 5984,
"database": "vl_db",
"database": "vl_db_work",
"view": {
"custobj": "share/CustomerObject",
"devices": "share/DeviceClass",
"calids": "share/Year_Standard-Type_Certificate_Issue"
}
},"redis":{
......
......@@ -32,14 +32,14 @@ class DB(System):
self.db.save(doc)
def get_custobj_ids(self):
view_con = self.db_dict.get('view').get('custobj')
def get_device_ids(self):
view_con = self.db_dict.get('view').get('devices')
try:
view = self.db.view(view_con)
res = [doc.get('id') for doc in view]
except Exception as inst:
self.log.error("cust view does not work: {}".format(inst))
res = ["dummy cust"]
self.log.error("device view does not work: {}".format(inst))
res = ["dummy device"]
self.log.warn("return dummy value")
return res
......@@ -67,6 +67,9 @@ class DB(System):
if 'CustomerObject' in doc:
red_doc = doc.get('CustomerObject')
if 'DeviceClass' in doc:
red_doc = doc.get('DeviceClass')
if 'CalibrationObject' in doc:
red_doc = doc.get('CalibrationObject')
else:
......@@ -95,6 +98,7 @@ class DB(System):
def get_task(self, doc_id, task_name):
doc = self.get_red_doc(doc_id)
if doc and 'Task' in doc:
tasks = doc.get('Task')
for task in tasks:
......@@ -170,20 +174,22 @@ class DB(System):
_, 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:
self.log.debug("try to save results: {}".format(results))
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, result))
self.doc_write_result(doc, doc_path, result)
self.log.debug("components are cal_id {}, doc_path_array: {}, result: {} saved".format(cal_id, doc_path, result))
self.adelete("result", line)
self.log.debug("deleted result of line {} from mem".format(line))
self.set_doc(doc)
def doc_write_result(self, doc, doc_path, result):
#
# last entry is something like Pressure (Type, Value and Unit)
# or (!) OperationKind
#
doc_path_array = doc_path.split(".")
last_entr = doc_path_array[-1]
......@@ -215,7 +221,6 @@ class DB(System):
if not found:
result = self.ensure_result_struct(result)
doc[last_entr].append(result)
else:
result = self.ensure_result_struct(result)
doc[last_entr] = result
......
......@@ -62,6 +62,11 @@ class System:
keys = self.get_keys(key_prefix)
return [key.split(self.keysep)[1] for key in keys]
def adelete(self, key_prefix, line):
k = self.gen_key(key_prefix, line)
self.r.delete(k)
def aset(self, key_prefix, line, value, expire=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment