コード例 #1
0
def channel_list():
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        request.values)

    chlModel = models.CustomChannel
    data_list = chlModel.query
    totalCount = data_list.count()

    # if columnName == 'name':
    #     orderObj = chlModel.name.asc() if sortOrder == 'asc' else chlModel.name.desc()
    # elif columnName == 'type':
    #     orderObj = chlModel.type.asc() if sortOrder == 'asc' else chlModel.type.desc()
    # else:
    #     orderObj = chlModel.id.asc() if sortOrder == 'asc' else chlModel.id.desc()

    orderObj = chlModel.id.asc()
    data_list = data_list.order_by(orderObj).offset(start).limit(length).all()
    selList = [{
        'id': data_list[ind].id,
        'ind': start + ind + 1,
        'name': data_list[ind].name,
        'type': data_list[ind].type,
        'options': data_list[ind].options
    } for ind in range(len(data_list))]

    return json.dumps(datatable_list(selList, totalCount, draw))
コード例 #2
0
def func_list():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)

    funcModel = models.ExecFunc
    totalCount = funcModel.query.count()
    data_list = funcModel.query.with_entities(funcModel.id, funcModel.group,
                                              funcModel.name, funcModel.desc)

    # if columnIndex == '1':
    #     orderObj = funcModel.group.asc() if sortOrder == 'asc' else funcModel.group.desc()
    # elif columnIndex == '2':
    #     orderObj = funcModel.name.asc() if sortOrder == 'asc' else funcModel.name.desc()
    # else:
    #     orderObj = funcModel.desc.asc() if sortOrder == 'asc' else funcModel.desc.desc()

    orderObj = funcModel.desc.asc()
    data_list = data_list.order_by(orderObj).offset(start).limit(length).all()
    selList = [{
        'id': data.id,
        'group': data.group,
        'name': data.name,
        'desc': data.desc
    } for data in data_list]

    return json.dumps(datatable_list(selList, totalCount, draw))
コード例 #3
0
def get_channel():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)

    selModbus = postData.get('selModbus')
    channels = models.ModbusChannel.query.filter_by(modbus_id=selModbus)
    totalCount = channels.count()

    channels = channels.offset(start).limit(length).all()
    data_list = []

    # mod_mem = Modbus_Memory()
    selModel = models.Modbus
    sel_ind = selModel.query.filter(selModel.id < selModbus).count()
    # modbus_chl = mod_mem.get_modbus_chl(sel_ind) modbus_chl[ind]
    ind = 0
    for channel in channels:
        optionArr = json.loads(channel.options)
        optionArr['id'] = channel.id
        optionArr['chl'] = "TRUE"
        optionArr['options'] = channel.options
        data_list.append(optionArr)

        ind += 1

    return json.dumps(datatable_list(data_list, totalCount, draw))
コード例 #4
0
def condgroup_list_setting():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)

    condgroupModel = models.ConditionGroup
    condgroups = condgroupModel.query.outerjoin(models.Control, condgroupModel.controlid == models.Control.id) \
        .with_entities(condgroupModel.id, condgroupModel.name, condgroupModel.controlid, condgroupModel.operator,
                       condgroupModel.reverse) \
        .add_columns(models.Control.name.label('control_name'))

    #beforeID = postData.get('beforeID')
    #if check_null(beforeID):
    #    condgroups = condgroups.filter(or_(condgroupModel.controlid == '0', condgroupModel.id == beforeID))
    #else :
    #    condgroups = condgroups.filter(condgroupModel.controlid == '0')
    condgroups = condgroups.filter(condgroupModel.controlid == '0')
    totalCount = condgroups.count()

    sortObj = condgroupModel.id.asc()
    condgroups = condgroups.order_by(sortObj).offset(start).limit(length).all()
    data_list = [{
        "id": condgroup[0],
        "name": condgroup[1],
        "controlid": condgroup[2],
        "operator": condgroup[3],
        "reverse": config.USE_FLAG[int(condgroup[4])],
        "control_name": condgroup[5],
        "ind": start + ind + 1,
        "valid": "TRUE"
    } for ind, condgroup in enumerate(condgroups)]

    return json.dumps(datatable_list(data_list, totalCount, draw))
