Spaces:
Runtime error
Runtime error
Commit
·
50ccfc5
1
Parent(s):
dadfa20
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,13 +10,15 @@ from cachetools import TTLCache, cached
|
|
| 10 |
from datetime import datetime, timedelta
|
| 11 |
from datasets import Dataset
|
| 12 |
import os
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
token = os.
|
| 15 |
assert token
|
| 16 |
librarian_bot_avatar = "https://aeiljuispo.cloudimg.io/v7/https://s3.amazonaws.com/moonup/production/uploads/1674830754237-63d3e0e8ff1384ce6c5dd17d.jpeg?w=200&h=200&f=face"
|
| 17 |
|
| 18 |
|
| 19 |
-
@cached(cache=TTLCache(maxsize=1000, ttl=timedelta(minutes=10), timer=datetime.now))
|
| 20 |
def get_hub_community_activity(user: str) -> List[Any]:
|
| 21 |
all_data = []
|
| 22 |
for i in range(1, 2000, 100):
|
|
@@ -59,11 +61,11 @@ def update_data():
|
|
| 59 |
data = [parse_pr_data(d) for d in data]
|
| 60 |
update_df = pl.DataFrame(data)
|
| 61 |
df = pl.concat([previous_df, update_df]).unique()
|
| 62 |
-
|
|
|
|
| 63 |
return df
|
| 64 |
|
| 65 |
|
| 66 |
-
|
| 67 |
# def get_pr_status():
|
| 68 |
# df = update_data()
|
| 69 |
# df = df.filter(pl.col("isPullRequest") is True)
|
|
@@ -71,12 +73,26 @@ def update_data():
|
|
| 71 |
# # return frequencies(x["status"] for x in pr_data)
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def create_pie():
|
| 75 |
-
|
| 76 |
-
df =
|
| 77 |
-
df =
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
def group_status_by_pr_number():
|
|
@@ -102,7 +118,8 @@ def plot_over_time():
|
|
| 102 |
df = df.to_pandas().set_index("createdAt").cumsum()
|
| 103 |
return px.line(df, x=df.index, y=[c for c in df.columns if c != "sum"])
|
| 104 |
|
| 105 |
-
|
|
|
|
| 106 |
|
| 107 |
with gr.Blocks() as demo:
|
| 108 |
# frequencies = get_pr_status("librarian-bot")
|
|
@@ -114,7 +131,7 @@ with gr.Blocks() as demo:
|
|
| 114 |
"The below pie chart shows the percentage of pull requests made by"
|
| 115 |
" librarian bot that are open, closed or merged"
|
| 116 |
)
|
| 117 |
-
create_pie()
|
| 118 |
with gr.Column():
|
| 119 |
gr.Markdown("Pull requests opened, closed and merged over time (cumulative)")
|
| 120 |
gr.Plot(plot_over_time())
|
|
|
|
| 10 |
from datetime import datetime, timedelta
|
| 11 |
from datasets import Dataset
|
| 12 |
import os
|
| 13 |
+
from functools import lru_cache
|
| 14 |
+
import pandas as pd
|
| 15 |
+
from toolz import frequencies
|
| 16 |
|
| 17 |
+
token = os.environ["HUGGINGFACE_TOKEN"]
|
| 18 |
assert token
|
| 19 |
librarian_bot_avatar = "https://aeiljuispo.cloudimg.io/v7/https://s3.amazonaws.com/moonup/production/uploads/1674830754237-63d3e0e8ff1384ce6c5dd17d.jpeg?w=200&h=200&f=face"
|
| 20 |
|
| 21 |
|
|
|
|
| 22 |
def get_hub_community_activity(user: str) -> List[Any]:
|
| 23 |
all_data = []
|
| 24 |
for i in range(1, 2000, 100):
|
|
|
|
| 61 |
data = [parse_pr_data(d) for d in data]
|
| 62 |
update_df = pl.DataFrame(data)
|
| 63 |
df = pl.concat([previous_df, update_df]).unique()
|
| 64 |
+
if len(df) != len(previous_df):
|
| 65 |
+
Dataset(df.to_arrow()).push_to_hub("librarian-bot/stats", token=token)
|
| 66 |
return df
|
| 67 |
|
| 68 |
|
|
|
|
| 69 |
# def get_pr_status():
|
| 70 |
# df = update_data()
|
| 71 |
# df = df.filter(pl.col("isPullRequest") is True)
|
|
|
|
| 73 |
# # return frequencies(x["status"] for x in pr_data)
|
| 74 |
|
| 75 |
|
| 76 |
+
@lru_cache(maxsize=512)
|
| 77 |
+
def get_pr_status(user: str):
|
| 78 |
+
all_data = get_hub_community_activity(user)
|
| 79 |
+
pr_data = (
|
| 80 |
+
x["discussionData"] for x in all_data if x["discussionData"]["isPullRequest"]
|
| 81 |
+
)
|
| 82 |
+
return frequencies(x["status"] for x in pr_data)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
def create_pie():
|
| 86 |
+
frequencies = get_pr_status("librarian-bot")
|
| 87 |
+
df = pd.DataFrame({"status": frequencies.keys(), "number": frequencies.values()})
|
| 88 |
+
return px.pie(df, values="number", names="status", template="seaborn")
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# def create_pie():
|
| 92 |
+
# df = update_data()
|
| 93 |
+
# df = df.filter(pl.col("isPullRequest") is True)
|
| 94 |
+
# df = df["status"].value_counts().to_pandas()
|
| 95 |
+
# return px.pie(df, values="counts", names="status", template="seaborn")
|
| 96 |
|
| 97 |
|
| 98 |
def group_status_by_pr_number():
|
|
|
|
| 118 |
df = df.to_pandas().set_index("createdAt").cumsum()
|
| 119 |
return px.line(df, x=df.index, y=[c for c in df.columns if c != "sum"])
|
| 120 |
|
| 121 |
+
|
| 122 |
+
create_pie()
|
| 123 |
|
| 124 |
with gr.Blocks() as demo:
|
| 125 |
# frequencies = get_pr_status("librarian-bot")
|
|
|
|
| 131 |
"The below pie chart shows the percentage of pull requests made by"
|
| 132 |
" librarian bot that are open, closed or merged"
|
| 133 |
)
|
| 134 |
+
gr.Plot(create_pie())
|
| 135 |
with gr.Column():
|
| 136 |
gr.Markdown("Pull requests opened, closed and merged over time (cumulative)")
|
| 137 |
gr.Plot(plot_over_time())
|