Пример #1
0
    def step( self, value, data={}, listeners=[] ):
        """
        This function will take one sample out of limit samples.

        :param value: The input value to be processesed
        :type value: int, float, string, etc
        :param data: a dictionary containing more information about the value.
        :param listeners: a list of the subscribed routines to send the data to
        :returns: new_value, new_data, new_listeners
        :rtype: int, dict, listeners
        :raises: KeyError

        >>> from steps.oneInN import oneInN
        >>> oneInN = oneInN()
        >>> c2f.step(0, {'device': 'test', 'port': 'test'}, ['a', 'b'])
        (32.0, {'device': 'test', 'units': 'F', 'port': 'test'}, [])
        >>> c2f.step(100, {'device': 'test', 'port': 'test'}, ['a', 'b'])
        (212.0, {'device': 'test', 'units': 'F', 'port': 'test'}, ['a', 'b'])

        """
        device, port = Common.getDeviceAndPort( data )
        limit = int( self.config[device][port] )

        Common.generateDevicePortTree( 0, device, port, self.count )
        if ( self.count[device][port] % limit ) != 0:
            listeners = []
            self.logger.debug( "count is {}: don't send data".format( self.count[device][port] ) )
        else:
            self.logger.debug( "count is {}: send data".format( self.count[device][port] ) )
        self.count[device][port] += 1
        return value, data, listeners
Пример #2
0
    def step( self, value, data={}, listeners=[] ):
        """
        This function will compare the value with the previous value and if they are different send the data to
        the next listener else don't send the data along.

        :param value: The number to add to the list of numbers.
        :type value: boolean, int or float
        :param data: a dictionary containing more information about the value. 
        :param listeners: a list of the subscribed routines to send the data to
        :returns: value, data, listeners
        :rtype: float, dict, listeners
        :Raises: ValueError, KeyError

        """

        device, port = Common.getDeviceAndPort( data )

        new_entry = Common.generateDevicePortTree( value, device, port, self.current_value )

        if ( ( value == self.current_value[device][port] ) and not new_entry ):
            listeners = []
            self.logger.debug( 'No change detected: steps discontinued: device = {} port = {} volue = {} previous value = {}'.format( device, port, value, self.current_value[device][port] ) )
        else:
            self.logger.debug( 'Change detected: continue stepping device = {} port = {} volue = {} previous value = {}'.format( device, port, value, self.current_value[device][port] ) )

        self.current_value[device][port] = value
        return value, data, listeners
Пример #3
0
    def step(self, value, data={}, listeners=[]):
        """
        This function will compare the value with the previous value and if they are different send the data to
        the next listener else don't send the data along.

        :param value: The number to add to the list of numbers.
        :type value: boolean, int or float
        :param data: a dictionary containing more information about the value. 
        :param listeners: a list of the subscribed routines to send the data to
        :returns: value, data, listeners
        :rtype: float, dict, listeners
        :Raises: ValueError, KeyError

        """

        device, port = Common.getDeviceAndPort(data)

        new_entry = Common.generateDevicePortTree(value, device, port,
                                                  self.current_value)

        if ((value == self.current_value[device][port]) and not new_entry):
            listeners = []
            self.logger.debug(
                'No change detected: steps discontinued: device = {} port = {} volue = {} previous value = {}'
                .format(device, port, value, self.current_value[device][port]))
        else:
            self.logger.debug(
                'Change detected: continue stepping device = {} port = {} volue = {} previous value = {}'
                .format(device, port, value, self.current_value[device][port]))

        self.current_value[device][port] = value
        return value, data, listeners
Пример #4
0
    def step( self, value, data={}, listeners=[] ):
        """
        This function will record the max value.

        :param value: The number to add to the list of numbers.
        :type value: boolean, int or float
        :param data: a dictionary containing more information about the value. 
        :param listeners: a list of the subscribed routines to send the data to
        :returns: value, data, listeners
        :rtype: float, dict, listeners
        :raises: ValueError, KeyError
        
        """
        device, port = Common.getDeviceAndPort( data )
        Common.generateDevicePortTree( value, device, port, self.max_value )

        if value > self.max_value[device][port]:
            self.max_value[device][port] = value

        return value, data, listeners
Пример #5
0
    def step(self, value, data={}, listeners=[]):
        """
        This function will record the max value.

        :param value: The number to add to the list of numbers.
        :type value: boolean, int or float
        :param data: a dictionary containing more information about the value. 
        :param listeners: a list of the subscribed routines to send the data to
        :returns: value, data, listeners
        :rtype: float, dict, listeners
        :raises: ValueError, KeyError
        
        """
        device, port = Common.getDeviceAndPort(data)
        Common.generateDevicePortTree(value, device, port, self.max_value)

        if value > self.max_value[device][port]:
            self.max_value[device][port] = value

        return value, data, listeners
Пример #6
0
    def test_generateDevicePortTree( self ):
        values = {}
        value = ( 'a', 'b' )
        devices = ( 'device1', 'device2' )
        ports = ( 'port1', 'port2' )
        expected_values = {devices[0]: {ports[0]: value[0]}}

        added = Common.generateDevicePortTree( value[0], devices[0], ports[0], values )
        self.assertDictEqual( expected_values, values )
        self.assertTrue( added )

        # Check if no new entry was added
        added = Common.generateDevicePortTree( value[0], devices[0], ports[0], values )
        self.assertDictEqual( expected_values, values )
        self.assertFalse( added )

        # Check port
        expected_values = {devices[0]: {ports[0]: value[0], ports[1]: value[1]}}
        added = Common.generateDevicePortTree( value[1], devices[0], ports[1], values )
        self.assertDictEqual( expected_values, values )
        self.assertTrue( added )