src/dirbs/reports/stats_generator.py
def _calc_top_models_common(conn, subquery, subquery_params=None):
    """Helper function to calculate the top models using a supplied subquery to supply a list of TACs and counts."""
    if subquery_params is None:
        subquery_params = []

    with conn.cursor() as cursor, utils.CodeProfiler() as cp:
        cursor.execute(sql.SQL("""SELECT manufacturer,
                                         model,
                                         total_imei_count,
                                         string_agg(technology_generation, '/') AS tech_generations
                                    FROM (SELECT manufacturer,
                                                 model,
                                                 total_imei_count,
                                                 technology_generation
                                            FROM (SELECT model_name AS model,
                                                         manufacturer::TEXT AS manufacturer,
                                                         SUM(st.imei_count)::BIGINT AS total_imei_count,
                                                         bit_or(rat_bitmask) AS model_rat
                                                    FROM gsma_data
                                                    JOIN ({0}) AS st
                                                   USING (tac)
                                                GROUP BY manufacturer, model_name
                                                ORDER BY total_imei_count DESC
                                                   LIMIT 10) top_10_models
                                            JOIN LATERAL (SELECT bitmask_to_set_bit_positions(top_10_models.model_rat)
                                                         AS model_gsma_rank) model_ranks
                                                 ON TRUE
                                            JOIN (SELECT DISTINCT gsma_rank, technology_generation
                                                    FROM radio_access_technology_map) unique_map
                                                 ON unique_map.gsma_rank = model_ranks.model_gsma_rank
                                         ) uniques
                                GROUP BY manufacturer, model, total_imei_count
                                ORDER BY total_imei_count DESC
                               """).format(subquery),  # noqa: Q447, Q449
                       subquery_params)
        results = [{'model': result.model,
                    'manufacturer': result.manufacturer,
                    'tech_generations': result.tech_generations,
                    'imei_count': result.total_imei_count} for result in cursor]
    return results, cp.duration, [cp.duration]
Helper function to calculate the top models using a supplied subquery to supply a list of TACs and counts.
Helper function to calculate the top models using a supplied subquery to supply a list of TACs and counts.
Helper function to calculate the top models using a supplied subquery to supply a list of TACs and counts .
def _calc_top_models_common(conn, subquery, subquery_params=None):
    if subquery_params is None:
        subquery_params = []
    with conn.cursor() as cursor, utils.CodeProfiler() as cp:
        cursor.execute(sql.SQL("""SELECT manufacturer,
                                         model,
                                         total_imei_count,
                                         string_agg(technology_generation, '/') AS tech_generations
                                    FROM (SELECT manufacturer,
                                                 model,
                                                 total_imei_count,
                                                 technology_generation
                                            FROM (SELECT model_name AS model,
                                                         manufacturer::TEXT AS manufacturer,
                                                         SUM(st.imei_count)::BIGINT AS total_imei_count,
                                                         bit_or(rat_bitmask) AS model_rat
                                                    FROM gsma_data
                                                    JOIN ({0}) AS st
                                                   USING (tac)
                                                GROUP BY manufacturer, model_name
                                                ORDER BY total_imei_count DESC
                                                   LIMIT 10) top_10_models
                                            JOIN LATERAL (SELECT bitmask_to_set_bit_positions(top_10_models.model_rat)
                                                         AS model_gsma_rank) model_ranks
                                                 ON TRUE
                                            JOIN (SELECT DISTINCT gsma_rank, technology_generation
                                                    FROM radio_access_technology_map) unique_map
                                                 ON unique_map.gsma_rank = model_ranks.model_gsma_rank
                                         ) uniques
                                GROUP BY manufacturer, model, total_imei_count
                                ORDER BY total_imei_count DESC
                               """).format(subquery),  
                       subquery_params)
        results = [{'model': result.model,
                    'manufacturer': result.manufacturer,
                    'tech_generations': result.tech_generations,
                    'imei_count': result.total_imei_count} for result in cursor]
    return results, cp.duration, [cp.duration]
def _calc_top_models_common ( conn , subquery , subquery_params = None ) : if subquery_params is None : subquery_params = [ ] with conn . cursor ( ) as cursor , utils . CodeProfiler ( ) as cp : cursor . execute ( sql . SQL ( """SELECT manufacturer,
                                         model,
                                         total_imei_count,
                                         string_agg(technology_generation, '/') AS tech_generations
                                    FROM (SELECT manufacturer,
                                                 model,
                                                 total_imei_count,
                                                 technology_generation
                                            FROM (SELECT model_name AS model,
                                                         manufacturer::TEXT AS manufacturer,
                                                         SUM(st.imei_count)::BIGINT AS total_imei_count,
                                                         bit_or(rat_bitmask) AS model_rat
                                                    FROM gsma_data
                                                    JOIN ({0}) AS st
                                                   USING (tac)
                                                GROUP BY manufacturer, model_name
                                                ORDER BY total_imei_count DESC
                                                   LIMIT 10) top_10_models
                                            JOIN LATERAL (SELECT bitmask_to_set_bit_positions(top_10_models.model_rat)
                                                         AS model_gsma_rank) model_ranks
                                                 ON TRUE
                                            JOIN (SELECT DISTINCT gsma_rank, technology_generation
                                                    FROM radio_access_technology_map) unique_map
                                                 ON unique_map.gsma_rank = model_ranks.model_gsma_rank
                                         ) uniques
                                GROUP BY manufacturer, model, total_imei_count
                                ORDER BY total_imei_count DESC
                               """ ) . format ( subquery ) , subquery_params ) results = [ { 'model' : result . model , 'manufacturer' : result . manufacturer , 'tech_generations' : result . tech_generations , 'imei_count' : result . total_imei_count } for result in cursor ] return results , cp . duration , [ cp . duration ]
Helper function to calculate the top models using a supplied subquery to supply a list of TACs and counts.
Helper function to calculate the top models using a supplied subquery to supply a list of TACs and counts .
"""Helper function to calculate the top models using a supplied subquery to supply a list of TACs and counts.""" # noqa: Q447, Q449
conn
subquery
subquery_params