-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathopen_leaderboard.ts
536 lines (510 loc) · 27.3 KB
/
open_leaderboard.ts
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { Task } from '..';
import { getRepoActivity, getRepoOpenrank, getUserActivity, getUserCommunityOpenrank } from '../../metrics/indices';
import { forEveryMonth } from '../../metrics/basic';
import { getLogger, rankData } from '../../utils';
import { getPlatformData } from '../../label_data_utils';
const task: Task = {
cron: '0 0 15 * *', // runs on the 15th day of every month at 00:00
callback: async () => {
const logger = getLogger('OpenLeaderboardTask');
logger.info(`Start to run open leaderboard task.`);
const startYear = 2015, startMonth = 1, now = new Date();
now.setMonth(now.getMonth() - 1);
const endYear = now.getFullYear(), endMonth = now.getMonth() + 1;
const limit = 300;
const allMonthes: string[] = [];
await forEveryMonth(startYear, startMonth, endYear, endMonth, async (y, m) => allMonthes.push(`${y}${m}`));
const allYears = Array.from({ length: endYear - startYear + 1 }, (_, i) => i + startYear);
const writeData = (dataMap: Map<any, any>, type: string, path: string) => {
for (const [time, data] of dataMap.entries()) {
const dir = `./local_files/open_leaderboard/${path}`;
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
writeFileSync(`./local_files/open_leaderboard/${path}/${time}.json`, JSON.stringify({
type, time, data,
}));
}
};
const exportUserTableName = 'export_user', exportRepoTableName = 'export_repo';
// get chinese month actor activity
const chineseUserMonthActivityData = await getUserActivity({
labelUnion: [':regions/CN'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupTimeRange: 'month', limitOption: 'each',
});
logger.info(`Get chinese user month activity data done, count=${chineseUserMonthActivityData.length}`);
const chineseUserMonthActivityMap = rankData(chineseUserMonthActivityData!, allMonthes, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
id: item.id,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of chineseUserMonthActivityMap.keys()) {
chineseUserMonthActivityMap.set(k, chineseUserMonthActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseUserMonthActivityMap, 'Actor_China_Month', 'activity/actor/chinese');
// get chinese actor year acitivity
const chineseUserYearActivityData = await getUserActivity({
labelUnion: [':regions/CN'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupTimeRange: 'year', limitOption: 'each',
});
logger.info(`Get chinese user year activity data done, count=${chineseUserYearActivityData.length}`);
const chineseUserYearActivityMap = rankData(chineseUserYearActivityData!, allYears, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
id: item.id,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of chineseUserYearActivityMap.keys()) {
chineseUserYearActivityMap.set(k, chineseUserYearActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseUserYearActivityMap, 'Actor_China_Year', 'activity/actor/chinese');
logger.info('Chinese actor activity done.');
// get global actor activity
const globalUserMonthActivityData = await getUserActivity({
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'month', whereClause: `actor_id IN (SELECT id FROM ${exportUserTableName})`,
}, false);
logger.info(`Get global user month activity data done, count=${globalUserMonthActivityData.length}`);
const globalUserMonthActivityMap = rankData(globalUserMonthActivityData!, allMonthes, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
id: item.id,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of globalUserMonthActivityMap.keys()) {
globalUserMonthActivityMap.set(k, globalUserMonthActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalUserMonthActivityMap, 'Actor_Global_Month', 'activity/actor/global');
const globalUserYearActivityData = await getUserActivity({
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'year', whereClause: `actor_id IN (SELECT id FROM ${exportUserTableName})`,
}, false);
logger.info(`Get global user year activity data done, count=${globalUserYearActivityData.length}`);
const globalUserYearActivityMap = rankData(globalUserYearActivityData!, allYears, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
id: item.id,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of globalUserYearActivityMap.keys()) {
globalUserYearActivityMap.set(k, globalUserYearActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalUserYearActivityMap, 'Actor_Global_Year', 'activity/actor/global');
logger.info('Global actor activity done.');
// get chinese company activity
// by month
const chineseCompanyMonthActivityData = await getRepoActivity({
labelIntersect: ['Company', ':regions/CN'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupBy: 'Company', limitOption: 'each',
groupTimeRange: 'month',
});
logger.info(`Get chinese company month activity data done, count=${chineseCompanyMonthActivityData?.length}`);
const chineseCompanyMonthActivityMap = rankData(chineseCompanyMonthActivityData!, allMonthes, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of chineseCompanyMonthActivityMap.keys()) {
chineseCompanyMonthActivityMap.set(k, chineseCompanyMonthActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseCompanyMonthActivityMap, 'Company_China_Month', 'activity/company/chinese');
// by year
const chineseCompanyYearActivityData = await getRepoActivity({
labelIntersect: ['Company', ':regions/CN'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupBy: 'Company', limitOption: 'each',
groupTimeRange: 'year',
});
logger.info(`Get chinese company year activity data done, count=${chineseCompanyYearActivityData?.length}`);
const chineseCompanyYearActivityMap = rankData(chineseCompanyYearActivityData!, allYears, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of chineseCompanyYearActivityMap.keys()) {
chineseCompanyYearActivityMap.set(k, chineseCompanyYearActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseCompanyYearActivityMap, 'Repo_China_Year', 'activity/company/chinese');
logger.info('Chinese company activity done.');
// get global company activity
// by month
const globalCompanyMonthActivityData = await getRepoActivity({
labelUnion: ['Company'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupBy: 'Company', limitOption: 'each',
groupTimeRange: 'month',
});
logger.info(`Get global company month activity data done, count=${globalCompanyMonthActivityData?.length}`);
const globalCompanyMonthActivityMap = rankData(globalCompanyMonthActivityData!, allMonthes, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of globalCompanyMonthActivityMap.keys()) {
globalCompanyMonthActivityMap.set(k, globalCompanyMonthActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalCompanyMonthActivityMap, 'Company_Global_Month', 'activity/company/global');
// by year
const globalCompanyYearActivityData = await getRepoActivity({
labelUnion: ['Company'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupBy: 'Company', limitOption: 'each',
groupTimeRange: 'year',
});
logger.info(`Get global company year activity data done, count=${globalCompanyYearActivityData?.length}`);
const globalCompanyYearActivityMap = rankData(globalCompanyYearActivityData!, allYears, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of globalCompanyYearActivityMap.keys()) {
globalCompanyYearActivityMap.set(k, globalCompanyYearActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalCompanyYearActivityMap, 'Repo_Global_Year', 'activity/company/global');
logger.info('Global company activity done.');
// get global repo activity
// by month
const globalRepoMonthActivityData = await getRepoActivity({
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'month', whereClause: `repo_id IN (SELECT id FROM ${exportRepoTableName})`,
});
logger.info(`Get global repo month activity data done, count=${globalRepoMonthActivityData?.length}`);
const globalRepoMonthActivityMap = rankData(globalRepoMonthActivityData!, allMonthes, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of globalRepoMonthActivityMap.keys()) {
globalRepoMonthActivityMap.set(k, globalRepoMonthActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalRepoMonthActivityMap, 'Repo_Global_Month', 'activity/repo/global');
// by year
const globalRepoYearActivityData = await getRepoActivity({
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'year', whereClause: `repo_id IN (SELECT id FROM ${exportRepoTableName})`,
});
logger.info(`Get global repo year activity data done, count=${globalRepoYearActivityData?.length}`);
const globalRepoYearActivityMap = rankData(globalRepoYearActivityData!, allYears, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of globalRepoYearActivityMap.keys()) {
globalRepoYearActivityMap.set(k, globalRepoYearActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalRepoYearActivityMap, 'Repo_Global_Year', 'activity/repo/global');
logger.info('Global repo activity done.');
// get Chinese repo activity
// by month
const chineseRepoMonthActivityData = await getRepoActivity({
labelUnion: [':regions/CN'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupTimeRange: 'month', limitOption: 'each',
});
logger.info(`Get chinese repo month activity data done, count=${chineseRepoMonthActivityData?.length}`);
const chineseRepoMonthActivityMap = rankData(chineseRepoMonthActivityData!, allMonthes, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of chineseRepoMonthActivityMap.keys()) {
chineseRepoMonthActivityMap.set(k, chineseRepoMonthActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseRepoMonthActivityMap, 'Repo_China_Month', 'activity/repo/chinese');
// by year
const chineseRepoYearActivityData = await getRepoActivity({
labelUnion: [':regions/CN'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupTimeRange: 'year', limitOption: 'each',
});
logger.info(`Get chinese repo year activity data done, count=${chineseRepoYearActivityData?.length}`);
const chineseRepoYearActivityMap = rankData(chineseRepoYearActivityData!, allYears, (item, _, index) => item.activity[index], (item, index) => {
return {
name: item.name,
issue_comment: item.issue_comment[index],
open_issue: item.open_issue[index],
open_pull: item.open_pull[index],
review_comment: item.review_comment[index],
merged_pull: item.merged_pull[index],
}
});
for (const k of chineseRepoYearActivityMap.keys()) {
chineseRepoYearActivityMap.set(k, chineseRepoYearActivityMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseRepoYearActivityMap, 'Repo_China_Year', 'activity/repo/chinese');
logger.info('Chinese repo activity done.');
// get Chinese actor OpenRank
// by month
const chineseUserLabelData = getPlatformData([':regions/CN']);
const platformData: any = chineseUserLabelData.map(i => ({
platform: i.name,
userIds: i.users.map(u => u.id),
}));
const chineseUserMonthOpenrankData = await getUserCommunityOpenrank({
idOrNames: platformData,
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupTimeRange: 'month', limitOption: 'each',
});
logger.info(`Get chinese user month openrank data done, count=${chineseUserMonthOpenrankData.length}`);
const chineseUserMonthOpenrankMap = rankData(chineseUserMonthOpenrankData!, allMonthes, (item, _, index) => item.openrank[index], item => { return { name: item.name, id: item.id }; });
for (const k of chineseUserMonthOpenrankMap.keys()) {
chineseUserMonthOpenrankMap.set(k, chineseUserMonthOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseUserMonthOpenrankMap, 'Actor_China_Month', 'open_rank/actor/chinese');
// by year
const chineseUserYearOpenrankData = await getUserCommunityOpenrank({
idOrNames: platformData,
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupTimeRange: 'year', limitOption: 'each',
});
logger.info(`Get chinese user year openrank data done, count=${chineseUserYearOpenrankData.length}`);
const chineseUserYearOpenrankMap = rankData(chineseUserYearOpenrankData!, allYears, (item, _, index) => item.openrank[index], item => { return { name: item.name, id: item.id }; });
for (const k of chineseUserYearOpenrankMap.keys()) {
chineseUserYearOpenrankMap.set(k, chineseUserYearOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseUserYearOpenrankMap, 'Actor_China_Year', 'open_rank/actor/chinese');
logger.info('Chinese actor OpenRank done.');
// get global actor OpenRank
// by month
// too memory consuming, split to batches and merge in memory
const globalUserMonthOpenrankDataArray = [
await getUserCommunityOpenrank({
startYear, startMonth, endYear: 2019, endMonth: 12,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'month', options: { withoutDetail: true, withBot: false }
}), await getUserCommunityOpenrank({
startYear: 2020, startMonth: 1, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'month', options: { withoutDetail: true, withBot: false }
})
];
const globalUserMonthOpenrankData = globalUserMonthOpenrankDataArray[0];
const firstBatchMonthes = globalUserMonthOpenrankDataArray[0][0].openrank.length;
const secondBatchMonthes = globalUserMonthOpenrankDataArray[1][0].openrank.length;
for (const row of globalUserMonthOpenrankData) {
const { platform, name } = row;
const secondRow = globalUserMonthOpenrankDataArray[1].find(i => i.name === name && i.platform === platform);
if (secondRow) {
// second batch has the user
row.openrank = row.openrank.concat(secondRow.openrank);
} else {
// the user not found in the second batch
row.openrank = row.openrank.concat(Array.from({ length: secondBatchMonthes }, () => 0));
}
}
for (const row of globalUserMonthOpenrankDataArray[1]) {
const { platform, name, openrank } = row;
const firstRow = globalUserMonthOpenrankDataArray[0].find(i => i.name === name && i.platform === platform);
if (!firstRow) {
// the user not found in the first batch
globalUserMonthOpenrankData.push({
platform, name, openrank: Array.from({ length: firstBatchMonthes }, () => 0).concat(openrank)
});
}
}
logger.info(`Get global user month openrank data done, count=${globalUserMonthOpenrankData.length}`);
let globalUserMonthOpenrankMap = rankData(globalUserMonthOpenrankData!, allMonthes, (item, _, index) => item.openrank[index], item => { return { name: item.name, id: item.id }; });
for (const k of globalUserMonthOpenrankMap.keys()) {
globalUserMonthOpenrankMap.set(k, globalUserMonthOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalUserMonthOpenrankMap, 'Actor_Global_Month', 'open_rank/actor/global');
// by year
const globalUserYearOpenrankData = await getUserCommunityOpenrank({
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'year', options: { withoutDetail: true, withBot: false }
});
logger.info(`Get global user year openrank data done, count=${globalUserYearOpenrankData.length}`);
const globalUserYearOpenrankMap = rankData(globalUserYearOpenrankData!, allYears, (item, _, index) => item.openrank[index], item => { return { name: item.name, id: item.id }; });
for (const k of globalUserYearOpenrankMap.keys()) {
globalUserYearOpenrankMap.set(k, globalUserYearOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalUserYearOpenrankMap, 'Actor_Global_Year', 'open_rank/actor/global');
logger.info('Global actor OpenRank done.');
// get Chinese repo OpenRank
// by month
const chineseRepoMonthOpenrankData = await getRepoOpenrank({
labelUnion: [':regions/CN'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2,
groupTimeRange: 'month', limitOption: 'each',
});
logger.info(`Get chinese repo month openrank data done, count=${chineseRepoMonthOpenrankData.length}`);
const chineseRepoMonthOpenrankMap = rankData(chineseRepoMonthOpenrankData!, allMonthes, (item, _, index) => item.openrank[index], item => { return { name: item.name }; });
for (const k of chineseRepoMonthOpenrankMap.keys()) {
chineseRepoMonthOpenrankMap.set(k, chineseRepoMonthOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseRepoMonthOpenrankMap, 'Repo_China_Month', 'open_rank/repo/chinese');
// by year
const chineseRepoYearOpenrankData = await getRepoOpenrank({
labelUnion: [':regions/CN'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2,
groupTimeRange: 'year', limitOption: 'each',
});
logger.info(`Get chinese repo year openrank data done, count=${chineseRepoYearOpenrankData.length}`);
const chineseRepoYearOpenrankMap = rankData(chineseRepoYearOpenrankData!, allYears, (item, _, index) => item.openrank[index], item => { return { name: item.name }; });
for (const k of chineseRepoYearOpenrankMap.keys()) {
chineseRepoYearOpenrankMap.set(k, chineseRepoYearOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseRepoYearOpenrankMap, 'Repo_China_Year', 'open_rank/repo/chinese');
logger.info('Chinese repo OpenRank done.');
// get Chinese company
// by month
const chineseCompanyRepoMonthOpenrankData = await getRepoOpenrank({
labelIntersect: [':regions/CN', 'Company'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'month', groupBy: 'Company',
});
logger.info(`Get chinese company repo month openrank data done, count=${chineseCompanyRepoMonthOpenrankData.length}`);
const chineseCompanyRepoMonthOpenrankMap = rankData(chineseCompanyRepoMonthOpenrankData!, allMonthes, (item, _, index) => item.openrank[index], item => { return { name: item.name }; });
for (const k of chineseCompanyRepoMonthOpenrankMap.keys()) {
chineseCompanyRepoMonthOpenrankMap.set(k, chineseCompanyRepoMonthOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseCompanyRepoMonthOpenrankMap, 'Company_China_Month', 'open_rank/company/chinese');
// by year
const chineseCompanyRepoYearOpenrankData = await getRepoOpenrank({
labelIntersect: [':regions/CN', 'Company'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2, limitOption: 'each',
groupTimeRange: 'year', groupBy: 'Company',
});
logger.info(`Get chinese company repo year openrank data done, count=${chineseCompanyRepoYearOpenrankData.length}`);
const chineseCompanyRepoYearOpenrankMap = rankData(chineseCompanyRepoYearOpenrankData!, allYears, (item, _, index) => item.openrank[index], item => { return { name: item.name }; });
for (const k of chineseCompanyRepoYearOpenrankMap.keys()) {
chineseCompanyRepoYearOpenrankMap.set(k, chineseCompanyRepoYearOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(chineseCompanyRepoYearOpenrankMap, 'Company_China_Year', 'open_rank/company/chinese');
logger.info('Chinese company OpenRank done.');
// get global repo OpenRank
// by month
const globalRepoMonthOpenrankData = await getRepoOpenrank({
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'month', whereClause: `repo_id IN (SELECT id FROM ${exportRepoTableName})`,
});
logger.info(`Get global repo month openrank data done, count=${globalRepoMonthOpenrankData.length}`);
const globalRepoMonthOpenrankMap = rankData(globalRepoMonthOpenrankData!, allMonthes, (item, _, index) => item.openrank[index], item => { return { name: item.name }; });
for (const k of globalRepoMonthOpenrankMap.keys()) {
globalRepoMonthOpenrankMap.set(k, globalRepoMonthOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalRepoMonthOpenrankMap, 'Repo_Global_Month', 'open_rank/repo/global');
// by year
const globalRepoYearOpenrankData = await getRepoOpenrank({
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit, precision: 2, limitOption: 'each',
groupTimeRange: 'year', whereClause: `repo_id IN (SELECT id FROM ${exportRepoTableName})`,
});
logger.info(`Get global repo year openrank data done, count=${globalRepoYearOpenrankData.length}`);
const globalRepoYearOpenrankMap = rankData(globalRepoYearOpenrankData!, allYears, (item, _, index) => item.openrank[index], item => { return { name: item.name }; });
for (const k of globalRepoYearOpenrankMap.keys()) {
globalRepoYearOpenrankMap.set(k, globalRepoYearOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalRepoYearOpenrankMap, 'Repo_Global_Year', 'open_rank/repo/global');
logger.info('Global repo OpenRank done.');
// get global company
// by month
const globalCompanyRepoMonthOpenrankData = await getRepoOpenrank({
labelUnion: ['Company'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2, limitOption: 'each',
groupTimeRange: 'month', groupBy: 'Company',
});
logger.info(`Get global company repo month openrank data done, count=${globalCompanyRepoMonthOpenrankData.length}`);
const globalCompanyRepoMonthOpenrankMap = rankData(globalCompanyRepoMonthOpenrankData!, allMonthes, (item, _, index) => item.openrank[index], item => { return { name: item.name }; });
for (const k of globalCompanyRepoMonthOpenrankMap.keys()) {
globalCompanyRepoMonthOpenrankMap.set(k, globalCompanyRepoMonthOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalCompanyRepoMonthOpenrankMap, 'Company_Global_Month', 'open_rank/company/global');
// by year
const globalCompanyRepoYearOpenrankData = await getRepoOpenrank({
labelUnion: ['Company'],
startYear, startMonth, endYear, endMonth,
order: 'DESC', limit: -1, precision: 2, limitOption: 'each',
groupTimeRange: 'year', groupBy: 'Company',
});
logger.info(`Get global company repo year openrank data done, count=${globalCompanyRepoYearOpenrankData.length}`);
const globalCompanyRepoYearOpenrankMap = rankData(globalCompanyRepoYearOpenrankData!, allYears, (item, _, index) => item.openrank[index], item => { return { name: item.name }; });
for (const k of globalCompanyRepoYearOpenrankMap.keys()) {
globalCompanyRepoYearOpenrankMap.set(k, globalCompanyRepoYearOpenrankMap.get(k)!.filter(i => i.value > 0));
}
writeData(globalCompanyRepoYearOpenrankMap, 'Company_Global_Year', 'open_rank/company/global');
logger.info('Global company OpenRank done.');
writeFileSync('./local_files/open_leaderboard/meta.json', JSON.stringify({ lastUpdatedAt: new Date().getTime() }));
logger.info('Task for open leaderboard done.');
}
};
module.exports = task;