Keep min and max values of dropped data points
This commit is contained in:
parent
c5b8476a42
commit
ca0ce798da
|
@ -43,6 +43,31 @@ class LTS:
|
||||||
json.dump({"description": self.description, "data": self.data}, fh)
|
json.dump({"description": self.description, "data": self.data}, fh)
|
||||||
self.rebuild_index()
|
self.rebuild_index()
|
||||||
|
|
||||||
|
def pop(self, i):
|
||||||
|
# Pop the element at index i and adjust the min/max values of the
|
||||||
|
# neighbours.
|
||||||
|
# We might also want to adjust the value of the neighbours to some
|
||||||
|
# (weighted) average, but I'm not sure if this is actually a good idea.
|
||||||
|
data = self.data
|
||||||
|
old = data.pop(i) # after that the neighbours are at i-1, i
|
||||||
|
min_v = old[2] if len(old) >= 4 else old[1]
|
||||||
|
max_v = old[3] if len(old) >= 4 else old[1]
|
||||||
|
if i > 0:
|
||||||
|
if len(data[i-1]) == 2:
|
||||||
|
data[i-1] = [data[i-1][0], data[i-1][1], data[i-1][1], data[i-1][1]]
|
||||||
|
if min_v < data[i-1][2]:
|
||||||
|
data[i-1][2] = min_v
|
||||||
|
if max_v > data[i-1][3]:
|
||||||
|
data[i-1][3] = max_v
|
||||||
|
if i < len(data):
|
||||||
|
if len(data[i]) == 2:
|
||||||
|
data[i] = [data[i][0], data[i][1], data[i][1], data[i][1]]
|
||||||
|
if min_v < data[i][2]:
|
||||||
|
data[i][2] = min_v
|
||||||
|
if max_v > data[i][3]:
|
||||||
|
data[i][3] = max_v
|
||||||
|
return old
|
||||||
|
|
||||||
def shrink(self):
|
def shrink(self):
|
||||||
# Remove one element in such a way that the distributions gets closer
|
# Remove one element in such a way that the distributions gets closer
|
||||||
# to an exponential curve through the first and the last few data
|
# to an exponential curve through the first and the last few data
|
||||||
|
@ -61,7 +86,7 @@ class LTS:
|
||||||
t_ideal = (math.exp(k * (n - i)/n) - 1) * (n * dt)
|
t_ideal = (math.exp(k * (n - i)/n) - 1) * (n * dt)
|
||||||
if t_last - data[i][0] > t_ideal:
|
if t_last - data[i][0] > t_ideal:
|
||||||
log.debug("%s - %s > %s -> popping element %s", t_last, data[i][0], t_ideal, i)
|
log.debug("%s - %s > %s -> popping element %s", t_last, data[i][0], t_ideal, i)
|
||||||
data.pop(i)
|
self.pop(i)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# Well, it works mostly. Sometimes all the real points are below
|
# Well, it works mostly. Sometimes all the real points are below
|
||||||
|
@ -71,7 +96,7 @@ class LTS:
|
||||||
# narrow range just before that.
|
# narrow range just before that.
|
||||||
i = random.randrange(int(n*0.98), int(n*0.99))
|
i = random.randrange(int(n*0.98), int(n*0.99))
|
||||||
log.debug("no match -> popping element %s", i)
|
log.debug("no match -> popping element %s", i)
|
||||||
data.pop(i)
|
self.pop(i)
|
||||||
|
|
||||||
def add(self, ts, value):
|
def add(self, ts, value):
|
||||||
while len(self.data) >= self.limit:
|
while len(self.data) >= self.limit:
|
||||||
|
|
Loading…
Reference in New Issue