Example #1
0
    def __init__(self):
        self.sqlcluster = SQLCluster('astuple')
        cp = ConfigParser.SafeConfigParser()
        cp.read('config\config.ini')
        cols_cnt = cp.get('table', 'cols_cnt')
        relation_table_name = cp.get('table', 'relation_table_name')
        cols_table_name = cp.get('table', 'cols_table_name')
        alarm_level_table = cp.get('table', 'alarm_level_table')
        tables = cols_table_name.split(',')
        logger.debug("tables %s" % tables)
        logger.debug('relation_table_name: %s' % relation_table_name)
        logger.debug('table cnt: %s' % cols_cnt)
        logger.debug('alarm_level_table: %s' % alarm_level_table)

        item = self.getTableNames(tables)
        logger.debug('item: %s' % item)

        self.arr = self.getList(item, 0)
        logger.debug('arr: %s' % self.arr)
        results = self.fetchRows(relation_table_name)
        logger.debug('result: %s' % results)

        levels = self.fetchRows(alarm_level_table)

        for i in results:
            #self.arr[i[1] - 1][i[2] - 1][i[4] - 1][i[5] - 1][i[6] - 1] = levels[i[9] - 1][0]
            self.arr[i[1] - 1][i[2] - 1][i[4] - 1][i[5] - 1][i[6] - 1] = i[9]
        logger.debug(
            'arr: %s' %
            json.dumps(self.arr, encoding='UTF-8', ensure_ascii=False))
Example #2
0
 def event2record(self, id, procUserName, procTime, procRecord):
     sqlcluster = SQLCluster()
     try:
         sqlcluster.moveEvent2Record(id, procUserName, procTime, procRecord)
         logger.info("%s process a package and write: %s" %
                     (str(procUserName), str(procRecord)))
     except Exception, e:
         logger.error(e, exc_info=True)
Example #3
0
class MenTable:

    def __init__(self):
        self.sqlcluster = SQLCluster()
        cp = ConfigParser.SafeConfigParser()
        cp.read('config\config.ini')
        cols_cnt = cp.get('table', 'cols_cnt')
        relation_table_name = cp.get('table', 'relation_table_name')
        cols_table_name = cp.get('table', 'cols_table_name')
        alarm_level_table = cp.get('table', 'alarm_level_table')
        tables = cols_table_name.split(',')
        logger.debug("tables %s" % tables)
        logger.debug('relation_table_name: %s' % relation_table_name)
        logger.debug('table cnt: %s' % cols_cnt)
        logger.debug('alarm_level_table: %s' % alarm_level_table)


        item = self.getTableNames(tables)
        logger.debug('item: %s' % item)

        self.arr = self.getList(item, 0)
        logger.debug('arr: %s' % self.arr)
        results = self.fetchRows(relation_table_name)
        logger.debug('result: %s' % results)

        levels = self.fetchRows(alarm_level_table)

        for i in results:
            #self.arr[i[1] - 1][i[2] - 1][i[4] - 1][i[5] - 1][i[6] - 1] = levels[i[9] - 1][0]
            self.arr[i['OrgType'] - 1][i['Position'] - 1][i['AlarmType'] - 1][i['DateAttribute'] - 1][i['TimeAttribute'] - 1] = i['AlarmLevel']
        logger.debug('arr: %s' % json.dumps(self.arr, encoding='UTF-8', ensure_ascii=False))

    def getTableNames(self, tables):
        item = []
        for tableName in tables:
            rows = self.sqlcluster.selectDictInfo(tableName)
            rowCount = len(rows)
            item.append(rowCount)
        return item

    def fetchRows(self, relation_table_name):
        rows = self.sqlcluster.selectDictInfo(relation_table_name)
        return rows

    def getList(self, arr, index):
        if index == len(arr) - 1:
            return [1] * arr[index]
        else:
            cur_list = []
            for i in range(arr[index]):
                cur_list.append(self.getList(arr, index + 1))
            return cur_list

    def query(self, i):
        if type(i) == list and len(i) == 5:
            return self.arr[i[0] - 1][i[1] - 1][i[2] - 1][i[3] - 1][i[4] - 1]
        return -1
