LysandreJik
commited on
Commit
•
b5bfbc4
1
Parent(s):
e57069c
Add issues
Browse files- app.py +49 -10
- index.html +1 -0
- index.js +69 -2
app.py
CHANGED
@@ -6,7 +6,7 @@ from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
|
6 |
from urllib.parse import parse_qs, urlparse
|
7 |
|
8 |
from huggingface_hub import list_datasets, set_access_token, HfFolder
|
9 |
-
from datasets import load_dataset
|
10 |
import numpy as np
|
11 |
|
12 |
HF_TOKEN = os.environ['HF_TOKEN']
|
@@ -15,11 +15,17 @@ HfFolder.save_token(HF_TOKEN)
|
|
15 |
|
16 |
|
17 |
datasets = {
|
18 |
-
|
19 |
-
"issues": load_dataset("open-source-metrics/issues"),
|
20 |
"pip": load_dataset("open-source-metrics/pip").sort('day')
|
21 |
}
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def running_mean(x, N, total_length=-1):
|
25 |
cumsum = np.cumsum(np.insert(x, 0, 0))
|
@@ -94,17 +100,50 @@ class RequestHandler(SimpleHTTPRequestHandler):
|
|
94 |
library_names = library_names.split(',')
|
95 |
|
96 |
returned_values = {}
|
97 |
-
dataset_dict =
|
98 |
|
99 |
for library_name in library_names:
|
100 |
dataset = dataset_dict[library_name]
|
101 |
|
102 |
n = 0
|
103 |
-
for
|
104 |
-
|
105 |
-
if
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
n += 1
|
109 |
if i['dates'] in returned_values:
|
110 |
returned_values[i['dates']][library_name] = n
|
@@ -131,8 +170,8 @@ class RequestHandler(SimpleHTTPRequestHandler):
|
|
131 |
return SimpleHTTPRequestHandler.do_GET(self)
|
132 |
|
133 |
|
134 |
-
server = ThreadingHTTPServer(("",
|
135 |
|
136 |
-
print("Running on port
|
137 |
|
138 |
server.serve_forever()
|
|
|
6 |
from urllib.parse import parse_qs, urlparse
|
7 |
|
8 |
from huggingface_hub import list_datasets, set_access_token, HfFolder
|
9 |
+
from datasets import load_dataset, DatasetDict
|
10 |
import numpy as np
|
11 |
|
12 |
HF_TOKEN = os.environ['HF_TOKEN']
|
|
|
15 |
|
16 |
|
17 |
datasets = {
|
18 |
+
"stars": load_dataset("open-source-metrics/stars").sort('dates'),
|
19 |
+
"issues": load_dataset("open-source-metrics/issues").sort('dates'),
|
20 |
"pip": load_dataset("open-source-metrics/pip").sort('day')
|
21 |
}
|
22 |
|
23 |
+
# datasets = {
|
24 |
+
# k1: DatasetDict({
|
25 |
+
# k2: v2.select(range(0, len(v2), max(1, int(len(v2) / 1000)))) for k2, v2 in v1.items()
|
26 |
+
# }) for k1, v1 in datasets.items()
|
27 |
+
# }
|
28 |
+
|
29 |
|
30 |
def running_mean(x, N, total_length=-1):
|
31 |
cumsum = np.cumsum(np.insert(x, 0, 0))
|
|
|
100 |
library_names = library_names.split(',')
|
101 |
|
102 |
returned_values = {}
|
103 |
+
dataset_dict = datasets['stars']
|
104 |
|
105 |
for library_name in library_names:
|
106 |
dataset = dataset_dict[library_name]
|
107 |
|
108 |
n = 0
|
109 |
+
for i in dataset:
|
110 |
+
n += 1
|
111 |
+
if i['dates'] in returned_values:
|
112 |
+
returned_values[i['dates']][library_name] = n
|
113 |
+
else:
|
114 |
+
returned_values[i['dates']] = {library_name: n}
|
115 |
+
|
116 |
+
for library_name in library_names:
|
117 |
+
for i in returned_values.keys():
|
118 |
+
if library_name not in returned_values[i]:
|
119 |
+
returned_values[i][library_name] = None
|
120 |
+
|
121 |
+
returned_values = collections.OrderedDict(sorted(returned_values.items()))
|
122 |
+
output = {l: [k[l] for k in returned_values.values()][::-1] for l in library_names}
|
123 |
+
output['day'] = list(returned_values.keys())[::-1]
|
124 |
+
|
125 |
+
self.send_response(200)
|
126 |
+
self.send_header("Content-Type", "application/json")
|
127 |
+
self.end_headers()
|
128 |
+
|
129 |
+
self.wfile.write(json.dumps(output).encode("utf-8"))
|
130 |
+
|
131 |
+
return SimpleHTTPRequestHandler
|
132 |
+
|
133 |
+
if self.path.startswith("/retrieveIssues"):
|
134 |
+
url = urlparse(self.path)
|
135 |
+
query = parse_qs(url.query)
|
136 |
+
library_names = query.get("input", None)[0]
|
137 |
+
library_names = library_names.split(',')
|
138 |
|
139 |
+
returned_values = {}
|
140 |
+
dataset_dict = datasets['issues']
|
141 |
+
|
142 |
+
for library_name in library_names:
|
143 |
+
dataset = dataset_dict[library_name]
|
144 |
+
|
145 |
+
n = 0
|
146 |
+
for k, i in enumerate(dataset):
|
147 |
n += 1
|
148 |
if i['dates'] in returned_values:
|
149 |
returned_values[i['dates']][library_name] = n
|
|
|
170 |
return SimpleHTTPRequestHandler.do_GET(self)
|
171 |
|
172 |
|
173 |
+
server = ThreadingHTTPServer(("", 7861), RequestHandler)
|
174 |
|
175 |
+
print("Running on port 7861")
|
176 |
|
177 |
server.serve_forever()
|
index.html
CHANGED
@@ -18,5 +18,6 @@
|
|
18 |
<div id="selector-submit" class="submit"></div>
|
19 |
<canvas id="pip-graph"></canvas>
|
20 |
<canvas id="star-graph"></canvas>
|
|
|
21 |
</body>
|
22 |
</html>
|
|
|
18 |
<div id="selector-submit" class="submit"></div>
|
19 |
<canvas id="pip-graph"></canvas>
|
20 |
<canvas id="star-graph"></canvas>
|
21 |
+
<canvas id="issue-graph"></canvas>
|
22 |
</body>
|
23 |
</html>
|
index.js
CHANGED
@@ -70,7 +70,7 @@ const initialize = async () => {
|
|
70 |
librarySelector.appendChild(div)
|
71 |
}
|
72 |
|
73 |
-
for (const element of ['pip', 'stars']) {
|
74 |
const div = document.createElement('div');
|
75 |
const checkBox = document.createElement('input');
|
76 |
checkBox.type = 'checkbox'
|
@@ -87,7 +87,7 @@ const initialize = async () => {
|
|
87 |
}
|
88 |
|
89 |
const fetchButton = createButton('Fetch', inferJson, () => {
|
90 |
-
const graphNames = ['pip', 'stars'].filter(e => document.querySelector(`#${e}CheckboxGraph`).checked);
|
91 |
const graphs = []
|
92 |
|
93 |
if (graphNames.includes('pip'))
|
@@ -96,6 +96,9 @@ const initialize = async () => {
|
|
96 |
if (graphNames.includes('stars'))
|
97 |
graphs.push(retrieveStars)
|
98 |
|
|
|
|
|
|
|
99 |
return graphs
|
100 |
})
|
101 |
selectorSubmit.appendChild(fetchButton);
|
@@ -140,6 +143,12 @@ const retrievePipInstalls = async (libraryNames) => {
|
|
140 |
type: 'time',
|
141 |
}
|
142 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
144 |
});
|
145 |
return myChart;
|
@@ -172,6 +181,58 @@ const retrieveStars = async (libraryNames) => {
|
|
172 |
const ctx = document.getElementById('star-graph');
|
173 |
|
174 |
const myChart = new Chart(ctx, {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
type: 'line',
|
176 |
data: {labels, datasets},
|
177 |
options: {
|
@@ -183,6 +244,12 @@ const retrieveStars = async (libraryNames) => {
|
|
183 |
type: 'time',
|
184 |
}
|
185 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
}
|
187 |
});
|
188 |
return myChart;
|
|
|
70 |
librarySelector.appendChild(div)
|
71 |
}
|
72 |
|
73 |
+
for (const element of ['pip', 'stars', 'issues']) {
|
74 |
const div = document.createElement('div');
|
75 |
const checkBox = document.createElement('input');
|
76 |
checkBox.type = 'checkbox'
|
|
|
87 |
}
|
88 |
|
89 |
const fetchButton = createButton('Fetch', inferJson, () => {
|
90 |
+
const graphNames = ['pip', 'stars', 'issues'].filter(e => document.querySelector(`#${e}CheckboxGraph`).checked);
|
91 |
const graphs = []
|
92 |
|
93 |
if (graphNames.includes('pip'))
|
|
|
96 |
if (graphNames.includes('stars'))
|
97 |
graphs.push(retrieveStars)
|
98 |
|
99 |
+
if (graphNames.includes('issues'))
|
100 |
+
graphs.push(retrieveIssues)
|
101 |
+
|
102 |
return graphs
|
103 |
})
|
104 |
selectorSubmit.appendChild(fetchButton);
|
|
|
143 |
type: 'time',
|
144 |
}
|
145 |
},
|
146 |
+
plugins: {
|
147 |
+
title: {
|
148 |
+
display: true,
|
149 |
+
text: 'Pip installs'
|
150 |
+
}
|
151 |
+
}
|
152 |
}
|
153 |
});
|
154 |
return myChart;
|
|
|
181 |
const ctx = document.getElementById('star-graph');
|
182 |
|
183 |
const myChart = new Chart(ctx, {
|
184 |
+
title: "Stars",
|
185 |
+
type: 'line',
|
186 |
+
data: {labels, datasets},
|
187 |
+
options: {
|
188 |
+
scales: {
|
189 |
+
y: {
|
190 |
+
beginAtZero: true
|
191 |
+
},
|
192 |
+
x: {
|
193 |
+
type: 'time',
|
194 |
+
}
|
195 |
+
},
|
196 |
+
plugins: {
|
197 |
+
title: {
|
198 |
+
display: true,
|
199 |
+
text: 'Number of stargazers'
|
200 |
+
}
|
201 |
+
}
|
202 |
+
}
|
203 |
+
});
|
204 |
+
return myChart;
|
205 |
+
};
|
206 |
+
|
207 |
+
const retrieveIssues = async (libraryNames) => {
|
208 |
+
const inferResponse = await fetch(`retrieveIssues?input=${libraryNames}`);
|
209 |
+
const inferJson = await inferResponse.json();
|
210 |
+
const colors = ['Lilac', 'Red', 'Blue', 'Orange', 'Green']
|
211 |
+
|
212 |
+
console.log(inferJson)
|
213 |
+
const labels = Array.from(inferJson['day']).map(e => new Date(e))
|
214 |
+
const datasets = [];
|
215 |
+
for (const element in inferJson) {
|
216 |
+
if (element === 'day')
|
217 |
+
continue
|
218 |
+
|
219 |
+
const color = colors.pop()
|
220 |
+
datasets.push({
|
221 |
+
label: element,
|
222 |
+
data: inferJson[element],
|
223 |
+
backgroundColor: color,
|
224 |
+
borderColor: color,
|
225 |
+
tension: 0.01,
|
226 |
+
pointRadius: 1,
|
227 |
+
borderWidth: 2,
|
228 |
+
fill: false
|
229 |
+
})
|
230 |
+
}
|
231 |
+
|
232 |
+
const ctx = document.getElementById('issue-graph');
|
233 |
+
|
234 |
+
const myChart = new Chart(ctx, {
|
235 |
+
title: "Issues",
|
236 |
type: 'line',
|
237 |
data: {labels, datasets},
|
238 |
options: {
|
|
|
244 |
type: 'time',
|
245 |
}
|
246 |
},
|
247 |
+
plugins: {
|
248 |
+
title: {
|
249 |
+
display: true,
|
250 |
+
text: 'Number of issues, PRs, and comments on these'
|
251 |
+
}
|
252 |
+
}
|
253 |
}
|
254 |
});
|
255 |
return myChart;
|