forked from iamstarkov/cssunderhood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.js
46 lines (37 loc) · 1.61 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
41
42
43
44
45
46
import fs from 'fs-extra';
import authors from './authors';
const isOwn = tweet => !isReply(tweet) && !isRetweet(tweet);
const isRetweet = tweet => !!tweet.retweeted_status;
const isReplyToSelf = tweet => tweet.in_reply_to_screen_name === 'cssunderhood';
const isReply = tweet => !!tweet.in_reply_to_screen_name && !isReplyToSelf(tweet);
const sumRetweeted = (state, tweet) => state + tweet.retweet_count;
const sumFavorited = (state, tweet) => state + tweet.favorite_count;
const analyze = (author)=> {
var rt = 0, fav = 0;
const username = author.username;
const _tweets = author.tweets;
const tweets = _tweets.length;
const _ownTweets = _tweets.filter(isOwn);
const percent = tweets / 100;
const ownTweets = _ownTweets.length;
const ownTweetsPercentage = ownTweets / percent;
const retweets = _tweets.filter(isRetweet).length;
const retweetsPercentage = retweets / percent;
const replies = _tweets.filter(isReply).length;
const repliesPercentage = replies / percent;
const retweeted = _ownTweets.reduce(sumRetweeted, 0);
const favorited = _ownTweets.reduce(sumFavorited, 0);
const retweetedKpi = Number((retweeted / ownTweets).toFixed(2));
const favoritedKpi = Number((favorited / ownTweets).toFixed(2));
fs.outputJson(`dump/${author.username}-stats.json`, {
username, tweets,
ownTweets, ownTweetsPercentage,
retweets, retweetsPercentage,
replies, repliesPercentage,
retweeted, retweetedKpi,
favorited, favoritedKpi
}, err => console.log(`${author.username} done`));
}
authors.forEach((item)=> {
fs.readJson(`dump/${item.username}.json`, (err, author) => analyze(author));
});