r87280 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87279‎ | r87280 | r87281 >
Date:19:16, 2 May 2011
Author:rfaulk
Status:deferred
Tags:
Comment:
- Maintenance: Added documentation in places
- removed redundant 'get_sql_filename_for_query' method from 'IntervalReportingLoader' class. This method is implemented in the Base class
- Added 'CampaignReportingLoader' class for handling results relating to campaigns
Modified paths:
  • /trunk/fundraiser-statistics/fundraiser-scripts/classes/DataLoader.py (modified) (history)

Diff [purge]

Index: trunk/fundraiser-statistics/fundraiser-scripts/classes/DataLoader.py
@@ -16,24 +16,32 @@
1717
1818
1919 import sys
20 -sys.path.append('../')
 20+# sys.path.append('../')
2121
2222 import MySQLdb
2323 import math
2424 import datetime
2525 import re # regular expression matching
2626
27 -import miner_help as mh
28 -import QueryData as QD
29 -import TimestampProcessor as TP
 27+import Fundraiser_Tools.miner_help as mh
 28+import Fundraiser_Tools.classes.QueryData as QD
 29+import Fundraiser_Tools.classes.TimestampProcessor as TP
3030
3131 """
3232
33 - CLASS :: DataLoader
 33+ BASE CLASS :: DataLoader
3434
 35+ This is the base class for data handling functionality of metrics.
 36+
3537 METHODS:
36 - init_db -
37 - close_db -
 38+ init_db
 39+ close_db
 40+ compose_key
 41+ include_keys
 42+ exclude_keys
 43+ get_sql_filename_for_query
 44+
 45+
3846 """
3947 class DataLoader(object):
4048
@@ -179,9 +187,6 @@
180188 self._query_names_['campaign'] = 'report_campaign_metrics_minutely'
181189 self._query_names_['campaign_total'] = 'report_campaign_metrics_minutely_total'
182190
183 - def get_sql_filename_for_query(self, query_type):
184 - return self._query_names_[query_type]
185 -
186191 """
187192 <DESCRIPTION>
188193
@@ -300,6 +305,7 @@
301306
302307 return [metrics, times]
303308
 309+
304310 """
305311
306312
@@ -344,7 +350,18 @@
345351
346352 return [metrics, times]
347353
 354+
 355+"""
 356+
 357+ CLASS :: BannerLPReportingLoader
348358
 359+ This dataloader handles reporting on banners and landing pages.
 360+
 361+ METHODS:
 362+ run_query
 363+
 364+
 365+"""
349366 class BannerLPReportingLoader(DataLoader):
350367
351368 def run_query(self):
@@ -437,8 +454,94 @@
438455 # return the metric values at each time
439456 return [metrics_1, metrics_2, times_indices]
440457
 458+
 459+"""
 460+
 461+ CLASS :: CampaignReportingLoader
441462
 463+ This dataloader handles reporting on utm_campaigns.
 464+
 465+ METHODS:
 466+ run_query
 467+
 468+
 469+"""
 470+class CampaignReportingLoader(DataLoader):
 471+
 472+ def __init__(self):
 473+ self._query_names_['totals'] = 'report_campaign_totals'
 474+ self._query_names_['times'] = 'report_campaign_times'
 475+
 476+ """
 477+ !! MODIFY -- use python reflection !! ... maybe
 478+
 479+ This method is retrieving campaign names
 480+
 481+ delegates the procesing to different methods
 482+
 483+ """
 484+ def run_query(self, query_type, params):
 485+
 486+ self.init_db()
 487+
 488+ if query_type == 'totals':
 489+ data = self.query_totals(query_type, params)
 490+
 491+ self.close_db()
 492+
 493+ return data
 494+
 495+ """
 496+
 497+ Handle queries from "report_campaign_totals"
 498+
 499+ """
 500+ def query_totals(self, query_type, params):
 501+
 502+ """ Resolve parameters """
 503+ metric_name = params['metric_name']
 504+ start_time = params['start_time']
 505+ end_time = params['end_time']
 506+
 507+ query_name = self.get_sql_filename_for_query(query_type)
 508+
 509+ """ Load the SQL File & Format """
 510+ filename = self._sql_path_+ query_name + '.sql'
 511+ sql_stmnt = mh.read_sql(filename)
 512+ sql_stmnt = QD.format_query(query_name, sql_stmnt, [start_time, end_time])
 513+
 514+ """ Get Indexes into Query """
 515+ key_index = QD.get_key_index(query_name)
 516+ metric_index = QD.get_metric_index(query_name, metric_name)
 517+
 518+ data = mh.AutoVivification()
 519+
 520+ """ Compose the data for each separate donor pipeline artifact """
 521+ try:
 522+
 523+ self._cur_.execute(sql_stmnt)
 524+
 525+ results = self._cur_.fetchall()
 526+
 527+ for row in results:
 528+
 529+ key_name = row[key_index]
 530+ data[key_name] = float(row[metric_index])
 531+
 532+
 533+ except Exception as inst:
 534+ print type(inst) # the exception instance
 535+ print inst.args # arguments stored in .args
 536+ print inst # __str__ allows args to printed directly
 537+
 538+ self._db_.rollback()
 539+ sys.exit(0)
442540
 541+
 542+ return data
 543+
 544+
 545+
443546 """
444547
445548 CLASS :: TTestLoaderHelp

Status & tagging log