forked from iamstarkov/jsunderhood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.js
40 lines (36 loc) · 1.01 KB
/
stats.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
const maxValues = require('max-values');
const { merge } = require('ramda');
const stats = require('./helpers/tweets-stats');
const getGainedFollowers = require('./helpers/get-gained-followers');
const getDiffFollowers = require('./helpers/get-diff-followers');
function getStatsPerAuthor(authors) {
return authors
.map((author) =>
merge(author, {
gainedFollowers: getGainedFollowers(author.authorId),
}),
)
.map((author) =>
merge(author, {
diffFollowers: getDiffFollowers(author.authorId),
}),
)
.map((author) => merge(author, stats(author.tweets)));
}
const getStats = (authors) => {
if (!authors || authors.length === 0) return null;
return maxValues(getStatsPerAuthor(authors), [
'tweets',
'gainedFollowers',
'diffFollowers.gain',
'diffFollowers.loss',
'own.total',
'replies.total',
'retweets.total',
'favorited.total',
'favorited.average',
'retweeted.total',
'retweeted.average',
]);
};
module.exports = getStats;