def _get_fenix_counts()

in glam/api/views.py [0:0]


def _get_fenix_counts(app_id, versions, ping_type, os, by_build):
    """
    Helper method to gather the `FenixCounts` data in a single query.

    Returns the data as a Python dict keyed by "{version}-{build_id}" for
    quick lookup.

    """
    query = FenixCounts.objects.filter(
        app_id=app_id, version__in=versions, ping_type=ping_type, os=os
    )
    if by_build:
        query = query.exclude(build_id="*")
    else:
        query = query.filter(build_id="*")
    query = query.annotate(key=Concat("version", Value("-"), "build_id"))
    data = {
        row["key"]: row["total_users"] for row in query.values("key", "total_users")
    }

    return data