diff --git a/ekgplotter/ekgplotter/main.py b/ekgplotter/ekgplotter/main.py index e57bf20..022c2ca 100644 --- a/ekgplotter/ekgplotter/main.py +++ b/ekgplotter/ekgplotter/main.py @@ -145,6 +145,10 @@ queue = Queue.Queue() class MyHandler(BaseHTTPRequestHandler): + def __del__(self): + self.thread.running = False + self.thread.join() + def do_GET(self): print "get" @@ -166,37 +170,71 @@ class MyHandler(BaseHTTPRequestHandler): scale = 254 / max_items * ix return [value / max_items + scale for value in data] + def set_point(plotPoint, pos, value, ix, max_items): scale = 254 / max_items * ix - plotPoint.setData(x = [pos], y = [6*ix + value / max_items + scale]) + y = 6 * ix + value / max_items + scale + plotPoint.setData(x = [pos], y = [y]) - def setValue(dataItem, pos, maxPos, value): - dataItem[pos] = value - return (pos + 1) % maxPos + def find_max_value(item_data): + max_index = -1 + for ix, i in enumerate(item_data): + if i > 250: + return ix, i + return None, None - def findMax(dataItem): - max_value = 0 - max_index = 0 - for ix, i in enumerate(dataItem): - if i > max_value: - max_value = i - max_index = ix - return max_index - def rearrange(data, index, max_items): - max_value = findMax(data) + def rearrange(item_data, actual_pos, max_items): + max_value_index, max_value = find_max_value(item_data) + if max_value_index is None: + return actual_pos mean = int(max_items / 2.) - start = mean - max_value - data.rotate(start) - pos = (index + start) % max_items - print "rearrange", index, max_items, pos + start = mean - max_value_index + if start != 0: + item_data.rotate(start) + pos = (actual_pos + start) % max_items + else: + pos = actual_pos + print "rearrange", mean, start, actual_pos, pos, item_data return pos - def checkDataPoints(value, data_max_value): - if value > max_value and value > 200: - return True, value - return False, data_max_value + + def set_value(item_data, pos, max_pos, value): + print "setValue before", pos, None, max_pos, value, item_data, len(item_data) + item_data[pos] = value + new_pos = (pos + 1) % max_pos + print "setValue after ", pos, new_pos, max_pos, value, item_data, len(item_data) + return new_pos + + def resize(item_data, max_length, new_max_length, pos): + print "resize", max_length, new_max_length + if new_max_length < 15: + return max_length, pos + + if new_max_length > max_length: + pad = (new_max_length - max_length) + print "pad", pad + for i in range(pad): + if i % 2 == 0: + item_data.append(0) + else: + item_data.appendleft(0) + pos += 1 + return new_max_length, pos + elif new_max_length < max_length: + pad = (max_length - new_max_length) + for i in range(pad): + if i % 2 == 0: + item_data.pop() + if pos >= new_max_length: + pos = 0 + else: + item_data.popleft() + if pos > 0: + pos -= 1 + return new_max_length, pos + return max_length, pos try: self.path=re.sub('[^.a-zA-Z0-9]', "",str(self.path)) @@ -218,6 +256,8 @@ class MyHandler(BaseHTTPRequestHandler): pos2 = 0 pos3 = 0 + lengths1 = [0] + data1_max_value = 0 data2_max_value = 0 data3_max_value = 0 @@ -229,7 +269,7 @@ class MyHandler(BaseHTTPRequestHandler): plot_data1 = deque([0] * data_points) plot_data2 = deque([0] * data_points) plot_data3 = deque([0] * data_points) - plt = PlotWidget(title="