Advertisement
Guest User

Untitled

a guest
May 24th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. import sys
  2. import string
  3. import logging
  4.  
  5. from util import mapper_logfile
  6. logging.basicConfig(filename=mapper_logfile, format='%(message)s',
  7.                     level=logging.INFO, filemode='w')
  8.  
  9. def mapper():
  10.    
  11.     for line in sys.stdin:
  12.         data = line.strip().split(",")
  13.         if data[1] == 'UNIT':
  14.             continue
  15.         print ( "{0}\t{1}\t{2}\t{3}".format(data[1],data[2],data[3],float(data[6])))
  16.         #logging.info( "{0}\t{1}\t{2}\t{3}".format(data[1],data[2],(data[4]),data[6]))
  17. mapper()
  18.  
  19. def reducer():
  20.    
  21.  
  22.     max_entries = 0
  23.     old_key = "R001"
  24.     datetime = ''
  25.  
  26.     for line in sys.stdin:
  27.         data = line.strip().split("\t")
  28.         if len(data)!=4:
  29.             continue
  30.         Unit , date , time , riders = data
  31.        
  32.         if old_key == Unit :
  33.             if max_entries < riders :
  34.                 max_entries = riders
  35.                 datetime = "{0} {1}".format(date , time)
  36.         else:
  37.             print ("{0}\t{1}\t{2}".format(old_key ,datetime , max_entries ))
  38.             logging.info("{0}\t{1}\t{2}".format(old_key , datetime , max_entries ))
  39.             old_key = Unit
  40.             max_entries = 0
  41.            
  42.     print ("{0}\t{1}\t{2}".format(old_key ,datetime , max_entries ))                    
  43. reducer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement