import collections


def get_history_package_numbers(data, commit, date):
    """Get number of packages for each status.
    """
    result = []
    all_statuses = [
        "blocked", "py3-only", "dropped", "idle", "in-progress",
        "released", "legacy-leaf", "mispackaged"]

    package_numbers = collections.Counter(
        package['status'] for package in data['packages'].values()
    )
    if 'released' not in package_numbers and date < '2018':
        # With data from before April 2017, "released" (dual-support) packages
        # are counted as py3-only
        package_numbers['released'] = package_numbers.pop('py3-only')
    for status in all_statuses:
        row = {
            'commit': commit,
            'date': date,
            'status': status,
            'num_packages': package_numbers.get(status, 0),
        }
        result.append(row)
    return result