Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- github_analytics/bar_chart.py +34 -0
- github_analytics/bubble_chart.py +48 -0
- github_analytics/line_chart.py +33 -0
- github_analytics/pie_chart.py +38 -0
github_analytics/bar_chart.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import plotly.graph_objs as go
|
3 |
+
from github_analytics.singular_analysis_chat import predict_2vars
|
4 |
+
|
5 |
+
|
6 |
+
def create_bar_chart(repo_data):
|
7 |
+
st.subheader("Here's your data visualization of Repositories compared by stars:")
|
8 |
+
# Extract labels and data from repo_data
|
9 |
+
if not repo_data:
|
10 |
+
return None
|
11 |
+
|
12 |
+
labels = [repo['name'] for repo in repo_data]
|
13 |
+
stars = [repo['stargazers_count'] for repo in repo_data]
|
14 |
+
|
15 |
+
# Create a Plotly line chart
|
16 |
+
fig = go.Figure(data=go.Bar(x=labels, y=stars))
|
17 |
+
|
18 |
+
# Customize the chart
|
19 |
+
fig.update_layout(
|
20 |
+
title='Stars by Repository',
|
21 |
+
xaxis_title='Repository',
|
22 |
+
yaxis_title='Number of Stars',
|
23 |
+
hovermode='closest',
|
24 |
+
xaxis=dict(tickangle=-45), # Rotate x-axis labels
|
25 |
+
width=800, # Set desired width
|
26 |
+
height=600
|
27 |
+
)
|
28 |
+
|
29 |
+
# Customize hover label
|
30 |
+
fig.update_traces(
|
31 |
+
hovertemplate='Repository: %{x}<br>Forks: %{y}'
|
32 |
+
)
|
33 |
+
response = predict_2vars(labels, stars, "repo names", "stars")
|
34 |
+
return st.plotly_chart(fig), st.write(response)
|
github_analytics/bubble_chart.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.express as px
|
4 |
+
from datetime import datetime
|
5 |
+
from github_analytics.singular_analysis_chat import predict_df
|
6 |
+
|
7 |
+
|
8 |
+
def create_bubble_chart(repo_data):
|
9 |
+
# Extract data from repo_data
|
10 |
+
if not repo_data:
|
11 |
+
return None
|
12 |
+
|
13 |
+
labels = [repo['name'] for repo in repo_data]
|
14 |
+
stars = [repo['stargazers_count'] for repo in repo_data]
|
15 |
+
forks = [repo['forks_count'] for repo in repo_data]
|
16 |
+
created_at = [datetime.strptime(repo['created_at'], "%Y-%m-%dT%H:%M:%SZ") for repo in repo_data]
|
17 |
+
# age = [(datetime.now() - created) for created in created_at]
|
18 |
+
age = [(datetime.now() - created).days for created in created_at]
|
19 |
+
|
20 |
+
# Create a DataFrame
|
21 |
+
df = pd.DataFrame({
|
22 |
+
'name': labels,
|
23 |
+
'stars': stars,
|
24 |
+
'forks': forks,
|
25 |
+
'age': age
|
26 |
+
})
|
27 |
+
|
28 |
+
# Create a Plotly bubble chart
|
29 |
+
fig = px.scatter(
|
30 |
+
df,
|
31 |
+
x='forks',
|
32 |
+
y='stars',
|
33 |
+
size='age',
|
34 |
+
hover_data=['name', 'forks', 'stars', 'age'],
|
35 |
+
size_max=60 # Adjust the maximum bubble size
|
36 |
+
)
|
37 |
+
|
38 |
+
# Customize the chart
|
39 |
+
fig.update_layout(
|
40 |
+
title='Stars vs. Forks',
|
41 |
+
xaxis_title='Number of Forks',
|
42 |
+
yaxis_title='Number of Stars',
|
43 |
+
hovermode='closest',
|
44 |
+
width=800,
|
45 |
+
height=600
|
46 |
+
)
|
47 |
+
response = predict_df(df)
|
48 |
+
return st.plotly_chart(fig), st.write(response)
|
github_analytics/line_chart.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import plotly.graph_objs as go
|
3 |
+
from github_analytics.singular_analysis_chat import predict_2vars
|
4 |
+
|
5 |
+
|
6 |
+
def create_line_chart(repo_data):
|
7 |
+
# Extract labels and data from repo_data
|
8 |
+
if not repo_data:
|
9 |
+
return None
|
10 |
+
|
11 |
+
labels = [repo['name'] for repo in repo_data]
|
12 |
+
forks = [repo['forks_count'] for repo in repo_data]
|
13 |
+
|
14 |
+
# Create a Plotly line chart
|
15 |
+
fig = go.Figure(data=go.Scatter(x=labels, y=forks, mode='lines+markers'))
|
16 |
+
|
17 |
+
# Customize the chart
|
18 |
+
fig.update_layout(
|
19 |
+
title='Forks by Repository',
|
20 |
+
xaxis_title='Repository',
|
21 |
+
yaxis_title='Number of Forks',
|
22 |
+
hovermode='closest',
|
23 |
+
xaxis=dict(tickangle=-45), # Rotate x-axis labels
|
24 |
+
width=800, # Set desired width
|
25 |
+
height=600
|
26 |
+
)
|
27 |
+
|
28 |
+
# Customize hover label
|
29 |
+
fig.update_traces(
|
30 |
+
hovertemplate='Repository: %{x}<br>Forks: %{y}'
|
31 |
+
)
|
32 |
+
response = predict_2vars(labels, forks, "repo names", "forks")
|
33 |
+
return st.plotly_chart(fig), st.write(response)
|
github_analytics/pie_chart.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from github_analytics.singular_analysis_chat import predict_2vars
|
3 |
+
import plotly.graph_objs as go
|
4 |
+
|
5 |
+
|
6 |
+
def create_pie_chart(repo_data):
|
7 |
+
"""Creates an interactive pie chart showing the distribution of repository languages."""
|
8 |
+
if not repo_data:
|
9 |
+
return None
|
10 |
+
|
11 |
+
languages = {}
|
12 |
+
for repo in repo_data:
|
13 |
+
if repo.get("language"): # Check if language exists
|
14 |
+
languages[repo["language"]] = languages.get(repo["language"], 0) + 1
|
15 |
+
|
16 |
+
language_labels = list(languages.keys())
|
17 |
+
language_counts = list(languages.values())
|
18 |
+
|
19 |
+
if not language_labels:
|
20 |
+
st.write("No languages found in repositories.")
|
21 |
+
return None
|
22 |
+
|
23 |
+
# Create Plotly pie chart
|
24 |
+
fig = go.Figure(data=[go.Pie(labels=language_labels, values=language_counts)])
|
25 |
+
|
26 |
+
fig.update_layout(
|
27 |
+
title="Repository Language Distribution",
|
28 |
+
hoverlabel=dict(
|
29 |
+
bgcolor="white",
|
30 |
+
font_size=16,
|
31 |
+
font_family="Rockwell"
|
32 |
+
),
|
33 |
+
width=800,
|
34 |
+
height=600
|
35 |
+
)
|
36 |
+
|
37 |
+
response = predict_2vars(language_labels, language_counts, "language_labels", "language_counts")
|
38 |
+
return st.plotly_chart(fig), st.write(response)
|