Index: trunk/fundraiser-statistics/fundraiser-scripts/classes/DataReporting.py |
— | — | @@ -16,25 +16,18 @@ |
17 | 17 | __date__ = "December 16th, 2010" |
18 | 18 | |
19 | 19 | |
20 | | -import sys |
21 | | -# sys.path.append('../') |
| 20 | +""" Import python base modules """ |
| 21 | +import sys, matplotlib, datetime, MySQLdb, pylab, HTML, math |
22 | 22 | |
23 | | -import matplotlib |
24 | | -import datetime |
25 | | -import MySQLdb |
26 | | -import pylab |
27 | | -# from matplotlib.lines import Line2D |
28 | | -import HTML |
29 | | -import math |
30 | | - |
| 23 | +""" Import Analytics modules """ |
31 | 24 | import Fundraiser_Tools.classes.QueryData as QD |
32 | 25 | import Fundraiser_Tools.classes.Helper as Hlp |
33 | 26 | import Fundraiser_Tools.classes.TimestampProcessor as TP |
34 | 27 | import Fundraiser_Tools.classes.DataLoader as DL |
35 | 28 | import Fundraiser_Tools.classes.HypothesisTest as HT |
| 29 | +import Fundraiser_Tools.classes.FundraiserDataHandler as FDH |
36 | 30 | |
37 | 31 | |
38 | | -# matplotlib.use('Agg') |
39 | 32 | |
40 | 33 | |
41 | 34 | |
— | — | @@ -245,9 +238,11 @@ |
246 | 239 | for key in kwargs: |
247 | 240 | if key == 'query_type': # Set custom data loaders |
248 | 241 | if kwargs[key] == 'campaign': |
249 | | - self._data_loader_ = DL.CampaignIntervalReportingLoader(kwargs[key]) |
| 242 | + self._data_loader_ = DL.CampaignIntervalReportingLoader() |
250 | 243 | else: |
251 | 244 | self._data_loader_ = DL.IntervalReportingLoader(kwargs[key]) |
| 245 | + elif key == 'was_run': |
| 246 | + self._was_run_ = kwargs[key] |
252 | 247 | |
253 | 248 | """ Call constructor of parent """ |
254 | 249 | DataReporting.__init__(self, **kwargs) |
— | — | @@ -316,7 +311,7 @@ |
317 | 312 | |
318 | 313 | #line_types = ['b-o','g-o','r-o','c-o','m-o','k-o','y-o','b--d','g--d','r--d','c--d','m--d','k--d','y--d','b-.s','g-.s','r-.s','c-.s','m-.s','k-.s','y-.s'] |
319 | 314 | line_types = ['b-o','g-x','r-s','c-d','m-o','k-o','y-o','b--d','g--d','r--d','c--d','m--d','k--d','y--d','b-.s','g-.s','r-.s','c-.s','m-.s','k-.s','y-.s'] |
320 | | - |
| 315 | + |
321 | 316 | count = 0 |
322 | 317 | for key in metrics.keys(): |
323 | 318 | if self._plot_type_ == 'step': |
— | — | @@ -378,13 +373,17 @@ |
379 | 374 | print >> sys.stderr, 'No summary data for this reporting object.\n' |
380 | 375 | return 0 |
381 | 376 | |
| 377 | + """ EXTRACT COLUMN NAMES AND ORDER THEM """ |
| 378 | + |
382 | 379 | data = self._data_loader_._summary_data_ |
383 | 380 | index = self._data_loader_._summary_data_.keys()[0] |
384 | 381 | col_names = self._data_loader_._summary_data_[index].keys() |
385 | 382 | |
386 | | - html = '<table border=\"1\" cellpadding=\"5\"><tr>' |
| 383 | + col_names = FDH.order_column_keys(col_names) |
387 | 384 | |
| 385 | + html = '<table border=\"1\" cellpadding=\"10\"><tr>' |
388 | 386 | |
| 387 | + |
389 | 388 | """ Build headers """ |
390 | 389 | html = html + '<th>' + self._data_loader_._query_type_ + '</th>' |
391 | 390 | for i in col_names: |
— | — | @@ -396,8 +395,8 @@ |
397 | 396 | for item in data.keys(): |
398 | 397 | html = html + '<tr>' |
399 | 398 | html = html + '<td>' + item + '</td>' |
400 | | - for elem in data[item].keys(): |
401 | | - html = html + '<td>' + str(data[item][elem]) + '</td>' |
| 399 | + for elem in col_names: |
| 400 | + html = html + '<td>' + QD.get_metric_data_type(elem,data[item][elem]) + '</td>' |
402 | 401 | html = html + '</tr>' |
403 | 402 | |
404 | 403 | html = html + '</table>' |
— | — | @@ -433,10 +432,10 @@ |
434 | 433 | for key in self._times_.keys(): |
435 | 434 | self._times_[key] = TP.normalize_timestamps(self._times_[key], False, 3) |
436 | 435 | self._times_[key], self._counts_[key] = TP.normalize_intervals(self._times_[key], self._counts_[key], interval) |
437 | | - |
| 436 | + |
438 | 437 | """ If there are missing metrics add them as zeros """ |
439 | 438 | for label in labels: |
440 | | - |
| 439 | + |
441 | 440 | if not(label in self._times_.keys()): |
442 | 441 | self._times_[label] = self._times_[self._times_.keys()[0]] |
443 | 442 | self._counts_[label] = [0.0] * len(self._times_[label]) |
— | — | @@ -772,7 +771,7 @@ |
773 | 772 | test_call = "run('" + test_name + "', '" + query_name + "', '" + metric_name + "', '" + campaign + "', '" + \ |
774 | 773 | item_1 + "', '" + item_2 + "', '" + start_time + "', '" + end_time + "', " + str(interval) + ", " + str(num_samples) + ")" |
775 | 774 | winner, percent_increase = self.print_metrics(fname, title, means_1, means_2, std_devs_1, std_devs_2, times_indices, labels, test_call) |
776 | | - |
| 775 | + |
777 | 776 | return [winner, percent_increase, confidence] |
778 | 777 | |
779 | 778 | |