def remote(): remote_limit = uiSizeRemoteConn local_ip = '' local_port = '5000' local_use = '0' selServer = models.LocalServer.query.first() if selServer: local_ip = selServer.ip_addr local_port = selServer.port_addr local_use = selServer.use_flag # rm_mem = RemoteDevice_Memory() # local_data = rm_mem.get_local_status() selSet = models.Settings.query.filter_by(name='mode').first() mode = selSet.value local_data = {} if mode == 'run': print("run") else: print("stop") return render_template('communicate/remote.html', remote_limit=remote_limit, local_ip=local_ip, local_use=local_use, local_port=local_port, remotes=get_remotes(), local_data=local_data)
def condgroup(): alarms = models.Alarm.query.all() return render_template('logic_setting/condition_group.html', condgroup_limit=const.uiSizeEvalGrp, condition_limit=const.uiSizeEval, time_limit=const.uiSizeTimePeriod, alarms=alarms, remotes=get_remotes())
def action(): return render_template('logic_setting/action.html', remotes=get_remotes(), action_limit=const.uiSizeCtrl, channel_limit=const.uiSizeUserDefComm, frame_limit=const.uiSizeUserDefCommFrame, defLimit=const.uiSizeRecipeDef, recipeLimit=const.uiSizeRecipe, recipeVarLimit=const.uiSizeRecipeVars)
def recipe_panel(): return render_template('logic_setting/recipe.html', defLimit=const.uiSizeRecipeDef, remotes=get_remotes(), recipeLimit=const.uiSizeRecipe, recipeVarLimit=const.uiSizeRecipeVars)
def condition(): return render_template('logic_setting/condition.html', remotes=get_remotes(), condition_limit=const.uiSizeEval, time_limit=const.uiSizeTimePeriod)
def variable(): return render_template('logic_setting/variable.html', remotes=get_remotes())
def collect(): setting = models.CollectSet.query.filter_by(name='data_set').first() return render_template('data_set/collect.html', remotes=get_remotes(), setting=setting)
def alarm(): setting = models.CollectSet.query.filter_by(name='alarm_set').first() return render_template('data_set/alarm.html', remotes=get_remotes(), alarm_limit=uiSizeAlarm, setting=setting)
def logic(selid='000'): if selid != '': selLogic = models.Logic.query.filter_by(logicid=selid).first() if selLogic: controlModel = models.Control controls = controlModel.query.filter_by(logicid=selid).order_by( cast(controlModel.ind, Integer)).all() data_list = [] for selControl in controls: selCondGroup = models.ConditionGroup.query.filter_by( controlid=selControl.id).first() selActGroup = models.ActionGroup.query.filter_by( controlid=selControl.id).first() if selCondGroup: cond_page_list = condition_page_modal_list(selCondGroup.id) selCondGroup = { 'id': selCondGroup.id, 'name': selCondGroup.name, 'options': selCondGroup.options } else: cond_page_list = [] selCondGroup = {'id': 0, 'name': '조건그룹', 'options': ''} if selActGroup: act_page_list = act_page_modal_list(selActGroup.id) selActGroup = { 'id': selActGroup.id, 'name': selActGroup.name, 'options': selActGroup.options, 'mode': config.ACTION_GROUP_MODE[selActGroup.mode] } else: act_page_list = [] selActGroup = { 'id': 0, 'name': '동작그룹', 'mode': '', 'options': '' } data_list.append({ 'control': { 'name': selControl.name, 'use_flag': config.USE_FLAG_KR[int(selControl.use_flag)], 'options': selControl.options, 'priority': selControl.priority, 'id': selControl.id }, 'condgroup': selCondGroup, 'cond_page_list': cond_page_list, 'actgroup': selActGroup, 'act_page_list': act_page_list }) alarms = models.Alarm.query.all() logic_mem = LogicMemory.SharedMem_Logic() start_val = controlModel.query.filter( controlModel.id < selid).count() # validList = logic_mem.get_buff(LogicMemory.Const_Logic, start_val, start_val + 1) validList[0]['val'] return render_template('logic_build/logic.html', logic=selLogic, controls=data_list, control_limit=const.uiSizeCtrl, condgroup_limit=const.uiSizeEvalGrp, actgroup_limit=const.uiSizeActGrp, action_limit=const.uiSizeAct, condition_limit=const.uiSizeEval, time_limit=const.uiSizeTimePeriod, alarms=alarms, remotes=get_remotes(), priority="5", selid=selid) else: return redirect('/') else: return redirect('/')
def detail(selid='000'): if selid != '': selMonitor = models.Monitor.query.filter_by(monitor_id=selid).first() if selMonitor: collectModel = models.DataCollect variable_list = collectModel.query.filter( collectModel.options.ilike('%analog-%')).all() image_list = models.Upload.query.filter_by( userid=session.get('user_id')).all() element_list = models.MonitorElement.query.filter_by(monitorid=selid)\ .order_by(cast(models.MonitorElement.ind, Integer)).all() for element in element_list: if element.type in ['read_val', 'set_val', 'table']: element = element.__dict__ size_options = element['sizeoptions'] element.pop('sizeoptions') options = json.loads(element['options']) element['unit'] = "" if element['type'] in ['read_val', 'set_val']: if ('set_val_variable_seltype' in options or 'read_val_variable_seltype' in options): if ('set_val_variable_seltype' in options): variable_type = options[ 'set_val_variable_selid'].split('-')[0] _key_value = 'set_val' else: variable_type = options[ 'read_val_variable_selid'].split('-')[0] _key_value = 'read_val' if (variable_type == 'analog'): variable_remote = options[ _key_value + '_variable_seltype'].split('-')[1] unit_row = models.Variable.query.filter( models.Variable.remote == variable_remote, models.Variable.type == options[ _key_value + '_variable_selid']).first() if (unit_row is not None): element['unit'] = unit_row.unit else: element['unit'] = '' if len(size_options) > 0: optArr = json.loads(size_options) element['width'] = str(optArr['selWidth']) element['height'] = str(optArr['selHeight']) else: element['width'] = '' element['height'] = '' if element['type'] in ['read_val', 'set_val']: for key, val in options.items(): element[key] = val if key in [ 'read_digital_on', 'read_digital_off', 'read_digital_icon', 'set_digital_icon' ]: selImg = models.Upload.query.filter_by( id=val).first() element[ key + "_img"] = selImg.userid + '/' + selImg.url if selImg else "" # var_arr = element[element['type'] + '_variable_seltype'].split('-') # type_arr = element[element['type'] + '_variable_selid'].split('-') # local_shm = SharedMem_LocalVar(var_arr[0]) # data_list = local_shm.get_buff(type_arr[0], int(type_arr[1]), int(type_arr[1]) + 1, # int(var_arr[1])) # element['shm_val'] = data_list[0]['val'] # # if type_arr[0] == 'analog': # selItem = models.Variable.query.filter_by(remote=var_arr[1]).filter_by( # type=type_arr[0]).first() # unit_val = selItem.unit if selItem else "" # else: # unit_val = "" # # element['unit'] = unit_val element['shm_val'] = '21.5' elif element['type'] == 'table': for key, val in options.items(): if 'row-' in key or 'column-' in key: element[key] = val elif key == "max-row" or key == "max-column": element[key] = int(val) elif '-selid' in key or '-seltype' in key: element[key] = val for ind in range(element["max-row"]): for ind1 in range(element["max-column"]): indStr = 'table-' + str(ind) + "-" + str(ind1) # var_arr = element[indStr + '-seltype'].split('-') # type_arr = element[indStr + '-selid'].split('-') # local_shm = SharedMem_LocalVar(var_arr[0]) # data_list = local_shm.get_buff(type_arr[0], int(type_arr[1]), int(type_arr[1]) + 1, # int(var_arr[1])) # element[indStr] = data_list[0]['val'] element[indStr] = '21.5' return render_template('monitor/detail.html', selMonitor=selMonitor, variable_list=variable_list, image_list=image_list, element_list=element_list, remotes=get_remotes(), selid=selid) else: return redirect('/') else: return redirect('/')