iris-hep / analysis-community-summary

Summary report on community interactions and contributions with IRIS-HEP Analysis Systems related tools
https://iris-hep.org/analysis-community-summary/
MIT License
5 stars 0 forks source link

Consider using ghapi #28

Open matthewfeickert opened 2 years ago

matthewfeickert commented 2 years ago

As an alternative to PyGithub, https://github.com/fastai/ghapi provides nice pagination that could make it easier to work with and gives access to the full GitHub API. This should also allow for the ability to go and get the full star history of any project.

Example: This code gets all of the GitHub star times and dates for pyhf

import json

import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import pandas as pd
from ghapi.all import GhApi, pages

with open(".secrets.json") as read_file:
    api = GhApi(token=json.load(read_file)["api_token"])

owner = "scikit-hep"
repo = "pyhf"
per_page = 30

api.activity.list_stargazers_for_repo(owner, repo, per_page=per_page)
n_pages = api.last_page()

all_pages = pages(
    api.activity.list_stargazers_for_repo,
    n_pages,
    owner,
    repo,
    per_page=per_page,
    headers={"Accept": "application/vnd.github.v3.star+json"},
)

data = [{"date": item["starred_at"], "count": 1} for page in all_pages for item in page]
df = pd.DataFrame(data)

df["date"] = pd.to_datetime(df["date"])
df = df.resample("W-Mon", on="date").sum().cumsum()
df["repo"] = repo

fig, ax = plt.subplots()

time_fmt = mdates.AutoDateLocator()
ax.xaxis.set_major_locator(time_fmt)

ax.plot(df.index, df["count"], label=repo)
ax.legend(loc="best", frameon=False)

ax.set_xlabel("Date", size=14)
ax.set_ylabel("Number of GitHub Stars", size=14)

fig.tight_layout()

file_types = ["png", "pdf", "svg"]
for extension in file_types:
    fig.savefig(f"ghapi_{repo}_star_history.{extension}", facecolor="white")

ghapi_pyhf_star_history

matthewfeickert commented 2 years ago

Another thing that this would allow would be allowing for projects to have their timelines aligned which is quite interesting to visualize growth in comparison to other projects:

star-history-aligned-2022-06-21

Timeline by year Timeline aligned
star-history-2022-06-21 star-history-aligned-2022-06-21