<s> from __future__ import absolute_import <EOL> import logging <EOL> from operator import itemgetter <EOL> from pyleus . storm import SimpleBolt <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> class TopGlobalBolt ( SimpleBolt ) : <EOL> OPTIONS = [ "<STR_LIT:N>" ] <EOL> OUTPUT_FIELDS = [ "<STR_LIT>" ] <EOL> def initialize ( self ) : <EOL> self . top_N = [ ] <EOL> self . N = self . options [ "<STR_LIT:N>" ] <EOL> def process_tick ( self ) : <EOL> log . debug ( "<STR_LIT>" ) <EOL> log . debug ( self . top_N ) <EOL> self . emit ( ( self . top_N , ) ) <EOL> self . top_N = [ ] <EOL> def process_tuple ( self , tup ) : <EOL> task_ranking , = tup . values <EOL> log . debug ( "<STR_LIT>" . format ( tup . task , task_ranking ) ) <EOL> self . top_N . extend ( task_ranking ) <EOL> self . top_N . sort ( key = itemgetter ( <NUM_LIT:1> ) , reverse = True ) <EOL> self . top_N = self . top_N [ : self . N ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> logging . basicConfig ( <EOL> level = logging . DEBUG , <EOL> filename = '<STR_LIT>' , <EOL> filemode = '<STR_LIT:a>' , <EOL> ) <EOL> TopGlobalBolt ( ) . run ( ) </s>
