Created
August 10, 2012 03:58
-
-
Save yayitswei/3310911 to your computer and use it in GitHub Desktop.
mrjob with parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from mrjob.job import MRJob | |
| from mrjob.protocol import JSONValueProtocol | |
| class MRConversions(MRJob): | |
| def __init__(self, duration=1, offset=0): | |
| self.duration = duration | |
| self.offset = offset | |
| self.now = datetime.date.today() | |
| def mapper(self, key, record): | |
| if record.get('action') == 'send': | |
| content = record.get('content', None) | |
| created = record.get('created', None) | |
| if created >= self.now - datetime.timedelta(self.duration + self.offset) and created < self.now - datetime.timedelta(self.offset): | |
| yield '{}_{}'.format(content, record.get('user_type')), 1 | |
| def reducer(self, key, pieces): | |
| yield key, sum(pieces) | |
| if __name__ == '__main__': | |
| MRConversions.run(2, 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment