src/dirbs/reports/stats_generator.py
def _calc_imei_gross_adds(db_config, operators, month, year):
    """Helper function to calculate IMEI gross adds."""
    with utils.create_db_connection(db_config) as conn, conn.cursor() as cursor, utils.CodeProfiler() as cp:
        start_date, end_date = _calc_date_range(month, year)
        all_operators = copy.copy(operators)
        all_operators.append(None)  # For country -- _monthly_network_triplets_partition will return country partition
        results = defaultdict(dict)
        for op in all_operators:
            network_triplets_partition = _monthly_network_triplets_partition(conn=conn, operator=op,
                                                                             month=month, year=year)
            cursor.execute(
                sql.SQL("""SELECT COUNT(*) AS num_gross_adds
                             FROM network_imeis
                            WHERE network_imeis.first_seen >= %s
                              AND network_imeis.first_seen < %s
                              AND EXISTS (SELECT 1
                                            FROM {0}
                                           WHERE imei_norm = network_imeis.imei_norm)
                        """).format(network_triplets_partition),
                [start_date, end_date]
            )
            if op is None:
                op = OperatorConfig.COUNTRY_OPERATOR_NAME
            results[op]['num_gross_adds'] = cursor.fetchone().num_gross_adds

    return _defaultdict_to_regular(results), cp.duration, [cp.duration]
Helper function to calculate IMEI gross adds.
Helper function to calculate IMEI gross adds.
Helper function to calculate IMEI gross adds .
def _calc_imei_gross_adds(db_config, operators, month, year):
    with utils.create_db_connection(db_config) as conn, conn.cursor() as cursor, utils.CodeProfiler() as cp:
        start_date, end_date = _calc_date_range(month, year)
        all_operators = copy.copy(operators)
        all_operators.append(None)  
        results = defaultdict(dict)
        for op in all_operators:
            network_triplets_partition = _monthly_network_triplets_partition(conn=conn, operator=op,
                                                                             month=month, year=year)
            cursor.execute(
                sql.SQL("""SELECT COUNT(*) AS num_gross_adds
                             FROM network_imeis
                            WHERE network_imeis.first_seen >= %s
                              AND network_imeis.first_seen < %s
                              AND EXISTS (SELECT 1
                                            FROM {0}
                                           WHERE imei_norm = network_imeis.imei_norm)
                        """).format(network_triplets_partition),
                [start_date, end_date]
            )
            if op is None:
                op = OperatorConfig.COUNTRY_OPERATOR_NAME
            results[op]['num_gross_adds'] = cursor.fetchone().num_gross_adds
    return _defaultdict_to_regular(results), cp.duration, [cp.duration]
def _calc_imei_gross_adds ( db_config , operators , month , year ) : with utils . create_db_connection ( db_config ) as conn , conn . cursor ( ) as cursor , utils . CodeProfiler ( ) as cp : start_date , end_date = _calc_date_range ( month , year ) all_operators = copy . copy ( operators ) all_operators . append ( None ) results = defaultdict ( dict ) for op in all_operators : network_triplets_partition = _monthly_network_triplets_partition ( conn = conn , operator = op , month = month , year = year ) cursor . execute ( sql . SQL ( """SELECT COUNT(*) AS num_gross_adds
                             FROM network_imeis
                            WHERE network_imeis.first_seen >= %s
                              AND network_imeis.first_seen < %s
                              AND EXISTS (SELECT 1
                                            FROM {0}
                                           WHERE imei_norm = network_imeis.imei_norm)
                        """ ) . format ( network_triplets_partition ) , [ start_date , end_date ] ) if op is None : op = OperatorConfig . COUNTRY_OPERATOR_NAME results [ op ] [ 'num_gross_adds' ] = cursor . fetchone ( ) . num_gross_adds return _defaultdict_to_regular ( results ) , cp . duration , [ cp . duration ]
Helper function to calculate IMEI gross adds.
Helper function to calculate IMEI gross adds .
"""Helper function to calculate IMEI gross adds.""" # For country -- _monthly_network_triplets_partition will return country partition
db_config
operators
month
year