-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
305 lines (278 loc) · 12.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// Used to make an ES2015+ ready environment on current browsers
import "@babel/polyfill"
import i18next from 'i18next';
import dayjs from 'dayjs'
import '@vaadin/vaadin-date-picker/vaadin-date-picker.js';
// UIUtils (to make analysis containers)
import UIUtils from './helpers/ui.utils';
// Custom helpers
// D3 Related should be exported from that package
import {
// drawPie,
drawHorizontalBarGraph,
drawLine,
drawTendanceGraph
} from './helpers/d3.utils';
// Progress handler
import { Progress } from './helpers/progress.utils';
import {
eventTypes,
getFromGHArchive,
filterDataByEvent,
getPeriodFromGH,
getPreparedData
} from './helpers/ghArchive.utils';
import { languageResource } from "./helpers/i18n.utils";
// import { callGitHubForTopic } from "./helpers/githubApi.utils";
import { parsePullRequestsLanguages, parseCommonWordsInCommits, convertMS, meanIssue } from "./helpers/analysis.utils";
const i18n = i18next.init({
lng: 'en',
debug: true,
resources: languageResource
});
i18n.on('languageChanged', (_lang) => {
// console.log('recreating UI for', _lang);
makeUI();
});
// HTML Elements
const debugZone = document.querySelector('#debug');
const debugElement = document.querySelector('#debugProgress');
const debugProgressTitle = document.querySelector('#debugProgressTitle');
const debugProgress = new Progress(debugElement, debugProgressTitle);
debugProgress.hide();
makeUI();
UIUtils.bindLangFlags(i18n);
/**
* Paint entire "web-app" ui
* (called on page load / lang change)
*/
function makeUI(){
const currentLang = i18n.languages[0];
const siteTitle = i18n.t('siteTitle');
document.querySelector('html').lang = currentLang;
document.querySelector('.title').innerText = siteTitle;
document.title = siteTitle;
// GHArchive utils
// Analysis #1 Languages distributions in Pull requests for a given date
UIUtils.makeAnalysisContainer(
'languageDistribution',
i18n.t('analysis1'),
{
inputValue: "2018-01-01",
inputValueHour: 12,
component: 'button',
title: i18n.t('invert'),
onStart: async function(){
debugProgress.show(i18n.t('analysisInProgress'));
const date = this.input.value;
if(!date || this.hourInput.value > 23 || this.hourInput.value < 0) return;
try {
const context = this;
const parsedObjects = await getFromGHArchive(date+"-"+this.hourInput.value, debugProgress);
// Filtering every pullRequest
const pullRequests = filterDataByEvent(parsedObjects, eventTypes.pullRequest);
debugProgress.total(pullRequests.length);
// Instanciate a new languages object
const languages = parsePullRequestsLanguages(pullRequests, debugProgress);
// draw d3 pie
// drawPie(languages, date, this.pie, "language", "count");
context.isDesc = true;
languages.sort((langA, langB) => langB.count - langA.count);
drawHorizontalBarGraph(this.pie, languages, "language", "count", true);
this.input.style.border = "";
// @tools debug
// console.log(`Languages distribution in pull requests :`, languages);
debugZone.style.display = "block";
debugZone.innerHTML = JSON.stringify(languages, null, 2);
debugProgress.hide();
} catch (err) {
this.input.style.border = "1px solid red";
throw err;
}
},
onUpdate: async function(event) {
debugProgress.show(i18n.t('analysisInProgress'));
const context = this;
const parsedObjects = await getFromGHArchive(this.input.value+"-"+this.hourInput.value, debugProgress);
const pullRequests = filterDataByEvent(parsedObjects, eventTypes.pullRequest);
if(context.isDesc === true){
context.isDesc = false;
} else {
context.isDesc = true;
}
const languages = parsePullRequestsLanguages(pullRequests,debugProgress).sort((langA, langB) => context.isDesc ? langB.count - langA.count : langA.count - langB.count);
drawHorizontalBarGraph(this.pie, languages, "language", "count", true);
debugProgress.total(pullRequests.length);
debugProgress.hide();
debugZone.style.display = "block";
debugZone.innerHTML = JSON.stringify(languages, null, 2);
}
}, i18n);
const numberOfWords = 20;
UIUtils.makeAnalysisContainer(
'drawCommonWords',
i18n.t('analysis2'),
{
inputValue: "2018-01-01",
inputValueHour: 12,
onStart: async function(){
debugProgress.show(i18n.t('analysisInProgress'));
// https://developers.google.com/machine-learning/guides/text-classification/step-2
const date = this.input.value;
if(!date || this.hourInput.value > 23 || this.hourInput.value < 0){
return;
}
// TODO XXX : Remove bots
try {
const part = await parseCommonWordsInCommits(this.input.value+"-"+this.hourInput.value, numberOfWords, debugProgress);
drawHorizontalBarGraph(this.pie, part, "pair", "occurences", true);
// drawPie(part, date, this.pie, "pair", "occurences");
console.timeEnd();
debugZone.style.display = "block";
debugZone.innerHTML = JSON.stringify(part, null, 2);
debugProgress.hide();
} catch (err) {
this.input.style.border = "1px solid red";
throw err;
}
},
component: 'range',
title: i18n.t('numberOfWords'),
min: 1,
max: 500,
initialValue: numberOfWords,
onUpdate: async function(event) {
const context = this;
const part = await parseCommonWordsInCommits(this.input.value+"-"+this.hourInput.value, event.target.value, debugProgress);
drawHorizontalBarGraph(this.pie, part, "pair", "occurences", true);
// drawPie(part, context.input.value, context.pie, "pair", "occurences", true, true);
}
}, i18n);
UIUtils.makeAnalysisContainer(
'timeToResolveIssues',
i18n.t('analysis3'),
{
inputValue: "2018-01-01",
onStart: async function(){
debugProgress.show(i18n.t('analysisInProgress'));
const startDate = this.input.value;
const endDate = document.querySelector("#endDateInput").value;
if(!startDate && !endDate){
return;
}
const periods = await getPeriodFromGH(`${startDate}`, `${endDate}`, debugProgress)
const dataset = [];
Object.keys(periods).map((period)=>{
const issuesEvents = filterDataByEvent(periods[period].data, eventTypes.issues);
const middleTimeToResolve = issuesEvents
.filter((issue)=>{
return issue.payload.issue.created_at !== null && issue.payload.issue.closed_at !== null
})
.map((issue)=>{
return dayjs(issue.payload.issue.closed_at).diff(dayjs(issue.payload.issue.created_at));
});
let x = convertMS(meanIssue(middleTimeToResolve));
dataset.push(
{
"y":x,
"x":period
}
)
//console.log("For period : " + period + ", the mean time is : " + x.day + "d " + x.hour + "h " + x.minute + "m " + x.seconds + "s")
});
drawLine(dataset, this.pie, i18n.t('date'), i18n.t('meanTimeInDays'), false, true, function(a, b, c) {
console.warn('For period : ', a.x, ' the middle time in day is ', a.y.day);
});
debugProgress.hide();
},
onMount: function() {
// This function create an input to enable choosing an end date
// for the timeToResolveIssues analysis
const endDateInputValue = "2018-01-02";
let panel = this.panel
let endDateInput = document.createElement("vaadin-date-picker");
let toText = document.createElement("span");
endDateInput.id = "endDateInput";
endDateInput.value = endDateInputValue;
panel.insertBefore(endDateInput, this.input.nextSibling);
toText.innerHTML = i18n.t('\t\tto\t\t');
panel.insertBefore(toText, endDateInput);
},
onUpdate: function(){
// Todo?
}
},
i18n
);
// TODO XXX :
// Use commit messages to classify by tasks, will be more useful as we are in hours/days
// Make a dictionary of words related to specific programmer tasks :
// UI, fix, .....
// Classify every commit message found in a category
// If we have time to do it...
/* UIUtils.makeAnalysisContainer(
'topicBasedAnalysis',
i18n.t('topicBasedAnalysis'),
{
onMount: function() {
const context = this;
/*
Append a topic add list, [TopicName, TopicInput] + AddButton
Append a "period choicer"
},
onStart: function(){
console.warn('WIP : Implement topic based analysis');
/*
will use : callGitHubForTopic("https://github.com/:owner/:repo", debugProgress);
and getPeriodFromGH
Draw an analysis container
Topic adder to train classifier with repository url
React : reactRepoURL
+ button to append
On "Train click" -> Train foreach topics
Period choice from : to:
bar graph of occurences in commit messages for period
}
}, i18n);*/
UIUtils.makeAnalysisContainer(
'Tendance2016',
i18n.t('Tendance2016'),
{
onMount: async function(){
const context = this;
let theYear = 2016;
const aButton = document.createElement("button");
aButton.className = 'analysis-start';
aButton.style.margin = '1em';
aButton.id="tendanceButton";
aButton.innerHTML=2016;
const thePie = this.pie;
aButton.onclick = function() {
if(theYear == 2016){
theYear++;
} else{
theYear--;
}
aButton.innerHTML=theYear;
while (thePie.firstChild) {
thePie.removeChild(thePie.firstChild);
}
prepareTendanceGraph(theYear, thePie);
};
let panel = this.panel
panel.insertBefore(aButton, this.pie);
const prepareTendanceGraph = async function(date, apie){
try {
const parsedObjects = await getPreparedData(date, debugProgress);
const theObject = parsedObjects[0];
drawTendanceGraph(apie, theObject,date);
} catch (err) {
console.warn("Something went wrong during data download.");
throw err;
}
}
prepareTendanceGraph(theYear, this.pie);
},
}, i18n);
UIUtils.bindAccordions();
}