-
Notifications
You must be signed in to change notification settings - Fork 16
/
report.js
254 lines (231 loc) · 10.8 KB
/
report.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
const main = document.getElementById("report");
let activityLevels = [];
main.setAttribute("aria-busy", true);
const period = 12;
const grouptypes = location.search ? location.search.slice(1).split(',') : ['cg','bg'];
document.getElementById('period').textContent = period;
[...document.querySelectorAll('.grouptype')].forEach(n => n.textContent = grouptypes.includes('cg') && grouptypes.includes('wg') ? 'All groups' : (grouptypes.includes('cg') ? 'Community Groups' : 'Working Groups'));
let inscopeGroups = 0;
const lastXMonths = ((period = period) => {
const now = new Date();
const ayearago = new Date();
const months = [];
ayearago.setDate(1);
ayearago.setMonth(ayearago.getMonth() - (period - 1));
while (ayearago < now) {
months.push(ayearago.toJSON().slice(0,7));
ayearago.setMonth(ayearago.getMonth() + 1);
}
return months;
})(period);
const barWidth = 5;
const heightFactor = {
lists: 1/3,
repository: 1/3,
wiki: 1,
rss: 1,
join: 1
};
const monthBar = (month, value, type, height) => {
const bar = document.createElementNS("http://www.w3.org/2000/svg", "rect");
const isLast = month === period - 1;
bar.setAttribute("x", month * barWidth);
bar.setAttribute("y", (height-value)*heightFactor[type]);
bar.setAttribute("width", barWidth);
bar.setAttribute("height", value*heightFactor[type]);
bar.setAttribute("class", type + (isLast ? " last" : ""));
const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
title.textContent = value + " " + type + " events in " + lastXMonths[month] + (isLast ? " (data as of " + document.getElementById('timestamp').textContent + ")" : "");
bar.appendChild(title);
return bar.outerHTML;
}
const arrayfi = x => Array.isArray(x) ? x : [x];
const bar = (values, type, group, fillname) => {
const height = Math.max(...values, 0) ;
const width = barWidth*13;
const count = values.reduce((acc, d) => acc + d, 0);
return `<svg width='${width}' height='${height*heightFactor[fillname]}' viewBox='0 0 ${width} ${height * heightFactor[fillname]}' role='presentation'>` + values.map((v,i) => monthBar(i, v, fillname, height)).join(' ') + `</svg><span title='${count} ${type} events for ${group} in the last ${period} months'>${count ? Math.floor(count) : ''}</span>`;
};
const groupLink = (id) => {
const link = document.createElement("a");
link.href = typeof id === "number" ? "https://www.w3.org/2004/01/pp-impl/" + id : (id.startsWith('https://') ? id : "https://www.w3.org/community/" + id);
return link;
};
let stats = {
nochairs: 0,
nostaff: 0,
norepo: 0,
nospec: 0
};
Promise.all([
fetch("report.json").then(r => r.json()),
fetch("annotations.json").then(r => r.json())
])
.then(([{data: groupdata, timestamp}, annotations]) => {
groupdata.filter(d => d && grouptypes.includes(d.type))
.forEach(d => {
if (!d) return;
inscopeGroups++;
document.getElementById('timestamp').textContent = new Date(timestamp).toJSON().slice(0,10);
const section = document.createElement("tr");
const h2 = document.createElement("th");
const sp = document.createElement('span');
const monthsSinceStart = d.created ? Math.round((new Date() - new Date(d.created)) / (1000 * 3600 * 24 * 30)) : 0;
const monthsAndYearSinceStart = monthsSinceStart >= 12 ? Math.floor(monthsSinceStart / 12) + " year" + (monthsSinceStart >= 24 ? "s" : "") : monthsSinceStart + " months";
sp.innerHTML = `<svg width='${monthsSinceStart * 5}' height='10' viewBox='0 0 ${monthsSinceStart * 5} 10'><title>Created ${monthsAndYearSinceStart} ago</title></title><rect x='0' y='8' height='2' width='${monthsSinceStart * 5}' fill='${monthsSinceStart >= period ? "#ACF" : "#AFA"}'/></svg>`;
h2.appendChild(sp);
const link = document.createElement("a");
link.appendChild(document.createTextNode(d.name.replace(/ Community Group/, ' CG').replace(/ Working Group/, ' WG').replace(/ Interest Group/, ' IG').replace(/ Business Group/, ' BG')));
link.href = d.link;
h2.appendChild(link);
const cgshortname = d.link.split('/')[4];
section.appendChild(h2);
let total = 0;
['lists', 'repository', 'wiki', 'rss', 'join']
.forEach(servicetype => {
const activitywrapper = document.createElement("td");
const activity = document.createElement("p");
const data = d.activity[servicetype];
let values = [];
if (!data) {
activitywrapper.classList.add('nosource');
activitywrapper.title = "No known " + servicetype ;
} else if (Object.keys(data)) {
values = lastXMonths.map(m => data[m] || 0);
}
if (values.length) activitywrapper.classList.add('num');
activity.innerHTML = bar(values, servicetype, d.name, servicetype);
total += values.reduce((acc, d) => acc + d, 0);
activitywrapper.appendChild(activity);
section.appendChild(activitywrapper);
});
const related = document.createElement("td");
if (annotations[cgshortname] && (annotations[cgshortname].wg || annotations[cgshortname].postWG || annotations[cgshortname].relatedwg)) {
const groups = annotations[cgshortname].wg ? arrayfi(annotations[cgshortname].wg) : (annotations[cgshortname].relatedwg ? arrayfi(annotations[cgshortname].relatedwg) : arrayfi(annotations[cgshortname].postWG || []));
const closed = !!annotations[cgshortname].postWG;
console.log(groups);
groups.forEach(g => {
const link = groupLink(g);
link.classList.add("tag");
link.classList.add(annotations[cgshortname].wg ? "sibling" : "related");
if (g === "schemaorg") {
link.textContent = "S.o";
link.title = "Building for schema.org";
} else {
const img = document.createElement("img");
img.src = "group.svg";
img.alt = (annotations[cgshortname].wg ? "Sibling" : "Related ") + (closed ? "closed" : "" ) + " WG/IG/CG";
img.height = 10;
if (closed) link.classList.add("closed");
link.appendChild(img);
}
related.appendChild(link);
});
}
if (annotations[cgshortname] && annotations[cgshortname].funnel) {
const funnel = arrayfi(annotations[cgshortname].funnel);
funnel.forEach(f => {
const link = document.createElement("a");
link.href = "https://github.com/w3c/strategy/issues/" + f;
const img = document.createElement("img");
img.src = "funnel.svg";
img.alt = "W3C Strategy funnel entry #" + f;
img.height = 10;
link.classList.add("tag");
link.classList.add("related");
link.appendChild(img);
related.appendChild(link);
});
}
section.append(related);
const stafflist = document.createElement("td");
if (d.staff.length) {
const staff = document.createElement("span");
d.staff.sort((a,b) => (b.photo !== undefined) - (a.photo !== undefined))
.forEach(s => {
if (s.photo) {
const img = document.createElement("img");
img.src = s.photo;
img.alt = s.name;
img.width = 20;
staff.appendChild(img);
} else {
const name = document.createElement("span");
name.title = s.name;
name.appendChild(document.createTextNode(s.name.split(/[- ]/).map(n => n[0]).join('')));
staff.appendChild(name);
}
stafflist.appendChild(staff);
});
} else {
stats.nostaff++;
}
if (annotations[cgshortname] && annotations[cgshortname].dup) {
const dup = document.createElement("span");
dup.classList.add("tag");
dup.classList.add("no");
const link = groupLink(annotations[cgshortname].dup);
link.title = "duplicate of another group";
link.appendChild(document.createTextNode("dup"));
dup.appendChild(link);
related.appendChild(dup);
}
section.append(stafflist);
const notes = document.createElement("td");
if (!d["spec-publisher"] && d.type !== "wg") {
stats.nospec++;
const nospec = document.createElement("span");
nospec.classList.add("tag");
nospec.classList.add("info");
nospec.appendChild(document.createTextNode("©-only"));
notes.appendChild(nospec);
}
if (!d.chairs.length) {
stats.nochairs++;
const chairs = document.createElement("span");
chairs.classList.add("tag");
chairs.classList.add("no");
chairs.appendChild(document.createTextNode("no chair"));
notes.appendChild(chairs);
}
if (!d.activity.repository) {
stats.norepo++;
const repos = document.createElement("span");
repos.classList.add("tag");
repos.classList.add("repo");
repos.appendChild(document.createTextNode("no repo"));
notes.appendChild(repos);
}
if (d.participants <= 5) {
const participants = document.createElement("span");
participants.classList.add("tag");
participants.classList.add("participant");
participants.appendChild(document.createTextNode(d.participants + " participant" + (d.participants > 1 ? "s" : "")));
notes.appendChild(participants);
}
const activityLevel = total * 1000 + d.participants;
section.appendChild(notes);
const idx = activityLevels.findIndex(x => activityLevel > x);
if (idx >= 0) {
main.insertBefore(section, main.children[idx]);
} else {
main.appendChild(section);
}
activityLevels.push(activityLevel);
activityLevels.sort((a,b) => b - a);
});
const statList = document.getElementById("stats");
const chairstat = document.createElement("li");
chairstat.appendChild(document.createTextNode(`${stats.nochairs} (${Math.round(100 * stats.nochairs / inscopeGroups)}%) groups have no chair`));
statList.appendChild(chairstat);
const staffstat = document.createElement("li");
staffstat.appendChild(document.createTextNode(`${stats.nostaff} (${Math.round(100 * stats.nostaff / inscopeGroups)}%) groups have no representative from the W3C staff`));
statList.appendChild(staffstat);
const repostat = document.createElement("li");
repostat.appendChild(document.createTextNode(`${stats.norepo} (${Math.round(100 * stats.norepo / inscopeGroups)}%) groups have no known repository`));
statList.appendChild(repostat);
const specstat = document.createElement("li");
specstat.appendChild(document.createTextNode(`${stats.nospec} (${Math.round(100 * stats.nospec / inscopeGroups)}%) groups are not intending to build technical specifications`));
statList.appendChild(specstat);
main.setAttribute("aria-busy", false);
});