src/dirbs/reports/stats_generator.py
def generate_monthly_report_stats(config, conn, month, year, statsd, metrics_run_root, run_id, refresh_data=True,
                                  debug_query_performance=False):
    """Either generates stats for the reports or returns the data_id to use when using cached data."""
    logger = logging.getLogger('dirbs.report')
    with conn.cursor() as cursor:
        # First, look for any existing report data for this month
        cursor.execute("""SELECT rdm.data_id,
                                 rdm.class_run_id
                            FROM report_data_metadata rdm
                            JOIN (SELECT MAX(data_id) AS data_id
                                    FROM report_data_metadata
                                   WHERE report_month = %s
                                     AND report_year = %s
                                     AND data_schema_version = %s) latest_data_id
                           USING (data_id)""",
                       [month, year, report_schema_version])
        result = cursor.fetchone()
        if result:
            data_id, class_run_id = result
        else:
            data_id, class_run_id = (None, None)

        # Commit connection here to prevent long-running transaction
        conn.commit()
        per_tac_compliance_data = None
        statsd.gauge('{0}refreshed_data'.format(metrics_run_root), int(refresh_data or not data_id))
        if not data_id or refresh_data:
            # If we don't have data for this month or we asked to generate new data, create a new entry in
            # report_metadata
            logger.info('No data previously generated for this month or refresh requested')
            data_id, class_run_id, per_tac_compliance_data = _refresh_data(config, conn, month, year, statsd,
                                                                           metrics_run_root, run_id,
                                                                           debug_query_performance)
            # Commit the connection so we can re-use this data even if subsequent operations fail
            conn.commit()
        else:
            logger.info('Previous report data detected for this month. Re-generating report using that data')
        return data_id, class_run_id, per_tac_compliance_data
Either generates stats for the reports or returns the data_id to use when using cached data.
Either generates stats for the reports or returns the data_id to use when using cached data.
Either generates stats for the reports or returns the data_id to use when using cached data .
def generate_monthly_report_stats(config, conn, month, year, statsd, metrics_run_root, run_id, refresh_data=True,
                                  debug_query_performance=False):
    logger = logging.getLogger('dirbs.report')
    with conn.cursor() as cursor:
        cursor.execute("""SELECT rdm.data_id,
                                 rdm.class_run_id
                            FROM report_data_metadata rdm
                            JOIN (SELECT MAX(data_id) AS data_id
                                    FROM report_data_metadata
                                   WHERE report_month = %s
                                     AND report_year = %s
                                     AND data_schema_version = %s) latest_data_id
                           USING (data_id)""",
                       [month, year, report_schema_version])
        result = cursor.fetchone()
        if result:
            data_id, class_run_id = result
        else:
            data_id, class_run_id = (None, None)
        conn.commit()
        per_tac_compliance_data = None
        statsd.gauge('{0}refreshed_data'.format(metrics_run_root), int(refresh_data or not data_id))
        if not data_id or refresh_data:
            logger.info('No data previously generated for this month or refresh requested')
            data_id, class_run_id, per_tac_compliance_data = _refresh_data(config, conn, month, year, statsd,
                                                                           metrics_run_root, run_id,
                                                                           debug_query_performance)
            conn.commit()
        else:
            logger.info('Previous report data detected for this month. Re-generating report using that data')
        return data_id, class_run_id, per_tac_compliance_data
def generate_monthly_report_stats ( config , conn , month , year , statsd , metrics_run_root , run_id , refresh_data = True , debug_query_performance = False ) : logger = logging . getLogger ( 'dirbs.report' ) with conn . cursor ( ) as cursor : cursor . execute ( """SELECT rdm.data_id,
                                 rdm.class_run_id
                            FROM report_data_metadata rdm
                            JOIN (SELECT MAX(data_id) AS data_id
                                    FROM report_data_metadata
                                   WHERE report_month = %s
                                     AND report_year = %s
                                     AND data_schema_version = %s) latest_data_id
                           USING (data_id)""" , [ month , year , report_schema_version ] ) result = cursor . fetchone ( ) if result : data_id , class_run_id = result else : data_id , class_run_id = ( None , None ) conn . commit ( ) per_tac_compliance_data = None statsd . gauge ( '{0}refreshed_data' . format ( metrics_run_root ) , int ( refresh_data or not data_id ) ) if not data_id or refresh_data : logger . info ( 'No data previously generated for this month or refresh requested' ) data_id , class_run_id , per_tac_compliance_data = _refresh_data ( config , conn , month , year , statsd , metrics_run_root , run_id , debug_query_performance ) conn . commit ( ) else : logger . info ( 'Previous report data detected for this month. Re-generating report using that data' ) return data_id , class_run_id , per_tac_compliance_data
Either generates stats for the reports or returns the data_id to use when using cached data.
Either generates stats for the reports or returns the data_id to use when using cached data .
"""Either generates stats for the reports or returns the data_id to use when using cached data.""" # First, look for any existing report data for this month # Commit connection here to prevent long-running transaction # If we don't have data for this month or we asked to generate new data, create a new entry in # report_metadata # Commit the connection so we can re-use this data even if subsequent operations fail
config
conn
month
year
statsd
metrics_run_root
run_id
refresh_data
debug_query_performance