コード例 #5
0
def alarm_list():
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        request.values)

    chlModel = models.Alarm
    data_list = chlModel.query
    totalCount = data_list.count()

    # if columnIndex == '2':
    #     orderObj = chlModel.category.asc() if sortOrder == 'asc' else chlModel.category.desc()
    # elif columnIndex == '3':
    #     orderObj = chlModel.name.asc() if sortOrder == 'asc' else chlModel.name.desc()
    # elif columnIndex == '4':
    #     orderObj = chlModel.confirm.asc() if sortOrder == 'asc' else chlModel.confirm.desc()
    # elif columnIndex == '5':
    #     orderObj = chlModel.type.asc() if sortOrder == 'asc' else chlModel.type.desc()
    # else:
    #     orderObj = chlModel.id.asc() if sortOrder == 'asc' else chlModel.id.desc()

    orderObj = chlModel.id.asc()
    data_list = data_list.order_by(orderObj).offset(start).limit(length).all()
    selList = [
        alarm_item(data_list[ind], start + ind + 1)
        for ind in range(len(data_list))
    ]

    return json.dumps(datatable_list(selList, totalCount, draw))
コード例 #6
0
def condition_list():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)

    data_list = []
    condModel = models.Condition
    conditions = condModel.query.outerjoin(models.ConditionGroup, models.ConditionGroup.id == condModel.condgroup) \
        .with_entities(condModel.id, condModel.name, condModel.type, condModel.use_flag, condModel.options,
                       condModel.condgroup) \
        .add_columns(models.ConditionGroup.name.label('condgroup_name'))

    beforeID = postData.get('beforeID')
    if check_null(beforeID):
        conditions = conditions.filter(
            or_(condModel.condgroup == '0', condModel.id == beforeID))

    totalCount = conditions.count()

    # if columnName == "use_flag":
    #     sortObj = condModel.use_flag.asc() if sortOrder == "asc" else condModel.use_flag.desc()
    # elif columnName == "name":
    #     sortObj = condModel.name.asc() if sortOrder == "asc" else condModel.name.desc()
    # elif columnName == "type":
    #     sortObj = condModel.type.asc() if sortOrder == "asc" else condModel.type.desc()
    # else:
    #     sortObj = condModel.id.asc() if sortOrder == "asc" else condModel.id.desc()

    sortObj = condModel.id.asc()
    conditions = conditions.order_by(sortObj).offset(start).limit(length).all()
    # validList = get_valid(LogicMemory.Const_Condition, start, length, const.uiSizeEval)
    for ind, condition in enumerate(conditions):
        result = {
            "id": condition[0],
            "name": condition[1],
            "type": condition[2],
            "use_flag": config.USE_FLAG_KR[int(condition[3])],
            "options": condition[4],
            "condgroup": condition[5],
            "condgroup_name": condition[6],
            "ind": start + ind + 1,
            # "valid": validList[ind],
            "valid": "TRUE"
        }

        settings = json.loads(result["options"])
        result.pop("options")
        for key, val in settings.items():
            result[key] = val

        result["desc"] = get_desc_str(result)
        result["type"] = config.VARIABLE_TYPE[result["type"]]
        for key, val in settings.items():
            result.pop(key)

        data_list.append(result)

    return json.dumps(datatable_list(data_list, totalCount, draw))
コード例 #7
0
def control_list():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)

    controlModel = models.Control
    controls = controlModel.query.outerjoin(models.Logic, models.Logic.logicid == controlModel.logicid) \
        .with_entities(controlModel.id, controlModel.name, controlModel.use_flag, controlModel.priority,
                       controlModel.mode) \
        .add_columns(models.Logic.name.label('logic_name'))

    beforeID = postData.get('beforeID')
    if check_null(beforeID):
        controls = controls.filter(
            or_(controlModel.logicid == '0', controlModel.id == beforeID))

    totalCount = controls.count()

    # if columnName == "useflag":
    #     sortObj = controlModel.use_flag.asc() if sortOrder == "asc" else controlModel.use_flag.desc()
    # elif columnName == "name":
    #     sortObj = controlModel.name.asc() if sortOrder == "asc" else controlModel.name.desc()
    # elif columnName == "priority":
    #     sortObj = controlModel.type.asc() if sortOrder == "asc" else controlModel.type.desc()
    # elif columnName == "mode1":
    #     sortObj = controlModel.mode.asc() if sortOrder == "asc" else controlModel.mode.desc()
    # else:
    #     sortObj = controlModel.id.asc() if sortOrder == "asc" else controlModel.id.desc()

    sortObj = controlModel.id.asc()
    controls = controls.order_by(sortObj).offset(start).limit(length).all()
    # validList = get_logic_mem(LogicMemory.Const_Control, start, length, const.uiSizeCtrl) validList[ind]
    data_list = [{
        "id": control[0],
        "name": control[1],
        "use_flag": control[2],
        "priority": control[3],
        "mode": control[4],
        "logic_name": control[5],
        "ind": start + ind + 1,
        "shm": "TRUE",
        'useflag': config.USE_FLAG_KR[int(control[2])],
        'mode1': config.USE_FLAG[int(control[4])]
    } for ind, control in enumerate(controls)]

    return json.dumps(datatable_list(data_list, totalCount, draw))
