-
Notifications
You must be signed in to change notification settings - Fork 0
Add daily workflow to export GitHub release download count #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gsheni
merged 8 commits into
main
from
24-add-daily-workflow-to-export-github-release-download-information-to-google-drive
Jul 29, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ff20930
wip
gsheni 5aaa62e
add prerelease, postrelease, devrelease
gsheni a3970fd
fix name
gsheni 680c76b
fix name
gsheni 1f568a4
cleanup
gsheni 4f80d1d
Update README.md
gsheni d9b7b9a
Update metrics.py
gsheni 75617c1
fix unit test
gsheni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| projects: | ||
| sdv-dev: | ||
| - sdv-dev/SDV | ||
| - sdv-dev/RDT | ||
| - sdv-dev/SDMetrics | ||
| - sdv-dev/SDGym | ||
| - sdv-dev/Copulas | ||
| - sdv-dev/CTGAN | ||
| - sdv-dev/DeepEcho | ||
| gretel: | ||
| - gretelai/gretel-python-client | ||
| - gretelai/trainer | ||
| - gretelai/gretel-synthetics | ||
| mostly-ai: | ||
| - mostly-ai/mostlyai | ||
| - mostly-ai/mostlyai-mock | ||
| ydata: | ||
| - ydataai/ydata-synthetic | ||
| - ydataai/ydata-quality | ||
| - ydataai/ydata-fabric-sdk | ||
| realtabformer: | ||
| - worldbank/REaLTabFormer | ||
| synthcity: | ||
| - vanderschaarlab/synthcity | ||
| smartnoise-sdk: | ||
| - opendp/smartnoise-sdk | ||
| be_great: | ||
| - kathrinse/be_great |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| """Functions to get GitHub downloads from GitHub.""" | ||
|
|
||
| import logging | ||
| import os | ||
| from collections import defaultdict | ||
|
|
||
| import pandas as pd | ||
| from tqdm import tqdm | ||
|
|
||
| from pymetrics.github import GithubClient | ||
| from pymetrics.output import append_row, create_csv, get_path, load_csv | ||
| from pymetrics.time_utils import drop_duplicates_by_date, get_current_utc | ||
|
|
||
| LOGGER = logging.getLogger(__name__) | ||
| dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
| TIME_COLUMN = 'timestamp' | ||
|
|
||
| GITHUB_DOWNLOAD_COUNT_FILENAME = 'github_download_counts.csv' | ||
|
|
||
|
|
||
| def get_previous_github_downloads(output_folder, dry_run=False): | ||
| """Get previous GitHub Downloads.""" | ||
| csv_path = get_path(output_folder, GITHUB_DOWNLOAD_COUNT_FILENAME) | ||
| read_csv_kwargs = { | ||
| 'parse_dates': [ | ||
| TIME_COLUMN, | ||
| 'created_at', | ||
| ], | ||
| 'dtype': { | ||
| 'ecosystem_name': pd.CategoricalDtype(), | ||
| 'org_repo': pd.CategoricalDtype(), | ||
| 'tag_name': pd.CategoricalDtype(), | ||
| 'prerelease': pd.BooleanDtype(), | ||
| 'download_count': pd.Int64Dtype(), | ||
| }, | ||
| } | ||
| data = load_csv(csv_path, read_csv_kwargs=read_csv_kwargs) | ||
| return data | ||
|
|
||
|
|
||
| def collect_github_downloads( | ||
| projects: dict[str, list[str]], output_folder: str, dry_run: bool = False, verbose: bool = False | ||
| ): | ||
| """Pull data about the downloads of a GitHub project. | ||
|
|
||
| Args: | ||
| projects (dict[str, list[str]]): | ||
| List of projects to analyze. Each key is the name of the ecosystem, and | ||
| each value is a list of github repositories (including organization). | ||
| output_folder (str): | ||
| Folder in which project downloads will be stored. | ||
| It can be passed as a local folder or as a Google Drive path in the format | ||
| `gdrive://{folder_id}`. | ||
| The folder must contain 'github_download_counts.csv' | ||
| dry_run (bool): | ||
| If `True`, do not upload the results. Defaults to `False`. | ||
| verbose (bool): | ||
| If `True`, will output dataframes heads of github download data. Defaults to `False`. | ||
| """ | ||
| overall_df = get_previous_github_downloads(output_folder=output_folder) | ||
|
|
||
| gh_client = GithubClient() | ||
| download_counts = defaultdict(int) | ||
|
|
||
| for ecosystem_name, repositories in projects.items(): | ||
| for org_repo in tqdm(repositories, position=1, desc=f'Ecosystem: {ecosystem_name}'): | ||
| pages_remain = True | ||
| page = 1 | ||
| per_page = 100 | ||
| download_counts[org_repo] = 0 | ||
|
|
||
| github_org = org_repo.split('/')[0] | ||
| repo = org_repo.split('/')[1] | ||
|
|
||
| while pages_remain is True: | ||
| response = gh_client.get( | ||
| github_org, | ||
| repo, | ||
| endpoint='releases', | ||
| query_params={'per_page': per_page, 'page': page}, | ||
| ) | ||
| release_data = response.json() | ||
| link_header = response.headers.get('link') | ||
|
|
||
| if response.status_code == 404: | ||
| LOGGER.debug(f'Skipping: {org_repo} because org/repo does not exist') | ||
| pages_remain = False | ||
| break | ||
|
|
||
| # Get download count | ||
| for release_info in tqdm( | ||
| release_data, position=0, desc=f'{repo} releases, page={page}' | ||
| ): | ||
| release_id = release_info.get('id') | ||
| tag_name = release_info.get('tag_name') | ||
| prerelease = release_info.get('prerelease') | ||
| created_at = release_info.get('created_at') | ||
| endpoint = f'releases/{release_id}' | ||
|
|
||
| timestamp = get_current_utc() | ||
| response = gh_client.get(github_org, repo, endpoint=endpoint) | ||
| data = response.json() | ||
| assets = data.get('assets') | ||
|
|
||
| tag_row = { | ||
| 'ecosystem_name': [ecosystem_name], | ||
| 'org_repo': [org_repo], | ||
| 'timestamp': [timestamp], | ||
| 'tag_name': [tag_name], | ||
| 'prerelease': [prerelease], | ||
| 'created_at': [created_at], | ||
| 'download_count': 0, | ||
| } | ||
| if assets and len(assets) > 0: | ||
| for asset in assets: | ||
| tag_row['download_count'] += asset.get('download_count', 0) | ||
|
|
||
| overall_df = append_row(overall_df, tag_row) | ||
|
|
||
| # Check pagination | ||
| if link_header and 'rel="next"' in link_header: | ||
| page += 1 | ||
| else: | ||
| break | ||
| overall_df = drop_duplicates_by_date( | ||
| overall_df, | ||
| time_column=TIME_COLUMN, | ||
| group_by_columns=['ecosystem_name', 'org_repo', 'tag_name'], | ||
| ) | ||
| if verbose: | ||
| LOGGER.info(f'{GITHUB_DOWNLOAD_COUNT_FILENAME} tail') | ||
| LOGGER.info(overall_df.tail(5).to_string()) | ||
|
|
||
| overall_df.to_csv('github_download_counts.csv', index=False) | ||
|
|
||
| if not dry_run: | ||
| gfolder_path = f'{output_folder}/{GITHUB_DOWNLOAD_COUNT_FILENAME}' | ||
| create_csv(output_path=gfolder_path, data=overall_df) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.