class AverageQualityObject(object):
    def __init__(self, bufferSize):
        self.absoluteBuffer = NumericRingBuffer(bufferSize)
        self.ratedBuffer = NumericRingBuffer(bufferSize)
        
    def calculate(self, absoluteValue, ratedValue):
        self.absoluteBuffer.add(absoluteValue)
        self.ratedBuffer.add(ratedValue)
    
    def getAbsoluteAverage(self):
        return self.absoluteBuffer.mean()

    def getRatedAverage(self):
        return self.ratedBuffer.mean()

    def getAbsoluteMin(self):
        return self.absoluteBuffer.min()
    
    def getAbsoluteMax(self):
        return self.absoluteBuffer.max()
    
    def getRatedMin(self):
        return self.ratedBuffer.min()
    
    def getRatedMax(self):
        return self.ratedBuffer.max()
class TimeElement(Element):
    def __init__(self, name, value=0):
        super(TimeElement, self).__init__(name)
        self.buffer = NumericRingBuffer(BUFFER_SIZE)
        [self.buffer.add(0) for _i in range(0, value)]
        self.startTime = None

    def started(self, test=False):
        if self.startTime:
            return True
        return False

    def start(self):
        if self.startTime is None:
            self.startTime = datetime.datetime.now()
        else:
            print self.name, "already started!"

    def stop(self, stoptime):
        if self.startTime is not None:
            self.buffer.add((stoptime - self.startTime).total_seconds())
            self.startTime = None
        else:
            print "TimeElement", self.name, "already stopped"

    def finish(self):
        print super(TimeElement, self).finish()
        print "Mean:", self.mean()
        return super(TimeElement, self).finish()

    def mean(self):
        return self.buffer.mean()

    def sum(self):
        return sum(self.buffer)

    def getData(self, name):
        return (name, self.buffer)

    def insertNotUsedValue(self, values=0):
        for _i in range(0, (values - self.buffer.len())):
            self.buffer.add(0)