def _buildWindow(self, start, end):
     window = {}
     for field in self.fields:
         value = self.rawData[start:end, self.header.index(field)]
         if self.hasQuality:
             quality = self.rawData[start:end,
                                    self.header.index("Q" + field)]
         else:
             quality = array([0] * (end - start))
         window[field] = {"value": value, "quality": quality}
     dto = WindowDto(self.windowSize, self.fields)
     dto.data = window
     return dto
예제 #2
0
class SignalWindow(object):

    def __init__(self, collectedQueue, windowSize, fields):
        self.collectedQueue = collectedQueue
        self.windowSize = windowSize
        self.fields = fields
        self.index = 0

        self._createDto()

    def _createDto(self):
        self.dto = WindowDto(self.windowSize, self.fields)

    def _resetWindow(self):
        self.index = 0
        self._createDto()

    def addData(self, data):
        '''
        expects data like this      
        {
            "X": {
                "value":     1,
                "quality":   2  
            },
            "F3": {
                "value":     3,
                "quality":   4  
            }, ...
        }
        
        :param dict data: 
        '''
        #TODO potential bottleneck
        self.dto.addData(data)
        self.index += 1
        
        if self.isFull():
            data = self._doWindowFunction(self.dto)
            self.collectedQueue.put(data)
            self._resetWindow()

    def isFull(self):
        return self.index >= self.windowSize

    def _doWindowFunction(self, data):
        pass

    def __repr__(self):  # pragma: no cover
        return "%s: { windowSize = %d, numValue = %d }" % (self.__class__.__name__, self.windowSize, self.index)
예제 #3
0
 def _createDto(self):
     self.dto = WindowDto(self.windowSize, self.fields)
 def getEmptyDto(self):
     return WindowDto(WINDOW_SIZE, FIELDS)
'''
Created on 02.07.2016

:author: Paul Pasler
:organization: Reutlingen University
'''

from base_test import *  # @UnusedWildImport

from Queue import Queue

from posdbos.collector.signal_window import RectangularSignalWindow
from posdbos.collector.window_dto import WindowDto

WINDOW_SECONDS = 4
EMPTY_DTO = WindowDto(WINDOW_SECONDS, ["X"])


def _fillValues(window, count, start=0):
    for i in range(start, count):
        window.addData({"X": {"value": i, "quality": i**2}})


def _fillWindowFull(window):
    _fillValues(window, WINDOW_SECONDS)


class TestRectanglarSignalWindow(BaseTest):
    def setUp(self):
        self.collectedQueue = Queue()
        self.window = RectangularSignalWindow(self.collectedQueue,
예제 #6
0
 def setUp(self):
     self.winSize = 4
     self.header = ["X", "AF3"]
     self.dto = WindowDto(self.winSize, self.header)
예제 #7
0
class TestWindowDto(BaseTest):
    def setUp(self):
        self.winSize = 4
        self.header = ["X", "AF3"]
        self.dto = WindowDto(self.winSize, self.header)

    def _fillDto(self, start=0, count=2):
        for i in range(start, count):
            self.dto.addData({
                "X": {
                    "value": i,
                    "quality": i * 2
                },
                "AF3": {
                    "value": i * 3,
                    "quality": i * 4
                }
            })

    def test_init(self):
        self._fillDto(count=self.winSize)

    def test_len(self):
        self.assertEqual(len(self.dto), len(self.header))

    def test_shape(self):
        self.assertEqual(self.dto.shape(), (len(self.dto), len(self.header)))

    def test_contains(self):
        self.assertTrue("X" in self.dto)
        self.assertTrue("AF3" in self.dto)
        self.assertFalse("x" in self.dto)
        self.assertFalse("Y" in self.dto)

    def test_getitem(self):
        self._fillDto(count=self.winSize)
        self.assertEqual(self.dto["X"]["value"], range(self.winSize))

    def test_iter(self):
        for key in self.dto:
            self.assertTrue(key in self.header)

    def test_eq(self):
        self.assertNotEqual(self.dto, None)
        self.assertNotEqual(self.dto, 1)
        cp = self.dto.copy()
        cp.header = ["AF3", "X"]
        self.assertNotEqual(self.dto, cp)

        cp = self.dto.copy()
        self.assertEqual(cp, self.dto)
        self._fillDto(count=self.winSize)
        self.assertNotEqual(cp, self.dto)

    def test_cp(self):
        cp = self.dto.copy()
        self.assertEqual(cp, self.dto)
        self.assertNotEquals(id(cp), id(self.dto))

    def test_getField(self):
        self._fillDto(count=self.winSize)

        assert_array_equal(self.dto.getValue("X"), range(self.winSize))
        assert_array_equal(self.dto.getQuality("X"),
                           np.array(range(self.winSize)) * 2)

        testVal = np.array([17]) * self.winSize
        self.dto.addNewField("X", "test", testVal)
        assert_array_equal(self.dto.getField("X", "test"), testVal)
 def _createDto(self):
     dto = WindowDto(2, TEST_DATA.keys())
     dto.setData(TEST_DATA)
     return dto