Example #4
0
class MenTable:
    def __init__(self):
        self.sqlcluster = SQLCluster('astuple')
        cp = ConfigParser.SafeConfigParser()
        cp.read('config\config.ini')
        cols_cnt = cp.get('table', 'cols_cnt')
        relation_table_name = cp.get('table', 'relation_table_name')
        cols_table_name = cp.get('table', 'cols_table_name')
        alarm_level_table = cp.get('table', 'alarm_level_table')
        tables = cols_table_name.split(',')
        logger.debug("tables %s" % tables)
        logger.debug('relation_table_name: %s' % relation_table_name)
        logger.debug('table cnt: %s' % cols_cnt)
        logger.debug('alarm_level_table: %s' % alarm_level_table)

        item = self.getTableNames(tables)
        logger.debug('item: %s' % item)

        self.arr = self.getList(item, 0)
        logger.debug('arr: %s' % self.arr)
        results = self.fetchRows(relation_table_name)
        logger.debug('result: %s' % results)

        levels = self.fetchRows(alarm_level_table)

        for i in results:
            #self.arr[i[1] - 1][i[2] - 1][i[4] - 1][i[5] - 1][i[6] - 1] = levels[i[9] - 1][0]
            self.arr[i[1] - 1][i[2] - 1][i[4] - 1][i[5] - 1][i[6] - 1] = i[9]
        logger.debug(
            'arr: %s' %
            json.dumps(self.arr, encoding='UTF-8', ensure_ascii=False))

    def getTableNames(self, tables):
        item = []
        for tableName in tables:
            rows = self.sqlcluster.selectDictInfo(tableName)
            rowCount = len(rows)
            item.append(rowCount)
        return item

    def fetchRows(self, relation_table_name):
        rows = self.sqlcluster.selectDictInfo(relation_table_name)
        return rows

    def getList(self, arr, index):
        if index == len(arr) - 1:
            return [1] * arr[index]
        else:
            cur_list = []
            for i in range(arr[index]):
                cur_list.append(self.getList(arr, index + 1))
            return cur_list

    def query(self, i):
        if type(i) == list and len(i) == 5:
            return self.arr[i[0] - 1][i[1] - 1][i[2] - 1][i[3] - 1][i[4] - 1]
        return -1
Example #5
0
    def __init__(self):
        self.sqlcluster = SQLCluster()
        cp = ConfigParser.SafeConfigParser()
        cp.read('config\config.ini')
        cols_cnt = cp.get('table', 'cols_cnt')
        relation_table_name = cp.get('table', 'relation_table_name')
        cols_table_name = cp.get('table', 'cols_table_name')
        alarm_level_table = cp.get('table', 'alarm_level_table')
        tables = cols_table_name.split(',')
        logger.debug("tables %s" % tables)
        logger.debug('relation_table_name: %s' % relation_table_name)
        logger.debug('table cnt: %s' % cols_cnt)
        logger.debug('alarm_level_table: %s' % alarm_level_table)


        item = self.getTableNames(tables)
        logger.debug('item: %s' % item)

        self.arr = self.getList(item, 0)
        logger.debug('arr: %s' % self.arr)
        results = self.fetchRows(relation_table_name)
        logger.debug('result: %s' % results)

        levels = self.fetchRows(alarm_level_table)

        for i in results:
            #self.arr[i[1] - 1][i[2] - 1][i[4] - 1][i[5] - 1][i[6] - 1] = levels[i[9] - 1][0]
            self.arr[i['OrgType'] - 1][i['Position'] - 1][i['AlarmType'] - 1][i['DateAttribute'] - 1][i['TimeAttribute'] - 1] = i['AlarmLevel']
        logger.debug('arr: %s' % json.dumps(self.arr, encoding='UTF-8', ensure_ascii=False))
