def download_stats()

in analytics/s3_test_stats_analyze.py [0:0]


def download_stats(folder: str, lookback: int):
    commit_sha_list = _get_latests_git_commit_sha_list(lookback)
    for commit_sha in commit_sha_list:
        for key in tqdm(BUCKET.objects.filter(Prefix=f'test_time/{commit_sha}')):
            remote_fname = key.key
            local_fname = os.path.join(folder, remote_fname)
            # TODO: Do this in parallel
            if not os.path.exists(local_fname):
                dirname = os.path.dirname(local_fname)
                if not os.path.exists(dirname):
                    os.makedirs(dirname)
                # only download when there's a cache miss
                if not os.path.exists(local_fname) or not os.path.isfile(local_fname):
                    print(f"\nDownloading {remote_fname}...")
                    CLIENT.download_file("ossci-metrics", remote_fname, local_fname)