Index: trunk/fundraiser-statistics/fundraiser-scripts/classes/DataLoader.py |
— | — | @@ -73,6 +73,8 @@ |
74 | 74 | def __init__(self): |
75 | 75 | self._query_names_['banner'] = 'report_banner_metrics_minutely' |
76 | 76 | self._query_names_['LP'] = 'report_LP_metrics_minutely' |
| 77 | + self._query_names_['campaign'] = 'report_campaign_metrics_minutely' |
| 78 | + self._query_names_['campaign_total'] = 'report_campaign_metrics_minutely_total' |
77 | 79 | |
78 | 80 | def get_sql_filename_for_query(self, query_type): |
79 | 81 | return self._query_names_[query_type] |
— | — | @@ -81,17 +83,17 @@ |
82 | 84 | <DESCRIPTION> |
83 | 85 | |
84 | 86 | INPUT: |
85 | | - start_time - |
86 | | - end_time - |
87 | | - interval - |
88 | | - query_type - |
89 | | - metric_name - |
90 | | - campaign - |
| 87 | + start_time - start timestamp for reporting |
| 88 | + end_time - end timestamp for reporting |
| 89 | + interval - minutely interval at which to report metrics |
| 90 | + query_type - query type: 'banner', 'campaign', 'LP' |
| 91 | + metric_name - the metric to report |
| 92 | + campaign - the campaign on which to select |
91 | 93 | |
92 | 94 | |
93 | 95 | RETURN: |
94 | | - metrics - |
95 | | - times - |
| 96 | + metrics - dict containing metric measure for each time index for each donation pipeline handle (e.g. banner names) |
| 97 | + times - dict containing time index for each donation pipeline handle (e.g. banner names) |
96 | 98 | """ |
97 | 99 | def run_query(self, start_time, end_time, interval, query_type, metric_name, campaign): |
98 | 100 | |
— | — | @@ -119,16 +121,13 @@ |
120 | 122 | |
121 | 123 | |
122 | 124 | """ Load the SQL File & Format """ |
123 | | - filename = self._sql_path_ + query_name + '.sql' |
| 125 | + filename = self._sql_path_+ query_name + '.sql' |
124 | 126 | sql_stmnt = mh.read_sql(filename) |
125 | 127 | |
126 | 128 | sql_stmnt = QD.format_query(query_name, sql_stmnt, [start_time, end_time, campaign, interval]) |
127 | 129 | |
128 | 130 | """ Get Indexes into Query """ |
129 | | - if query_type == 'banner': |
130 | | - key_index = QD.get_banner_index(query_name) |
131 | | - if query_type == 'LP': |
132 | | - key_index = QD.get_landing_page_index(query_name) |
| 131 | + key_index = QD.get_key_index(query_name) |
133 | 132 | |
134 | 133 | metric_index = QD.get_metric_index(query_name, metric_name) |
135 | 134 | time_index = QD.get_time_index(query_name) |
— | — | @@ -181,7 +180,6 @@ |
182 | 181 | self._db_.rollback() |
183 | 182 | sys.exit(0) |
184 | 183 | |
185 | | - |
186 | 184 | |
187 | 185 | """ Ensure that the last time in the list is the endtime less the interval """ |
188 | 186 | for key in times.keys(): |
— | — | @@ -200,7 +198,51 @@ |
201 | 199 | metrics[key] = metrics_new |
202 | 200 | |
203 | 201 | return [metrics, times] |
| 202 | + |
| 203 | +""" |
| 204 | + |
| 205 | + |
| 206 | +""" |
| 207 | +class CampaignIntervalReportingLoader(IntervalReportingLoader): |
204 | 208 | |
| 209 | + def __init__(self): |
| 210 | + IntervalReportingLoader.__init__(self) |
| 211 | + |
| 212 | + """ |
| 213 | + <DESCRIPTION> |
| 214 | + |
| 215 | + INPUT: |
| 216 | + start_time - start timestamp for reporting |
| 217 | + end_time - end timestamp for reporting |
| 218 | + interval - minutely interval at which to report metrics |
| 219 | + query_type - query type: 'banner', 'campaign', 'LP' |
| 220 | + metric_name - the metric to report |
| 221 | + campaign - the campaign on which to select |
| 222 | + |
| 223 | + |
| 224 | + RETURN: |
| 225 | + metrics - dict containing metric measure for each time index for each donation pipeline handle (e.g. banner names) |
| 226 | + times - dict containing time index for each donation pipeline handle (e.g. banner names) |
| 227 | + """ |
| 228 | + def run_query(self, start_time, end_time, interval, query_type, metric_name, campaign): |
| 229 | + |
| 230 | + query_type_1 = 'campaign' |
| 231 | + query_type_2 = 'campaign_total' |
| 232 | + |
| 233 | + """ Execute the standard interval reporting query """ |
| 234 | + metrics, times = IntervalReportingLoader.run_query(self, start_time, end_time, interval, query_type_1, metric_name, campaign) |
| 235 | + |
| 236 | + """ Get the totals for campaign views and donations """ |
| 237 | + metrics_total, times_total = IntervalReportingLoader.run_query(self, start_time, end_time, interval, query_type_2, metric_name, campaign) |
| 238 | + |
| 239 | + """ Combine the results for the campaign totals with (banner, landing page, campaign) """ |
| 240 | + for key in metrics_total.keys(): |
| 241 | + metrics[key] = metrics_total[key] |
| 242 | + times[key] = times_total[key] |
| 243 | + |
| 244 | + |
| 245 | + return [metrics, times] |
| 246 | + |
205 | 247 | |
206 | 248 | class BannerLPReportingLoader(DataLoader): |
207 | 249 | |