src/dirbs/reports/stats_generator.py
def _calc_distinct_id_counts(db_config, month, year):
    """Calculate per-operator and country daily and monthly ID counts for a given month and year."""
    with utils.create_db_connection(db_config) as conn, conn.cursor() as cursor, utils.CodeProfiler() as cp:
        results = defaultdict(lambda: dict(num_triplets=0, num_imeis=0, num_imsis=0, num_msisdns=0,
                                           num_imei_imsis=0, num_imei_msisdns=0, num_imsi_msisdns=0))
        cursor.execute(
            """SELECT operator_id,
                      data_date,
                      (hll_cardinality(COALESCE(hll_union_agg(triplet_hll), hll_empty())))::BIGINT AS num_triplets,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_hll), hll_empty())))::BIGINT AS num_imeis,
                      (hll_cardinality(COALESCE(hll_union_agg(imsi_hll), hll_empty())))::BIGINT AS num_imsis,
                      (hll_cardinality(COALESCE(hll_union_agg(msisdn_hll), hll_empty())))::BIGINT AS num_msisdns,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_imsis_hll), hll_empty())))::BIGINT
                        AS num_imei_imsis,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_msisdns_hll), hll_empty())))::BIGINT
                        AS num_imei_msisdns,
                      (hll_cardinality(COALESCE(hll_union_agg(imsi_msisdns_hll), hll_empty())))::BIGINT
                        AS num_imsi_msisdns
                 FROM daily_per_mno_hll_sketches
                WHERE date_part('month', data_date) = %(month)s
                  AND date_part('year', data_date) = %(year)s
             GROUP BY CUBE (operator_id, data_date)
            """,
            {'month': month, 'year': year}
        )

        results = [res._asdict() for res in cursor]

    return results, cp.duration, [cp.duration]
Calculate per-operator and country daily and monthly ID counts for a given month and year.
Calculate per-operator and country daily and monthly ID counts for a given month and year.
Calculate per - operator and country daily and monthly ID counts for a given month and year .
def _calc_distinct_id_counts(db_config, month, year):
    with utils.create_db_connection(db_config) as conn, conn.cursor() as cursor, utils.CodeProfiler() as cp:
        results = defaultdict(lambda: dict(num_triplets=0, num_imeis=0, num_imsis=0, num_msisdns=0,
                                           num_imei_imsis=0, num_imei_msisdns=0, num_imsi_msisdns=0))
        cursor.execute(
            """SELECT operator_id,
                      data_date,
                      (hll_cardinality(COALESCE(hll_union_agg(triplet_hll), hll_empty())))::BIGINT AS num_triplets,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_hll), hll_empty())))::BIGINT AS num_imeis,
                      (hll_cardinality(COALESCE(hll_union_agg(imsi_hll), hll_empty())))::BIGINT AS num_imsis,
                      (hll_cardinality(COALESCE(hll_union_agg(msisdn_hll), hll_empty())))::BIGINT AS num_msisdns,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_imsis_hll), hll_empty())))::BIGINT
                        AS num_imei_imsis,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_msisdns_hll), hll_empty())))::BIGINT
                        AS num_imei_msisdns,
                      (hll_cardinality(COALESCE(hll_union_agg(imsi_msisdns_hll), hll_empty())))::BIGINT
                        AS num_imsi_msisdns
                 FROM daily_per_mno_hll_sketches
                WHERE date_part('month', data_date) = %(month)s
                  AND date_part('year', data_date) = %(year)s
             GROUP BY CUBE (operator_id, data_date)
            """,
            {'month': month, 'year': year}
        )
        results = [res._asdict() for res in cursor]
    return results, cp.duration, [cp.duration]
def _calc_distinct_id_counts ( db_config , month , year ) : with utils . create_db_connection ( db_config ) as conn , conn . cursor ( ) as cursor , utils . CodeProfiler ( ) as cp : results = defaultdict ( lambda : dict ( num_triplets = 0 , num_imeis = 0 , num_imsis = 0 , num_msisdns = 0 , num_imei_imsis = 0 , num_imei_msisdns = 0 , num_imsi_msisdns = 0 ) ) cursor . execute ( """SELECT operator_id,
                      data_date,
                      (hll_cardinality(COALESCE(hll_union_agg(triplet_hll), hll_empty())))::BIGINT AS num_triplets,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_hll), hll_empty())))::BIGINT AS num_imeis,
                      (hll_cardinality(COALESCE(hll_union_agg(imsi_hll), hll_empty())))::BIGINT AS num_imsis,
                      (hll_cardinality(COALESCE(hll_union_agg(msisdn_hll), hll_empty())))::BIGINT AS num_msisdns,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_imsis_hll), hll_empty())))::BIGINT
                        AS num_imei_imsis,
                      (hll_cardinality(COALESCE(hll_union_agg(imei_msisdns_hll), hll_empty())))::BIGINT
                        AS num_imei_msisdns,
                      (hll_cardinality(COALESCE(hll_union_agg(imsi_msisdns_hll), hll_empty())))::BIGINT
                        AS num_imsi_msisdns
                 FROM daily_per_mno_hll_sketches
                WHERE date_part('month', data_date) = %(month)s
                  AND date_part('year', data_date) = %(year)s
             GROUP BY CUBE (operator_id, data_date)
            """ , { 'month' : month , 'year' : year } ) results = [ res . _asdict ( ) for res in cursor ] return results , cp . duration , [ cp . duration ]
Calculate per-operator and country daily and monthly ID counts for a given month and year.
Calculate per - operator and country daily and monthly ID counts for a given month and year .
"""Calculate per-operator and country daily and monthly ID counts for a given month and year."""
db_config
month
year