forked from aaronjorbin/wp-newbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
123 lines (115 loc) · 3.95 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
var _ = require( 'underscore' ),
versions = [ '3.2', '3.3', '3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4.0', '4.1', '4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4', '5.5', '5.6' ],
rp = require('request-promise'),
Promise = require("bluebird"),
AsciiTable = require('ascii-table')
fs = require('fs');
const releaseDay = ( process.argv[2] == 'day' );
console.log( releaseDay );
var requests = versions.map( v => rp( 'http://api.wordpress.org/core/credits/1.1/?version=' + v ) );
function overlap ( v1, v2 ) {
return Math.round( ( _.intersection( v1, v2 ).length / v1.length ) * 100 ) + '%';
}
Promise.all( requests ).then( function( responses ){
console.log( 'props being processed' );
return new Promise( function (resolve, reject) {
var props = [];
responses.forEach( r => {
var data = JSON.parse( r );
var groups = Object.keys( data.groups );
var version = data.data.version;
props[ version ] = [];
groups.forEach( g => {
if ( g !== 'libraries' ) {
props[ version ] = props[ version ].concat(
Object.keys( data.groups[g].data ).map( s => s.toLowerCase() )
);
}
});
props[ version ] = _.uniq( props[ version ] );
if ( releaseDay ) {
const shortName = version.replace( '.', '');
props[version] = require( './releaseday/' + shortName + '.json' );
}
});
resolve( props );
});
}).then( function( props ){
console.log( 'building prop list' );
return new Promise( function (resolve, reject) {
var lastVersion = false,
unions = [],
newbs = [],
forward = [],
frequency = {};
versions.forEach( v => {
if ( lastVersion ){
unions[ v ] = _.union( props[ v ] , unions[ lastVersion ] );
newbs[ v ] = _.difference( props[ v ], unions[ lastVersion ] );
} else {
unions[ v ] = props[v];
newbs[ v ] = props[v];
}
props[v].forEach( ps => {
if( typeof( frequency[ps.toLowerCase()] ) === 'undefined' ){
frequency[ps.toLowerCase()] = [];
}
frequency[ps.toLowerCase()].push( v );
frequency[ps.toLowerCase()] = _.uniq( frequency[ps.toLowerCase()] );
});
lastVersion = v;
});
lastVersion = false;
versions.reverse();
versions.forEach( v => {
if ( lastVersion ){
forward[ v ] = _.union( props[ lastVersion ] , forward[ lastVersion ] );
} else {
forward[ v ] = [];
}
lastVersion = v;
});
resolve( [ newbs, props, unions, frequency, forward ] );
});
}).then( function( r ){
var newbs = r[0],
props = r[1],
unions = r[2],
frequency = r[3],
forward = r[4];
return new Promise( function (resolve, reject) {
console.log( 'Build Table' );
var overlap_colums = [''].concat( versions );
var howFrequent = {};
table = new AsciiTable( 'Contributors' ).setHeading('Version', 'Total', 'New', 'Percent New' )
overlapTable = new AsciiTable( 'Overlap' ).setHeading( overlap_colums );
frequencyTable = new AsciiTable( 'Versions WP contributors' ).setHeading( 'Versions', 'Uniq Individuals' );
forwardTable = new AsciiTable( 'Future Contributors' ).setHeading('Version', 'Total', 'return Percent' )
versions.forEach( v => {
var overlaps = [v];
versions.forEach( v2 => {
overlaps.push( overlap( props[v], props[v2] ) );
});
overlapTable.addRow( overlaps );
table.addRow( v , props[v].length, newbs[v].length,
parseInt( 100 * ( newbs[v].length / props[v].length )) + '%' );
forwardTable.addRow( v, props[v].length, overlap( props[v], forward[v] ) );
});
_.each( frequency, ( versions, person ) => {
if ( typeof( howFrequent[ versions.length ] ) === 'undefined' ){
howFrequent[ versions.length ] = [];
}
howFrequent[ versions.length ].push( person );
});
console.log( howFrequent );
_.each(howFrequent, ( p, f ) => {
frequencyTable.addRow( f, p.length );
});
resolve( table );
});
}).then( function(){
console.log(table.toString());
console.log(overlapTable.toString());
console.log(frequencyTable.toString());
console.log(forwardTable.toString());
});;