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

detect measurement complete, anselm talks to bot channel

parent 5912f341
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@ class Bot(System):
MENTION_REGEX = "^<@(|[WU].+?)>(.*)"
RTM_READ_DELAY = 1
OUT_CHANNEL = "bot"
def __init__(self):
super().__init__()
channel_list = None
......@@ -30,7 +30,7 @@ class Bot(System):
if channel_list and 'channels' in channel_list:
for channel in channel_list.get('channels'):
if channel.get('name') == 'allgemein':
if channel.get('name') == 'bot':
self.log.info("git info channel id")
self.info_channel_id = channel.get('id')
break
......@@ -56,6 +56,10 @@ class Bot(System):
if command.startswith('ga'):
ok = True
self.post(channel, "calibration gas is {}".format(self.aget('gas',0)))
if command.startswith('ch'):
ok = True
self.post(channel, "I send my infos to channel #{}".format(self.OUT_CHANNEL))
if command.startswith('id'):
ok = True
......@@ -73,7 +77,7 @@ class Bot(System):
if command.startswith('he'):
ok = True
self.post(channel, "Available commands are *he[lp]* *ga[s]*, *fu[llscales]* or *id[s]*.")
self.post(channel, "Available commands are *he[lp]*, *ch[annel]*, *ga[s]*, *fu[llscales]* or *id[s]*.")
if not ok:
self.post(channel, "Not sure what you mean. Try *help* command.")
......
......@@ -53,7 +53,10 @@ def target_pressure():
lines = s.get_lines('cal_id')
todo_pressures_acc = []
repeat_over_rating = 7.0
continue_measurement = True
epsilon = 0.01
highest_rating = 0 # start value
for line in lines:
cal_id = s.aget('cal_id', line)
doc = db.get_doc(cal_id)
......@@ -70,42 +73,53 @@ def target_pressure():
last_unit = test_unit
# let's find next pressure
if highest_rating < repeat_over_rating:
for todo_pressure in todo_pressures_acc:
for todo_pressure in todo_pressures_acc:
if float(todo_pressure) > last_pressure:
break
point_no = todo_pressures_acc.index(todo_pressure) + 1
points_total = len(todo_pressures_acc)
measurement_complete = last_pressure/float(todo_pressures_acc[-1]) -1 < epsilon
if highest_rating < repeat_over_rating:
# next pressure with ok rating
next_pressure, next_unit = todo_pressure, todo_unit
if not measurement_complete:
continue_measurement = True
# next pressure with ok rating
next_pressure, next_unit = todo_pressure, todo_unit
s.r.publish('info', "The last measurement point has a rating of *{}* of [0..9]. This is ok.".format(highest_rating))
s.r.publish('info', "Next pressure point (No.: {} of {} in total) will be *{} {}*".format(point_no+1, points_total, next_pressure, next_unit))
else:
continue_measurement = False
s.r.publish('info', "The last measurement point has a rating of *{}* of [0..9]. This is ok.".format(highest_rating))
s.r.publish('info', "It was the *last measurement point*.")
s.r.publish('info', """
last measurement point has a rating of: *{}*. This is ok. Next pressure point will be *{} {}*
""".format(highest_rating, todo_pressure, todo_unit))
if highest_rating > repeat_over_rating:
s.r.publish('info', """
last measurement point has a rating of *{}*. This is *not ok*. Repeat last pressure point *{} {}*
""".format(highest_rating, todo_pressure, todo_unit))
continue_measurement = True
# next pressure with ok rating not ok
next_pressure, next_unit = last_pressure, last_unit
if 'DocPath' in req:
doc_path = req.get('DocPath')
for line in lines:
s.aset("result", line, [{'Type':'target_pressure', 'Value': float(next_pressure), 'Unit':next_unit}])
s.aset("doc_path", line, doc_path)
db.save_results()
else:
msg = "missing DocPath"
res['error'] = msg
s.log.error(msg)
s.aset('save', 0, "no" )
s.log.info("check calibration {}".format(cal_id))
s.r.publish('info', "The last measurement point has a rating of *{}*. This is *not ok*.".format(highest_rating))
s.r.publish('info', "Repeat the last pressure point (No.: {} of {} in total) *{} {}*.".format(point_no, points_total, next_pressure, next_unit))
return jsonify({'ToExchange':{'Target_pressure.Selected': float(next_pressure) , 'Target_pressure.Unit': next_unit }})
if continue_measurement:
if 'DocPath' in req:
doc_path = req.get('DocPath')
for line in lines:
s.aset("result", line, [{'Type':'target_pressure', 'Value': float(next_pressure), 'Unit':next_unit}])
s.aset("doc_path", line, doc_path)
db.save_results()
else:
msg = "missing DocPath"
res['error'] = msg
s.log.error(msg)
s.aset('save', 0, "no" )
return jsonify({'ToExchange':{'Target_pressure.Selected': float(next_pressure) , 'Target_pressure.Unit': next_unit , 'Continue_mesaurement.Bool': continue_measurement}})
else:
return jsonify({'ToExchange':{'Continue_mesaurement.Bool': continue_measurement}})
@app.route('/save_dut_branch', methods=['POST'])
def save_dut_branch():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment