예제 #1
0
    def simulateData(self,
                     dataFilter: Data,
                     limit: int = -1,
                     lastTime: float = -1):
        """ Implement me! :: Allows to simulate data if this module start standalone """

        if self.simulationStep == 0:
            self.file = open(self.SimulatingPath, 'r').readlines()
            self.file_length = len(self.file)

        dataReturn = []

        if dataFilter.package != '':
            for target_list in self.file:
                if len(target_list) < 10:
                    continue
                dataSimulated = Data()
                dataSimulated = dataSimulated.parse(target_list, False, True)
                if dataSimulated.package == dataFilter.package and dataSimulated.source_name == dataFilter.source_name:
                    dataReturn.append(dataSimulated)
                    dataReturn.insert(0, {'queryTime': time()})
                    return dataReturn

        if self.simulationStep < self.file_length:
            if len(self.file[self.simulationStep]) < 10:
                dataReturn.insert(0, {'queryTime': time()})
                self.simulationStep += 1
                return dataReturn

            dataSimulated = Data()
            dataSimulated = dataSimulated.parse(self.file[self.simulationStep],
                                                False, True)

            if dataSimulated.source_name != dataFilter.source_name:
                dataReturn.insert(0, {'queryTime': time()})
                self.simulationStep += 1
                return dataReturn

            self.simulationStep += 1
            dataReturn.append(dataSimulated)
            dataReturn.insert(0, {'queryTime': time()})
        else:
            self.simulationStep = 0
            dataReturn = self.simulateData(dataFilter)

        return dataReturn
예제 #2
0
    def get(self, parser, sourceType: SourceTypes, origin: str):
        """ Returns all active data. 
                Params: Data
            
            Retrive a object Data with structure:
                {
                    'id'            : self.id,
                    'born'          : self.born,
                    'source_type'   : str(self.source_type),
                    'source_name'   : self.source_name,
                    'source_item'   : self.source_item,
                    'package'       : self.package,
                    'data'          : self.serialize(self.data),
                    'aux'           : self.serialize(self.aux),
                    'state'         : str(self.state),
                },
                limit,
                lastTime,
                all
            
            Controller and device could be an Exp Reg.
            Ex. 'CamController' for single or 'CamController.*?' for all from CamController
        """
        try:
            #TODO: Si en lugar de data se reciben las variables id, package, source_name y source_item
            # como se registra en la documentación. Además el tipo lo debe sacar de la url que se usa
            parser = reqparse.RequestParser()
            parser.add_argument('data')
            parser.add_argument('limit')
            parser.add_argument('lastTime')
            parser.add_argument('onlyActive')
            args = parser.parse_args()

            dataIn = args.data
            dataIn = '' if dataIn == None else dataIn
            data = Data()
            data.id = '-1'
            if dataIn != '':
                data = data.parse(dataIn)

            limit = args.limit
            lastTime = args.lastTime
            onlyActive = True if args.onlyActive == '' else Misc.toBool(
                args.onlyActive)

            result = DataPool().getPool(data=data,
                                        limit=limit,
                                        lastTime=lastTime,
                                        onlyActive=onlyActive)

            result = list(map(lambda d: d.getJson(), result))
            result.insert(0, {'msg': 'ok', 'queryTime': time()})
        except:
            message = Binnacle().errorDetail(Messages.error_pool_reading)
            Binnacle().logFromCore(message, LogTypes.ERROR, origin)
            result = [{'msg': message}]
        return result
예제 #3
0
    def post(self, parser, sourceType: SourceTypes, origin: str):
        """ Load data in pool. Params:
                data: Data
            
            Retrive a object Data with structure:
                {
                    'id'            : self.id,
                    'born'          : self.born,
                    'source_type'   : str(self.source_type),
                    'source_name'   : self.source_name,
                    'source_item'   : self.source_item,
                    'package'       : self.package,
                    'data'          : self.serialize(self.data),
                    'aux'           : self.serialize(self.aux),
                    'state'         : str(self.state),
                }
        """
        try:
            #TODO: Validar tipo de dato y si no coiside emitir error
            #TODO: E ltipo de dato esperado lo debe sacar de la clase en su instanciación
            parser = reqparse.RequestParser()
            parser.add_argument('data')
            args = parser.parse_args()

            dataIn = args.data
            dataIn = '' if dataIn == None else dataIn
            data = Data()
            data.id = -1
            if dataIn != '':
                data = data.parse(dataIn)
                if sourceType != SourceTypes.parse(data.source_type):
                    raise ValueError(
                        Messages.bad_source_type_deteiled.format(
                            sourceType, SourceTypes.parse(data.source_type)))
                DataPool().append(data)
                DataPool().pop()

            result = [{'msg': 'ok', 'id': data.id}]
        except:
            message = Binnacle().errorDetail(Messages.error_pool_writing)
            Binnacle().logFromCore(message, LogTypes.ERROR, origin)
            result = [{'msg': message}]
        return result
예제 #4
0
 def post(self):
     """ Register message in Binnacle """
     parser = reqparse.RequestParser()
     parser.add_argument('data')
     #parser.add_argument('data.data')
     #parser.add_argument('data.aux')
     parser.add_argument('logType')
     parser.add_argument('isCore')
     args = parser.parse_args()
     dataIn = args.data
     dataIn = '' if dataIn == None else dataIn
     data = Data()
     data.id = -1
     if dataIn != '':
         data = data.parse(dataIn, dataPlain=True, auxPlain=True)
         if Misc.toBool(args.isCore):
             Binnacle().logFromCore(data.data, LogTypes.parse(args.logType),
                                    data.aux)
         else:
             Binnacle().logFromComponent(data, LogTypes.parse(args.logType))