Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/readers.py
diff options
context:
space:
mode:
Diffstat (limited to 'readers.py')
-rw-r--r--readers.py89
1 files changed, 59 insertions, 30 deletions
diff --git a/readers.py b/readers.py
index f14e686..ce7af80 100644
--- a/readers.py
+++ b/readers.py
@@ -21,57 +21,78 @@
import cPickle
import csv
+from gettext import gettext as _
-class StopWatch():
+
+class StopWatchReader():
def __init__(self, data):
+ """Import chart data from file."""
+
self._data = cPickle.load(data)
- def get_stopwatchs_with_marks(self):
- count = 0
- stopwatchs_list = []
- for i in self._data[-1]:
- if i:
- count += 1
- stopwatchs_list.append([count, self._data[1][count - 1]])
+ self._v_label = _('Time')
+ self._h_label = ''
- return stopwatchs_list, count
+ def get_chart_data(self):
+ """Return data suitable for pyCHA."""
- def get_stopwatch_name(self, num=0):
- return self._data[1][num]
+ count = self._get_stopwatchs_with_marks()
+ chart_data = []
- def marks_to_chart_data(self, num=0, chart_data=[]):
- marks_count = 0
+ if count == 1:
+ self._h_label = _('Mark')
- marks = self._data[-1][num]
- marks.sort()
+ marks_count = 0
- for i in marks:
- marks_count += 1
- chart_data.append((str(marks_count), round(i, 2)))
+ for x in self._data[-1]:
+ x.sort()
+ for y in x:
+ marks_count += 1
+ chart_data.append((str(marks_count), round(y, 2)))
- return chart_data
+ elif count == 0 or count > 1:
+ self._h_label = _('StopWatch')
- def times_to_chart_data(self):
- times = [i[0][0] for i in self._data[2]]
+ times = [i[0][0] for i in self._data[2]]
- times_count = 0
- chart_data = []
+ times_count = 0
+ chart_data = []
- for i in times:
- times_count += 1
- chart_data.append((self.get_stopwatch_name(times_count - 1),
- round(i, 2)))
+ for i in times:
+ times_count += 1
+ chart_data.append((self._get_stopwatch_name(times_count - 1),
+ round(i, 2)))
return chart_data
+ def get_labels_name(self):
+ """Return the h_label and y_label names."""
-class Measure():
+ return self._v_label, self._h_label
- def __init__(self, data):
- self._reader = csv.reader(data)
+ def _get_stopwatchs_with_marks(self):
+ count = 0
+ for i in self._data[-1]:
+ if i:
+ count += 1
+
+ return count
+
+ def _get_stopwatch_name(self, num=0):
+ return self._data[1][num]
+
+
+class MeasureReader():
+
+ def __init__(self, file):
+ """Import chart data from file."""
+
+ self._reader = csv.reader(file)
def get_chart_data(self):
+ """Return data suitable for pyCHA."""
+
count = 0
chart_data = []
@@ -83,3 +104,11 @@ class Measure():
chart_data.append((label, float(value)))
return chart_data
+
+ def get_labels_name(self):
+ """Return the h_label and y_label names."""
+
+ v_label = _('Values')
+ h_label = _('Samples')
+
+ return v_label, h_label