コード例 #8
0
def actgroup_list_setting():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)

    actgroupModel = models.ActionGroup
    actGroups = actgroupModel.query.outerjoin(models.Control, actgroupModel.controlid == models.Control.id) \
        .with_entities(actgroupModel.id, actgroupModel.name, actgroupModel.controlid, actgroupModel.mode,
                       actgroupModel.cnt) \
        .add_columns(models.Control.name.label('control_name'))

    #beforeID = postData.get('beforeID')
    #if check_null(beforeID):
    #    actGroups = actGroups.filter(or_(actgroupModel.controlid == '0', actgroupModel.id == beforeID))
    #else:
    #    actGroups = actGroups.filter(actgroupModel.controlid == '0')
    actGroups = actGroups.filter(actgroupModel.controlid == '0')

    totalCount = actGroups.count()

    # if columnName == "name":
    #     sortObj = actgroupModel.name.asc() if sortOrder == "asc" else actgroupModel.name.desc()
    # elif columnName == "mode":
    #     sortObj = actgroupModel.mode.asc() if sortOrder == "asc" else actgroupModel.mode.desc()
    # elif columnName == "cnt":
    #     sortObj = actgroupModel.cnt.asc() if sortOrder == "asc" else actgroupModel.cnt.desc()
    # else:
    #     sortObj = actgroupModel.id.asc() if sortOrder == "asc" else actgroupModel.id.desc()

    sortObj = actgroupModel.id.asc()
    actGroups = actGroups.order_by(sortObj).offset(start).limit(length).all()
    # validList = get_logic_mem(LogicMemory.Const_ActGroup, start, length, const.uiSizeActGrp) validList[ind]
    data_list = [{
        "id": condgroup[0],
        "name": condgroup[1],
        "mode": config.ACTION_GROUP_MODE[condgroup[3]],
        "cnt": condgroup[4],
        "control_name": condgroup[5],
        "ind": start + ind + 1,
        "mode1": condgroup[3],
        "run": "TRUE"
    } for ind, condgroup in enumerate(actGroups)]

    return json.dumps(datatable_list(data_list, totalCount, draw))
コード例 #9
0
def modbus_list():
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        request.values)
    cliModel = models.Modbus
    data_list = cliModel.query
    totalCount = data_list.count()

    # if columnName == 'type':
    #     orderObj = cliModel.type.asc() if sortOrder == 'asc' else cliModel.type.desc()
    # elif columnName == 'protocol':
    #     orderObj = cliModel.protocol.asc() if sortOrder == 'asc' else cliModel.protocol.desc()
    # else:
    #     orderObj = cliModel.id.asc() if sortOrder == 'asc' else cliModel.id.desc()

    orderObj = cliModel.id.asc()
    data_list = data_list.order_by(orderObj).offset(start).limit(length).all()
    selList = [
        modbus_item(data_list[ind], start + ind + 1)
        for ind in range(len(data_list))
    ]

    return json.dumps(datatable_list(selList, totalCount, draw))
コード例 #10
0
def recipe_list():
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        request.values)

    defModel = models.RecipeDef
    def_list = defModel.query
    totalCount = def_list.count()

    # if columnName == "name":
    #     sortObj = defModel.name.asc() if sortOrder == "asc" else defModel.name.desc()
    # else:
    #     sortObj = defModel.id.asc() if sortOrder == "asc" else defModel.id.desc()

    sortObj = defModel.id.asc()
    def_list = def_list.order_by(sortObj).offset(start).limit(length).all()
    selList = [{
        'id': def_list[ind].id,
        'ind': start + ind + 1,
        'name': def_list[ind].name
    } for ind in range(len(def_list))]

    return json.dumps(datatable_list(selList, totalCount, draw))
