src/dirbs/reports/csv_reports.py
def write_country_duplicates_report(conn: callable, config: callable, month: int, year: int,
                                    country_name: str, output_dir: str, imsi_min_limit: int = 5) -> callable:
    """
    Helper function to write out the country-wide duplicates report.

    Arguments:
        conn: DIRBS PostgreSQL connection object
        config: DIRBS config object
        month: month of the report
        year: year of the report
        country_name: name of the country
        output_dir: output directory path
        imsi_min_limit: minimum IMSI limit (default 5)
    Returns:
        Reports metadata
    """
    duplicates_csv_filename = '{0}_{1:d}_{2:d}_duplicates.csv'.format(country_name, month, year)
    with open(os.path.join(output_dir, duplicates_csv_filename), 'w', encoding='utf8') as of:
        writer = csv.writer(of)
        writer.writerow(['IMEI', 'IMSI count'])
        # We can't use our normal duplicate dimension here as it doesn't give the limits, so unfortunately,
        # we have to use a modified query that is also slightly optimized as it can query using triplet_year
        # and triplet_month
        with conn.cursor(name='duplicates_report') as cursor:
            cursor.execute("""SELECT imei_norm,
                                     COUNT(*) AS imsi_count
                                FROM (SELECT DISTINCT imei_norm, imsi
                                        FROM monthly_network_triplets_country_no_null_imeis
                                       WHERE triplet_month = %s
                                         AND triplet_year = %s
                                         AND is_valid_imsi(imsi)) all_network_imei_imsis
                            GROUP BY imei_norm HAVING COUNT(*) >= %s
                            ORDER BY imsi_count DESC""",
                           [month, year, imsi_min_limit])
            for res in cursor:
                writer.writerow([res.imei_norm, res.imsi_count])

    return _gen_metadata_for_reports([duplicates_csv_filename], output_dir)

    Helper function to write out the country-wide duplicates report.

    Arguments:
        conn: DIRBS PostgreSQL connection object
        config: DIRBS config object
        month: month of the report
        year: year of the report
        country_name: name of the country
        output_dir: output directory path
        imsi_min_limit: minimum IMSI limit (default 5)
    Returns:
        Reports metadata
    
Helper function to write out the country-wide duplicates report.
Helper function to write out the country - wide duplicates report .
def write_country_duplicates_report(conn: callable, config: callable, month: int, year: int,
                                    country_name: str, output_dir: str, imsi_min_limit: int = 5) -> callable:
    duplicates_csv_filename = '{0}_{1:d}_{2:d}_duplicates.csv'.format(country_name, month, year)
    with open(os.path.join(output_dir, duplicates_csv_filename), 'w', encoding='utf8') as of:
        writer = csv.writer(of)
        writer.writerow(['IMEI', 'IMSI count'])
        with conn.cursor(name='duplicates_report') as cursor:
            cursor.execute("""SELECT imei_norm,
                                     COUNT(*) AS imsi_count
                                FROM (SELECT DISTINCT imei_norm, imsi
                                        FROM monthly_network_triplets_country_no_null_imeis
                                       WHERE triplet_month = %s
                                         AND triplet_year = %s
                                         AND is_valid_imsi(imsi)) all_network_imei_imsis
                            GROUP BY imei_norm HAVING COUNT(*) >= %s
                            ORDER BY imsi_count DESC""",
                           [month, year, imsi_min_limit])
            for res in cursor:
                writer.writerow([res.imei_norm, res.imsi_count])
    return _gen_metadata_for_reports([duplicates_csv_filename], output_dir)
def write_country_duplicates_report ( conn : callable , config : callable , month : int , year : int , country_name : str , output_dir : str , imsi_min_limit : int = 5 ) -> callable : duplicates_csv_filename = '{0}_{1:d}_{2:d}_duplicates.csv' . format ( country_name , month , year ) with open ( os . path . join ( output_dir , duplicates_csv_filename ) , 'w' , encoding = 'utf8' ) as of : writer = csv . writer ( of ) writer . writerow ( [ 'IMEI' , 'IMSI count' ] ) with conn . cursor ( name = 'duplicates_report' ) as cursor : cursor . execute ( """SELECT imei_norm,
                                     COUNT(*) AS imsi_count
                                FROM (SELECT DISTINCT imei_norm, imsi
                                        FROM monthly_network_triplets_country_no_null_imeis
                                       WHERE triplet_month = %s
                                         AND triplet_year = %s
                                         AND is_valid_imsi(imsi)) all_network_imei_imsis
                            GROUP BY imei_norm HAVING COUNT(*) >= %s
                            ORDER BY imsi_count DESC""" , [ month , year , imsi_min_limit ] ) for res in cursor : writer . writerow ( [ res . imei_norm , res . imsi_count ] ) return _gen_metadata_for_reports ( [ duplicates_csv_filename ] , output_dir )
Helper function to write out the country-wide duplicates report.
Helper function to write out the country - wide duplicates report .
"""
    Helper function to write out the country-wide duplicates report.

    Arguments:
        conn: DIRBS PostgreSQL connection object
        config: DIRBS config object
        month: month of the report
        year: year of the report
        country_name: name of the country
        output_dir: output directory path
        imsi_min_limit: minimum IMSI limit (default 5)
    Returns:
        Reports metadata
    """ # We can't use our normal duplicate dimension here as it doesn't give the limits, so unfortunately, # we have to use a modified query that is also slightly optimized as it can query using triplet_year # and triplet_month
None
conn
callable
DIRBS PostgreSQL connection object
DIRBS PostgreSQL connection object
config
callable
DIRBS config object
DIRBS config object
month
int
month of the report
month of the report
year
int
year of the report
year of the report
country_name
str
name of the country
name of the country
output_dir
str
output directory path
output directory path
imsi_min_limit
int
minimum IMSI limit (default 5)
minimum IMSI limit ( default 5 )