Example #6
0
class PCProcessThread(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.auSco = GlobalParams.GetAutoScoreInstance()
        self.IsRunning = True
        self.sqlcluster = SQLCluster()

    def StopThread(self):
        self.IsRunning = False

    def run(self):
        logger.info("ProcessCoreListener " + self.getName() + " Start Running")
        while self.IsRunning:
            msg = self.auSco.respQueue.get()

            self.sqlcluster.updatePackageFinishInfo(msg['packageId'], msg['userName'], msg['time'],msg['record'])

            logger.info(msg)

        logger.info("ProcessCoreListener " + self.getName() + " Stop Running")
Example #7
0
class PCProcessThread(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.auSco = GlobalParams.GetAutoScoreInstance()
        self.IsRunning = True
        self.sqlcluster = SQLCluster()

    def StopThread(self):
        self.IsRunning = False

    def run(self):
        logger.info("ProcessCoreListener " + self.getName() + " Start Running")
        while self.IsRunning:
            msg = self.auSco.respQueue.get()

            self.sqlcluster.updatePackageFinishInfo(msg['packageId'],
                                                    msg['userName'],
                                                    msg['time'], msg['record'])

            logger.info(msg)

        logger.info("ProcessCoreListener " + self.getName() + " Stop Running")
Example #8
0
    def process(self, type, params):
        RetCode = -1
        RetInfo = None

        if type == 100:
            # 执行操作1=============
            #print str(params)
            #id 包id
            id = int(params['1'].encode("utf-8"))
            user = params['2'].encode("utf-8")
            time = params['3'].encode("utf-8")
            operation = params['4'].encode("utf-8")
            #客户端处理包信息,通知processcore
            alarmUtil = AlarmUtil()
            alarmUtil.endPackageByUser(id, user, time, operation)

            sqlcluster = SQLCluster()
            eventList = sqlcluster.selectAlarmEventByPackageId(id)
            #将处理的包中的所有的event移到Record中
            for event in eventList:
                self.event2record(event['ID'], user, time, operation)
            RetCode = id
            # RetInfo = [(1, "11111"), (2, "22222")]
        elif type == 102:
            # 执行操作1=============
            print str(params)
        elif type == 103:
            # 执行操作1=============
            print str(params)
        elif type == 104:
            # 执行操作1=============
            print str(params)
        elif type == 105:
            # 执行操作1=============
            print str(params)
        else:
            logger.error("Error Type Number!! Please Check Interface Book!!!")

        return RetCode, RetInfo
Example #9
0
    def __init__(self):

        self.sqlcluster = SQLCluster()
Example #10
0
class AlarmUtil:
    def __init__(self):

        self.sqlcluster = SQLCluster()

    '''

    params: orgId, positionId, alarmId, dateArrId, timeArrId, alarmLevel
    alarmLevel:
        gentable = GenTable()
        gentable.query([DicOrgType,DicPosition,DicAlarmType,DicDateAttribute,DicTimeAttribute])
    '''

    def saveAlarmInfo(self, dictAlarmEvent):

        id = 1

        orgId = self.sqlcluster.deviceID2orgID(dictAlarmEvent['DeviceID'])
        orgType = self.sqlcluster.selectOrgTypeByOrgId(orgId)  #Type
        positionId = self.sqlcluster.deviceID2position(
            dictAlarmEvent['DeviceID'])
        alarmId = int(dictAlarmEvent['AlarmType'])
        dateArrId = int(dictAlarmEvent['DateAttribute'])
        timeArrId = int(dictAlarmEvent['TimeAttribute'])

        gentable = GlobalParams.GetGenTable()
        alarmLevel = gentable.query(
            [orgType, positionId, alarmId, dateArrId, timeArrId])

        parser = MsgParser()
        # save as db

        id = self.sqlcluster.insertAlarmEvent(dictAlarmEvent, alarmLevel)
        logger.info("Message has been inserted into db successfully, id: " +
                    str(id))

        auSco = GlobalParams.GetAutoScoreInstance()
        auSco.reqQueue.put({
            'orgId': orgId,
            'deviceId': dictAlarmEvent['DeviceID'],
            'alarmId': alarmId,
            'dateArrId': dateArrId,
            'timeArrId': timeArrId,
            'currentAlarmLevel': alarmLevel,
            'id': id
        })
        logger.info("put message to process core")

    def createPackage(self, orgId, level, id, isDeal=0, isFinish=0):
        #创建新包
        packageId = self.sqlcluster.createPackage(orgId, level, isDeal,
                                                  isFinish)

        #更新AlarmEvent中的packageid
        self.sqlcluster.updateAlarmEvent(packageId, id)

        #通知客户端
        notice_queue = GlobalParams.getNoticeProcessQueue()
        notice_queue.put(packageId)
        logger.info("create package: " + str(packageId))
        return packageId

    def updatePackageInfo(self, packageId, id, level):
        #更新包信息
        self.sqlcluster.updatePackageLevel(packageId, level)

        #更新AlarmEvent中的packageid
        self.sqlcluster.updateAlarmEvent(packageId, id)

        #通知客户端
        notice_queue = GlobalParams.getNoticeProcessQueue()
        notice_queue.put(packageId)

    def getMsg(self):
        # 获取要结包的packageId
        auSco = GlobalParams.GetAutoScoreInstance()
        dict = auSco.respQueue.get()
        self.sqlcluster.updatePackageFinishInfo(dict['packageId'])

    def endPackageByUser(self, packageId, userName, time, record):
        msg = {}
        auSco = GlobalParams.GetAutoScoreInstance()
        #self.sqlcluster.updatePackageFinishInfoByUser(packageId, userName, time, record)
        orgId = self.sqlcluster.selectOrgIdByPackageId(packageId)
        msg['orgId'] = orgId
        msg['userName'] = userName
        msg['time'] = time
        msg['record'] = record
        msg['packageId'] = packageId
        msg['stop'] = 'End by client'
        auSco.reqQueue.put(msg)
Example #11
0
 def render_POST(self, request):
     logger.info("Received post register request from host: " +
                 str(request.client.host) + ".")
     data = request.content.read()
     logger.debug("Received register data: " + data)
     #save register info
     msgparser = MsgParser()
     sqlcluster = SQLCluster()
     deviceId, channels = msgparser.parseRegisterData(data)
     try:
         if channels == {}:
             #unregister device
             deviceId = sqlcluster.selectDeviceId(deviceId)
             sqlcluster.updateDeviceRegisterInfo(deviceId, 0)
             sqlcluster.delChannelRegisterInfo(deviceId)
             logger.info("Unregister device: " + str(deviceId))
             return '200'
         else:
             #register device
             deviceId = sqlcluster.selectDeviceId(deviceId)
             sqlcluster.updateDeviceRegisterInfo(deviceId, 1)
             for k, v in channels.items():
                 inputDeviceId = deviceId
                 channelno = k
                 channelip = v[0]
                 channelport = v[1]
                 channelname = v[2]
                 channeltype = v[3]
                 sqlcluster.insertChannelRegisterInfo(
                     str(channelname), channelno, channeltype, channelip,
                     inputDeviceId, channelport)
             logger.info("Register device: " + str(deviceId))
             return '200'
     except Exception, e:
         logger.error("Error occured!!!", exc_info=True)
         return '400'
Example #12
0
 def render_POST(self,request):
     logger.info("Received post register request from host: " + str(request.client.host) + ".")
     data = request.content.read()
     logger.debug("Received register data: " + data)
     #save register info
     msgparser = MsgParser()
     sqlcluster = SQLCluster()
     deviceId, channels = msgparser.parseRegisterData(data)
     try:
         if channels == {}:
             #unregister device
             deviceId = sqlcluster.selectDeviceId(deviceId)
             sqlcluster.updateDeviceRegisterInfo(deviceId, 0)
             sqlcluster.delChannelRegisterInfo(deviceId)
             logger.info("Unregister device: " + str(deviceId))
             return '200'
         else:
             #register device
             deviceId = sqlcluster.selectDeviceId(deviceId)
             sqlcluster.updateDeviceRegisterInfo(deviceId, 1)
             for k, v in channels.items():
                 inputDeviceId = deviceId
                 channelno = k
                 channelip = v[0]
                 channelport = v[1]
                 channelname = v[2]
                 channeltype = v[3]
                 sqlcluster.insertChannelRegisterInfo(str(channelname), channelno, channeltype, channelip, inputDeviceId, channelport)
             logger.info("Register device: " + str(deviceId))
             return '200'
     except Exception, e:
         logger.error("Error occured!!!", exc_info=True)
         return '400'
Example #13
0
    def __init__(self):

        self.sqlcluster = SQLCluster()
Example #14
0
class AlarmUtil:
    def __init__(self):

        self.sqlcluster = SQLCluster()
    '''

    params: orgId, positionId, alarmId, dateArrId, timeArrId, alarmLevel
    alarmLevel:
        gentable = GenTable()
        gentable.query([DicOrgType,DicPosition,DicAlarmType,DicDateAttribute,DicTimeAttribute])
    '''

    def saveAlarmInfo(self, dictAlarmEvent):

        id = 1

        orgId = self.sqlcluster.deviceID2orgID(dictAlarmEvent['DeviceID'])
        orgType = self.sqlcluster.selectOrgTypeByOrgId(orgId)#Type
        positionId = self.sqlcluster.deviceID2position(dictAlarmEvent['DeviceID'])
        alarmId = int(dictAlarmEvent['AlarmType'])
        dateArrId = int(dictAlarmEvent['DateAttribute'])
        timeArrId = int(dictAlarmEvent['TimeAttribute'])

        gentable = GlobalParams.GetGenTable()
        alarmLevel = gentable.query([orgType, positionId, alarmId, dateArrId, timeArrId])

        parser = MsgParser()
        # save as db

        id = self.sqlcluster.insertAlarmEvent(dictAlarmEvent, alarmLevel)
        logger.info("Message has been inserted into db successfully, id: " + str(id))

        auSco = GlobalParams.GetAutoScoreInstance()
        auSco.reqQueue.put({'orgId': orgId, 'deviceId': dictAlarmEvent['DeviceID'], 'alarmId': alarmId, 'dateArrId': dateArrId, 'timeArrId': timeArrId, 'currentAlarmLevel': alarmLevel, 'id': id})
        logger.info("put message to process core")


    def createPackage(self, orgId, level, id, isDeal = 0, isFinish = 0):
        #创建新包
        packageId = self.sqlcluster.createPackage(orgId, level, isDeal, isFinish)

        #更新AlarmEvent中的packageid
        self.sqlcluster.updateAlarmEvent(packageId, id)

        #通知客户端
        notice_queue = GlobalParams.getNoticeProcessQueue()
        notice_queue.put(packageId)
        logger.info("create package: " + str(packageId))
        return packageId

    def updatePackageInfo(self, packageId, id, level):
        #更新包信息
        self.sqlcluster.updatePackageLevel(packageId, level)

        #更新AlarmEvent中的packageid
        self.sqlcluster.updateAlarmEvent(packageId, id)

        #通知客户端
        notice_queue = GlobalParams.getNoticeProcessQueue()
        notice_queue.put(packageId)

    def getMsg(self):
        # 获取要结包的packageId
        auSco = GlobalParams.GetAutoScoreInstance()
        dict = auSco.respQueue.get()
        self.sqlcluster.updatePackageFinishInfo(dict['packageId'])


    def endPackageByUser(self, packageId, userName, time, record):
        msg = {}
        auSco = GlobalParams.GetAutoScoreInstance()
        #self.sqlcluster.updatePackageFinishInfoByUser(packageId, userName, time, record)
        orgId = self.sqlcluster.selectOrgIdByPackageId(packageId)
        msg['orgId'] = orgId
        msg['userName'] = userName
        msg['time'] = time
        msg['record'] = record
        msg['packageId'] = packageId
        msg['stop'] = 'End by client'
        auSco.reqQueue.put(msg)
Example #15
0
 def __init__(self):
     Thread.__init__(self)
     self.auSco = GlobalParams.GetAutoScoreInstance()
     self.IsRunning = True
     self.sqlcluster = SQLCluster()
Example #16
0
 def __init__(self):
     Thread.__init__(self)
     self.auSco = GlobalParams.GetAutoScoreInstance()
     self.IsRunning = True
     self.sqlcluster = SQLCluster()