Commit 94c6cd7e authored by Joanne Hugé's avatar Joanne Hugé

Offset the histogram data if needed

parent ff0ffd42
...@@ -316,10 +316,11 @@ class MeasureSet: ...@@ -316,10 +316,11 @@ class MeasureSet:
return metadata return metadata
def add_metadata(self, measure_type, units, metadata): def add_metadata(self, measure_type, units, middle, metadata):
self.measure_type = measure_type self.measure_type = measure_type
self.units = units self.units = units
self.middle = middle
self.metadata.update(metadata) self.metadata.update(metadata)
def add_chronological(self, props_names, props): def add_chronological(self, props_names, props):
...@@ -348,12 +349,12 @@ class MeasureSet: ...@@ -348,12 +349,12 @@ class MeasureSet:
enumerate_prop = list(enumerate(prop)) enumerate_prop = list(enumerate(prop))
self.max.append(max(list(map(lambda x: x[0] if x[1] else 0, enumerate_prop)))) self.max.append(max(list(map(lambda x: (x[0] - self.middle) if x[1] else 0, enumerate_prop))))
self.min.append(min(map(lambda x: x[0] if x[1] else 0, enumerate_prop))) self.min.append(min(map(lambda x: (x[0] - self.middle) if x[1] else 0, enumerate_prop)))
sum_prop = sum(prop) sum_prop = sum(prop)
avg = sum(map(lambda x: x[0]*x[1], enumerate_prop)) / sum_prop avg = sum(map(lambda x: abs(x[0] - self.middle)*x[1], enumerate_prop)) / sum_prop
var = 0 var = 0
for x, p in enumerate_prop: for x, p in enumerate_prop:
var += p * x**2 var += p * x**2
...@@ -407,8 +408,12 @@ class MeasureSet: ...@@ -407,8 +408,12 @@ class MeasureSet:
measure_type = data['measure_type'] measure_type = data['measure_type']
units = data['units'] units = data['units']
metadata = data['metadata'] metadata = data['metadata']
if 'middle' in data:
middle = data['middle']
else:
middle = 0
self.add_metadata(measure_type, units, metadata) self.add_metadata(measure_type, units, middle, metadata)
props_names = data['props_names'] props_names = data['props_names']
...@@ -434,8 +439,8 @@ class MeasureSet: ...@@ -434,8 +439,8 @@ class MeasureSet:
def generate_histogram(self, i, color, name): def generate_histogram(self, i, color, name):
bins = [i for i in range(self.max[i] + 1)] bins = [i for i in range(self.min[i], self.max[i] + 1)]
vals = self.props[i][:self.max[i] + 1] vals = self.props[i][self.min[i] + self.middle : self.max[i] + self.middle + 1]
min_val = max(vals) / 140 min_val = max(vals) / 140
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment