Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import string
- import logging
- from util import mapper_logfile
- logging.basicConfig(filename=mapper_logfile, format='%(message)s',
- level=logging.INFO, filemode='w')
- def mapper():
- for line in sys.stdin:
- data = line.strip().split(",")
- if data[1] == 'UNIT':
- continue
- print ( "{0}\t{1}\t{2}\t{3}".format(data[1],data[2],data[3],float(data[6])))
- #logging.info( "{0}\t{1}\t{2}\t{3}".format(data[1],data[2],(data[4]),data[6]))
- mapper()
- def reducer():
- max_entries = 0
- old_key = "R001"
- datetime = ''
- for line in sys.stdin:
- data = line.strip().split("\t")
- if len(data)!=4:
- continue
- Unit , date , time , riders = data
- if old_key == Unit :
- if max_entries < riders :
- max_entries = riders
- datetime = "{0} {1}".format(date , time)
- else:
- print ("{0}\t{1}\t{2}".format(old_key ,datetime , max_entries ))
- logging.info("{0}\t{1}\t{2}".format(old_key , datetime , max_entries ))
- old_key = Unit
- max_entries = 0
- print ("{0}\t{1}\t{2}".format(old_key ,datetime , max_entries ))
- reducer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement