original_docstring: 
      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
      
docstring: Helper function to write out the country-wide duplicates report.
docstring_tokens: Helper function to write out the country - wide duplicates report .
code: 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)
code_tokens: 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 )
short_docstring: Helper function to write out the country-wide duplicates report.
short_docstring_tokens: Helper function to write out the country - wide duplicates report .
comment: """
      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
      """$SEP$# We can't use our normal duplicate dimension here as it doesn't give the limits, so unfortunately,$SEP$# we have to use a modified query that is also slightly optimized as it can query using triplet_year$SEP$# and triplet_month