from datetime import datetime


def _prepare_summary(report, package_versions=None):
    """Return tests summary including number of failed and passed tests.

    Return summary with length of each list in report.
    Summary example:
    {
        "date": "08/06/2019 09:37:45",
        "failed": 61,
        "passed": 497,
        "skipped": 0,
        "versions": [
            {
                "name": "onnx",
                "version": "1.5.0"
            },
            {
                "name": "onnxruntime",
                "version": "0.5.0"
            },
        ]
    }

    :param report: Dictionary with REPORT_KEYS and list of tests names as values.
    :type report: dict
    :param package_versions: List of packages installed by pip.
    :type package_versions: list
    :return: Summary with length of each list in report.
    :rtype: dict
    """
    if not package_versions:
        package_versions = []

    summary = {"date": report.get("date", datetime.now().strftime("%m/%d/%Y %H:%M:%S"))}
    summary["versions"] = package_versions
    for key in report.keys():
        if isinstance(report.get(key), list):
            summary[key] = len(report.get(key))
    return summary