Example #1
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 #2
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 #3
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 #4
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)