forked from aszhang95/123proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveCSVmaker.py
42 lines (31 loc) · 976 Bytes
/
ActiveCSVmaker.py
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
from mrjob.job import MRJob
from mrjob.step import MRStep
import sys
import csv
import json
import re
import numpy as np
#python3 taskx.py csvfile > newcsvfilename
class MRFindActiveUsers(MRJob):
'''
This will yield the active users (more than 20 comments) into a csv file
as user, None
'''
def active_user_mapper(self, _, line):
line = line.split(',')
#print(line[0])
user = re.findall(r'"(.*)', line[0])[0]
yield user, 1
def active_user_combiner(self, user, count):
yield user, sum(count)
def active_user_reducer(self, user, count):
if sum(count) > 20 and np.random.uniform() > 0.9999:
yield (user, None)
def steps(self):
return [
MRStep(
mapper=self.active_user_mapper,
combiner=self.active_user_combiner,
reducer=self.active_user_reducer)]
if __name__ == '__main__':
MRFindActiveUsers.run()