コード例 #11
0
def client_list():
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        request.values)
    cliModel = models.RemoteClient
    data_list = cliModel.query
    totalCount = data_list.count()

    # if columnName == 'name':
    #     orderObj = cliModel.name.asc() if sortOrder == 'asc' else cliModel.name.desc()
    # else:
    #     orderObj = cliModel.id.asc() if sortOrder == 'asc' else cliModel.id.desc()

    orderObj = cliModel.id.asc()
    data_list = data_list.order_by(orderObj).offset(start).limit(length).all()
    # rm_mem = RemoteDevice_Memory()
    # client_arr = rm_mem.get_remote_clients()
    client_arr = []
    selList = [
        client_item(data_list[ind], start + ind + 1, client_arr)
        for ind in range(len(data_list))
    ]

    return json.dumps(datatable_list(selList, totalCount, draw))
コード例 #12
0
def remote_list():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)
    # searchValue = postData.get('search[value]')

    remoteID = postData.get('variable_id')
    variable_type = postData.get('variable_type')
    variable1 = postData.get('variable').split('-')
    variableStr = "LOCAL." if variable1[
        0] == "local" else "REMOTE." + variable1[1] + "."

    totalCount = 0
    variable_type1 = config.VARIABLE_MATCH[variable_type]
    variableStr += variable_type1 + "."
    if variable_type1 == "DG":
        totalCount = const.uiSizeDigital
    elif variable_type1 == "AN":
        totalCount = const.uiSizeAnalog
    elif variable_type1 == "ST":
        totalCount = const.uiSizeString
    elif variable_type1 == "DT":
        totalCount = const.uiSizeDate
    elif variable_type1 == "TM":
        totalCount = const.uiSizeTime

    if start > totalCount:
        start = 0

    selList = []
    sortOrder = "asc"
    step = 1 if sortOrder == "asc" else -1
    end = start + length if sortOrder == "asc" else totalCount - start - length
    start = start if sortOrder == "asc" else totalCount - start - 1

    if end >= totalCount:
        end = totalCount
    elif end < 0:
        end = 0

    for i in range(start, end, step):
        itemStr = variable_type + "-" + str(i)
        selVar = models.Variable.query.filter_by(remote=remoteID).filter_by(
            type=itemStr).first()

        itemName = selVar.name if selVar and len(
            selVar.name) > 0 else config.VARIABLE_TYPE[
                variable_type.upper()] + str(i)
        itemUnit = selVar.unit if selVar else ''
        itemChk = selVar.use_flag if selVar else '0'
        itemDefault = selVar.defaults if selVar else ''
        selList.append({
            'id': i,
            'address': variableStr + str(i),
            'name': itemName,
            'chk': itemChk,
            'unit': itemUnit,
            'default': itemDefault
        })

    return json.dumps(datatable_list(selList, totalCount, draw))
