def main(args): user = projSet.__system_user__ cmd_pattern = 'run_cache_fundraiser_totals' sm = SM.SystemMonitor() if sm.check_for_process_in_PIDfile(user, cmd_pattern): try: ft_dc = DC.Fundraiser_Totals_DataCaching() ft_dc.execute_process(view_keys.FR_TOT_DICT_KEY) sm.remove_process_from_PIDfile(user, cmd_pattern) except Exception as inst: logging.info('Unable to produce fundraising totals: %s' % str(inst)) finally: sm.remove_process_from_PIDfile(user, cmd_pattern) else: logging.info( 'Process for "run_cache_fundraiser_totals" is already running.') return 0
def long_term_trends(request): cache = DC.LTT_DataCaching() dict_param = cache.retrieve_cached_data(view_keys.LTT_DICT_KEY) return render_to_response('live_results/long_term_trends.html', dict_param, context_instance=RequestContext(request))
def fundraiser_totals(request): cache = DC.Fundraiser_Totals_DataCaching() data = cache.retrieve_cached_data(view_keys.FR_TOT_DICT_KEY) dict_param = data['Total'] dict_param['err_msg'] = '' dict_param['country'] = 'Total' return render_to_response('live_results/fundraiser_totals.html', dict_param, context_instance=RequestContext(request))
def fundraiser_totals_cntry(request, country): cache = DC.Fundraiser_Totals_DataCaching() data = cache.retrieve_cached_data(view_keys.FR_TOT_DICT_KEY) try: dict_param_country = data[country] dict_param_country['err_msg'] = '' dict_param_country['country'] = country return render_to_response('live_results/fundraiser_totals.html', dict_param_country, context_instance=RequestContext(request)) except: dict_param = data['Total'] dict_param['err_msg'] = 'Could not find totals for that country.' dict_param['country'] = 'Total' return render_to_response('live_results/fundraiser_totals.html', dict_param, context_instance=RequestContext(request))
def main(args): user = projSet.__system_user__ cmd_pattern = 'run_cache_live_results' sm = SM.SystemMonitor() if sm.check_for_process_in_PIDfile(user, cmd_pattern): try: lr_dc = DC.LiveResults_DataCaching() lr_dc.execute_process(view_keys.LIVE_RESULTS_DICT_KEY) sm.remove_process_from_PIDfile(user, cmd_pattern) except Exception as inst: logging.info('Unable to produce live results: %s' % str(inst)) finally: sm.remove_process_from_PIDfile(user, cmd_pattern) else: logging.info('Process for "run_cache_live_results" is already running.') return 0
def index(request): """ PROCESS POST DATA ================= Escape all user input that can be entered in text fields """ try: campaign_regexp_filter = MySQLdb._mysql.escape_string( request.POST['campaign_regexp_filter']) if cmp(campaign_regexp_filter, '') == 0: campaign_regexp_filter = '^C_|^C11_' except: campaign_regexp_filter = '^C_|^C11_' try: min_donation = MySQLdb._mysql.escape_string( request.POST['min_donation'].strip()) min_donation = int(min_donation) except: min_donation = 0 # Filter on ISO codes to include matched countries try: iso_filter = MySQLdb._mysql.escape_string( request.POST['iso_filter'].strip()) except: iso_filter = '.{2}' """ Call up cached results """ cache = DC.LiveResults_DataCaching() dict_param = cache.retrieve_cached_data(view_keys.LIVE_RESULTS_DICT_KEY) measured_metrics_counts = dict_param['measured_metrics_counts'] results = dict_param['results'] column_names = dict_param['column_names'] sampling_interval = dict_param['interval'] duration_hrs = dict_param['duration'] start_time = dict_param['start_time'] end_time = dict_param['end_time'] ir_cmpgn = DR.IntervalReporting(query_type=FDH._QTYPE_CAMPAIGN_ + FDH._QTYPE_TIME_, generate_plot=False) ir_banner = DR.IntervalReporting(query_type=FDH._QTYPE_BANNER_ + FDH._QTYPE_TIME_, generate_plot=False) ir_lp = DR.IntervalReporting(query_type=FDH._QTYPE_LP_ + FDH._QTYPE_TIME_, generate_plot=False) ir_cmpgn._counts_ = dict_param['ir_cmpgn_counts'] ir_banner._counts_ = dict_param['ir_banner_counts'] ir_lp._counts_ = dict_param['ir_lp_counts'] ir_cmpgn._times_ = dict_param['ir_cmpgn_times'] ir_banner._times_ = dict_param['ir_banner_times'] ir_lp._times_ = dict_param['ir_lp_times'] metric_legend_table = dict_param['metric_legend_table'] conf_legend_table = dict_param['conf_legend_table'] """ Filtering -- donations and artifacts """ country_index = column_names.index('country') donations_index = column_names.index('donations') campaign_index = column_names.index('utm_campaign') new_results = list() # minimum d for row in results: try: if row[donations_index] > min_donation and re.search( campaign_regexp_filter, row[campaign_index]) and re.search( iso_filter, row[country_index]): new_results.append(list(row)) except: logging.error( 'live_results/views.py -- Could not process row: %s' % str(row)) results = new_results new_measured_metrics_counts = dict() for metric in measured_metrics_counts: new_measured_metrics_counts[metric] = dict() for artifact_key in measured_metrics_counts[metric]: if re.search(campaign_regexp_filter, artifact_key): new_measured_metrics_counts[metric][ artifact_key] = measured_metrics_counts[metric][ artifact_key] """ Format results to encode html table cell markup in results """ ret = DR.ConfidenceReporting( query_type='', hyp_test='').get_confidence_on_time_range( None, None, None, measured_metrics_counts=new_measured_metrics_counts ) # first get color codes on confidence conf_colour_code = ret[0] for row_index in range(len(results)): artifact_index = results[row_index][0] + '-' + results[row_index][ 1] + '-' + results[row_index][2] for col_index in range(len(column_names)): is_coloured_cell = False if column_names[col_index] in conf_colour_code.keys(): if artifact_index in conf_colour_code[ column_names[col_index]].keys(): results[row_index][ col_index] = '<td style="background-color:' + conf_colour_code[ column_names[col_index]][ artifact_index] + ';">' + str( results[row_index][col_index]) + '</td>' is_coloured_cell = True if not (is_coloured_cell): results[row_index][col_index] = '<td>' + str( results[row_index][col_index]) + '</td>' if results: summary_table = DR.DataReporting()._write_html_table( results, column_names, use_standard_metric_names=True, omit_cell_markup=True) else: summary_table = '<p><font size="4">No data available.</font></p>' summary_table = '<h4><u>Metrics Legend:</u></h4><div class="spacer"></div>' + metric_legend_table + \ '<div class="spacer"></div><h4><u>Confidence Legend for Hypothesis Testing:</u></h4><div class="spacer"></div>' + conf_legend_table + '<div class="spacer"></div><div class="spacer"></div>' + summary_table """ Prepare Live Plots """ """ compose a list of zero data """ empty_data = [[1.0, 0.0]] * (duration_hrs * 60 / sampling_interval + 1) for i in range(len(empty_data)): empty_data[i][0] = empty_data[i][0] * i * sampling_interval """ Extract data from interval reporting objects """ cmpgn_data_dict = ir_cmpgn.get_data_lists( ['C_', 'C11_', campaign_regexp_filter], empty_data) cmpgn_banner_dict = ir_banner.get_data_lists(['B_', 'B11_'], empty_data) cmpgn_lp_dict = ir_lp.get_data_lists(['L11_', '^cc'], empty_data) """ Build template parameters """ template_dict = Hlp.combine_data_lists( [cmpgn_data_dict, cmpgn_banner_dict, cmpgn_lp_dict]) # combine the separate data sets template_dict['summary_table'] = summary_table template_dict['latest_log_end_time'] = end_time template_dict['start_time'] = start_time return render_to_response('live_results/index.html', template_dict, context_instance=RequestContext(request))