<s> from collections import defaultdict , Counter <EOL> import json <EOL> import sys <EOL> BUCKET_WIDTH = <NUM_LIT:50> if len ( sys . argv ) == <NUM_LIT:1> else int ( sys . argv [ <NUM_LIT:1> ] ) <EOL> def action_factor ( e ) : <EOL> return { <NUM_LIT:0> : "<STR_LIT>" , <NUM_LIT:1> : "<STR_LIT:left>" , <NUM_LIT:2> : "<STR_LIT:right>" , <NUM_LIT:3> : "<STR_LIT>" } [ e [ '<STR_LIT:action>' ] ] <EOL> counts = defaultdict ( Counter ) <EOL> for n , episode_json in enumerate ( sys . stdin ) : <EOL> for event in json . loads ( episode_json ) : <EOL> bucket = ( ( n / BUCKET_WIDTH ) + <NUM_LIT:1> ) * BUCKET_WIDTH <EOL> counts [ bucket ] [ action_factor ( event ) ] += <NUM_LIT:1> <EOL> print "<STR_LIT:\t>" . join ( [ '<STR_LIT>' , '<STR_LIT:action>' , '<STR_LIT>' ] ) <EOL> for bucket , action_freqs in counts . iteritems ( ) : <EOL> for action , freq in action_freqs . iteritems ( ) : <EOL> print "<STR_LIT:\t>" . join ( map ( str , [ bucket , action , freq ] ) ) </s>