コード例 #13
0
def variable_list():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)
    # searchValue = postData.get('search[value]')

    remoteID = postData.get('variable_id')
    variable_type = postData.get('variable_type')
    variable1 = postData.get('variable').split('-')
    variableStr = "LOCAL." if variable1[
        0] == "local" else "REMOTE." + variable1[1] + "."

    totalCount = 0
    variable_type1 = config.VARIABLE_MATCH[variable_type]
    variableStr += variable_type1 + "."
    if variable_type1 == "DG":
        totalCount = const.uiSizeDigital
    elif variable_type1 == "AN":
        totalCount = const.uiSizeAnalog
    elif variable_type1 == "ST":
        totalCount = const.uiSizeString
    elif variable_type1 == "DT":
        totalCount = const.uiSizeDate
    elif variable_type1 == "TM":
        totalCount = const.uiSizeTime

    if start > totalCount:
        start = 0

    selList = []
    sortOrder = "asc"
    step = 1 if sortOrder == "asc" else -1
    end = start + length if sortOrder == "asc" else totalCount - start - length
    start = start if sortOrder == "asc" else totalCount - start - 1

    if end >= totalCount:
        end = totalCount
    elif end < 0:
        end = 0

    if remoteID != '0':
        data_list_count = models.Variable.query.filter_by(
            remote=remoteID).filter_by(use_flag="1").filter(
                models.Variable.type.ilike('%' + variable_type + '%')).all()
        totalCount = len(data_list_count)

    orderObj = models.Variable.addr_id.asc()
    data_list = models.Variable.query.filter_by(remote=remoteID).filter_by(
        use_flag="1").filter(
            models.Variable.type.ilike('%' + variable_type + '%')).order_by(
                orderObj).offset(start).limit(length).all()

    if remoteID != '0':
        for i in range(len(data_list)):
            itemStr = variable_type + "-" + str(i)

            nameEnd = str(data_list[i].addr_id
                          ) if data_list[i].addr_id is not None else str(i)
            itemName = data_list[i].name if data_list[i] and len(
                data_list[i].name) > 0 else config.VARIABLE_TYPE[
                    variable_type.upper()] + nameEnd

            itemUnit = data_list[i].unit if data_list[i] else ''
            itemChk = data_list[i].use_flag if data_list[i] else '0'
            itemDefault = data_list[i].defaults if data_list[i] else ''

            adressEnd = str(data_list[i].addr_id
                            ) if data_list[i].addr_id is not None else str(i)
            selList.append({
                'id': i,
                'address': variableStr + adressEnd,
                'name': itemName,
                'chk': itemChk,
                'unit': itemUnit,
                'default': itemDefault,
                'addr_id': data_list[i].addr_id,
                'remote_id': remoteID
            })
    else:
        for i in range(start, end, step):
            itemStr = variable_type + "-" + str(i)
            selVar = models.Variable.query.filter_by(
                remote=remoteID).filter_by(type=itemStr).first()

            itemName = selVar.name if selVar and len(
                selVar.name) > 0 else config.VARIABLE_TYPE[
                    variable_type.upper()] + str(i)
            itemUnit = selVar.unit if selVar else ''
            itemChk = selVar.use_flag if selVar else '0'
            itemDefault = selVar.defaults if selVar else ''
            selList.append({
                'id': i,
                'address': variableStr + str(i),
                'name': itemName,
                'chk': itemChk,
                'unit': itemUnit,
                'default': itemDefault,
                'remote_id': remoteID,
                'addr_id': str(i)
            })

    return json.dumps(datatable_list(selList, totalCount, draw))
コード例 #14
0
def action_list():
    postData = request.values
    draw, start, length, columnIndex, columnName, sortOrder = datatable_head(
        postData)

    data_list = []
    actionModel = models.Action
    actions = actionModel.query.outerjoin(models.ActionGroup, models.ActionGroup.id == actionModel.actgroup) \
        .with_entities(actionModel.id, actionModel.name, actionModel.type, actionModel.use_flag, actionModel.options,
                       actionModel.order, actionModel.actgroup) \
        .add_columns(models.ActionGroup.name.label('actgroup_name'))

    beforeID = postData.get('beforeID')
    if check_null(beforeID):
        actions = actions.filter(
            or_(actionModel.actgroup == '0', actionModel.id == beforeID))

    totalCount = actions.count()

    # if columnName == "use_flag":
    #     sortObj = actionModel.use_flag.asc() if sortOrder == "asc" else actionModel.use_flag.desc()
    # elif columnName == "name":
    #     sortObj = actionModel.name.asc() if sortOrder == "asc" else actionModel.name.desc()
    # elif columnName == "type":
    #     sortObj = actionModel.type.asc() if sortOrder == "asc" else actionModel.type.desc()
    # elif columnName == "order":
    #     sortObj = actionModel.order.asc() if sortOrder == "asc" else actionModel.order.desc()
    # else:
    #     sortObj = actionModel.id.asc() if sortOrder == "asc" else actionModel.id.desc()

    sortObj = actionModel.id.asc()
    actions = actions.order_by(sortObj).offset(start).limit(length).all()
    # validList = get_logic_mem(LogicMemory.Const_Action, start, length, const.uiSizeAct)
    for ind, action in enumerate(actions):
        result = {
            "id": action[0],
            "name": action[1],
            "type": action[2],
            "use_flag": config.USE_FLAG_KR[int(action[3])],
            "options": action[4],
            "order": action[5],
            "actgroup": action[6],
            "actgroup_name": action[7],
            "ind": start + ind + 1,
            # "shm": validList[ind]
            "shm": {
                'status': '',
                'busy': False,
                'done': False,
                'err': False
            }
        }

        settings = json.loads(result["options"])
        result.pop("options")
        for key, val in settings.items():
            result[key] = val

        result["desc"] = get_desc_str1(result)
        result["type"] = config.VARIABLE_TYPE[action[2]]
        for key, val in settings.items():
            result.pop(key)

        data_list.append(result)

    return json.dumps(datatable_list(data_list, totalCount, draw))