<s> from mrjob . job import MRJob <EOL> from mrjob . step import MRStep <EOL> import csv <EOL> cols = '<STR_LIT>' . split ( '<STR_LIT:U+002C>' ) <EOL> class salaryavg ( MRJob ) : <EOL> def avgmapper ( self , _ , line ) : <EOL> row = dict ( zip ( cols , [ a . strip ( ) for a in csv . reader ( [ line ] ) . next ( ) ] ) ) <EOL> self . increment_counter ( '<STR_LIT>' , row [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> yield row [ '<STR_LIT>' ] , ( int ( float ( row [ '<STR_LIT>' ] [ <NUM_LIT:1> : ] ) ) , <NUM_LIT:1> ) <EOL> def avgreducer ( self , key , values ) : <EOL> s = <NUM_LIT:0> <EOL> c = <NUM_LIT:0> <EOL> for average , count in values : <EOL> s += average * count <EOL> c += count <EOL> if c > <NUM_LIT:3> : <EOL> self . increment_counter ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> yield key , ( s / c , c ) <EOL> def ttmapper ( self , key , value ) : <EOL> yield None , ( value [ <NUM_LIT:0> ] , key ) <EOL> def ttreducer ( self , key , values ) : <EOL> topten = [ ] <EOL> for average , job in values : <EOL> topten . append ( ( average , job ) ) <EOL> topten . sort ( ) <EOL> topten = topten [ - <NUM_LIT:10> : ] <EOL> for average , job in topten : <EOL> yield None , ( average , job ) <EOL> def steps ( self ) : <EOL> return [ <EOL> MRStep ( mapper = self . avgmapper , <EOL> combiner = self . avgreducer , <EOL> reducer = self . avgreducer ) , <EOL> MRStep ( mapper = self . ttmapper , <EOL> combiner = self . ttreducer , <EOL> reducer = self . ttreducer ) ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> salaryavg . run ( ) </s>
