src/dirbs/reports/stats_generator.py
def _calc_daily_imei_imsi_overloading(db_config, month, year, operator=None, bin_width=0.1, _min_seen_days=5):
    """Helper function to determine average IMEI-IMSI overloading for a year, month and operator."""
    with utils.create_db_connection(db_config) as conn, conn.cursor() as cursor, utils.CodeProfiler() as cp:
        network_triplets_partition = _monthly_network_triplets_partition(conn=conn, operator=operator,
                                                                         month=month, year=year)
        cursor.execute(
            sql.SQL("""SELECT COUNT(*) AS num_imeis,
                              (bin_id * %(bin_width)s)::REAL AS bin_start,
                              ((bin_id + 1) * %(bin_width)s)::REAL AS bin_end
                         FROM (SELECT imei_norm,
                                      FLOOR(SUM(bitcount(combined_date_bitmask))::NUMERIC/
                                      bitcount(bit_or(combined_date_bitmask))/%(bin_width)s)::INT AS bin_id
                                 FROM (SELECT imei_norm,
                                              imsi,
                                              bit_or(date_bitmask) AS combined_date_bitmask
                                         FROM {0}
                                        WHERE imei_norm IS NOT NULL
                                          AND is_valid_imsi(imsi)
                                     GROUP BY imei_norm, imsi) all_imei_imsis
                             GROUP BY imei_norm
                                      HAVING bitcount(bit_or(combined_date_bitmask)) >= %(min_seen_days)s ) histogram
                     GROUP BY bin_id""").format(network_triplets_partition),  # noqa: Q447
            {'bin_width': bin_width, 'min_seen_days': _min_seen_days}
        )
        results = [{'num_imeis': r.num_imeis,
                    'bin_start': r.bin_start,
                    'bin_end': r.bin_end} for r in cursor]
    return results, cp.duration, [cp.duration]
Helper function to determine average IMEI-IMSI overloading for a year, month and operator.
Helper function to determine average IMEI-IMSI overloading for a year, month and operator.
Helper function to determine average IMEI - IMSI overloading for a year month and operator .
def _calc_daily_imei_imsi_overloading(db_config, month, year, operator=None, bin_width=0.1, _min_seen_days=5):
    with utils.create_db_connection(db_config) as conn, conn.cursor() as cursor, utils.CodeProfiler() as cp:
        network_triplets_partition = _monthly_network_triplets_partition(conn=conn, operator=operator,
                                                                         month=month, year=year)
        cursor.execute(
            sql.SQL("""SELECT COUNT(*) AS num_imeis,
                              (bin_id * %(bin_width)s)::REAL AS bin_start,
                              ((bin_id + 1) * %(bin_width)s)::REAL AS bin_end
                         FROM (SELECT imei_norm,
                                      FLOOR(SUM(bitcount(combined_date_bitmask))::NUMERIC/
                                      bitcount(bit_or(combined_date_bitmask))/%(bin_width)s)::INT AS bin_id
                                 FROM (SELECT imei_norm,
                                              imsi,
                                              bit_or(date_bitmask) AS combined_date_bitmask
                                         FROM {0}
                                        WHERE imei_norm IS NOT NULL
                                          AND is_valid_imsi(imsi)
                                     GROUP BY imei_norm, imsi) all_imei_imsis
                             GROUP BY imei_norm
                                      HAVING bitcount(bit_or(combined_date_bitmask)) >= %(min_seen_days)s ) histogram
                     GROUP BY bin_id""").format(network_triplets_partition),  
            {'bin_width': bin_width, 'min_seen_days': _min_seen_days}
        )
        results = [{'num_imeis': r.num_imeis,
                    'bin_start': r.bin_start,
                    'bin_end': r.bin_end} for r in cursor]
    return results, cp.duration, [cp.duration]
def _calc_daily_imei_imsi_overloading ( db_config , month , year , operator = None , bin_width = 0.1 , _min_seen_days = 5 ) : with utils . create_db_connection ( db_config ) as conn , conn . cursor ( ) as cursor , utils . CodeProfiler ( ) as cp : network_triplets_partition = _monthly_network_triplets_partition ( conn = conn , operator = operator , month = month , year = year ) cursor . execute ( sql . SQL ( """SELECT COUNT(*) AS num_imeis,
                              (bin_id * %(bin_width)s)::REAL AS bin_start,
                              ((bin_id + 1) * %(bin_width)s)::REAL AS bin_end
                         FROM (SELECT imei_norm,
                                      FLOOR(SUM(bitcount(combined_date_bitmask))::NUMERIC/
                                      bitcount(bit_or(combined_date_bitmask))/%(bin_width)s)::INT AS bin_id
                                 FROM (SELECT imei_norm,
                                              imsi,
                                              bit_or(date_bitmask) AS combined_date_bitmask
                                         FROM {0}
                                        WHERE imei_norm IS NOT NULL
                                          AND is_valid_imsi(imsi)
                                     GROUP BY imei_norm, imsi) all_imei_imsis
                             GROUP BY imei_norm
                                      HAVING bitcount(bit_or(combined_date_bitmask)) >= %(min_seen_days)s ) histogram
                     GROUP BY bin_id""" ) . format ( network_triplets_partition ) , { 'bin_width' : bin_width , 'min_seen_days' : _min_seen_days } ) results = [ { 'num_imeis' : r . num_imeis , 'bin_start' : r . bin_start , 'bin_end' : r . bin_end } for r in cursor ] return results , cp . duration , [ cp . duration ]
Helper function to determine average IMEI-IMSI overloading for a year, month and operator.
Helper function to determine average IMEI - IMSI overloading for a year month and operator .
"""Helper function to determine average IMEI-IMSI overloading for a year, month and operator.""" # noqa: Q447
db_config
month
year
operator
bin_width
_min_seen_days