<s> "<STR_LIT>" <EOL> import argparse <EOL> import collections as co <EOL> import matplotlib . pyplot as plt <EOL> import re <EOL> import sys <EOL> def parse_timing ( timing , limit ) : <EOL> "<STR_LIT>" <EOL> if timing . endswith ( '<STR_LIT>' ) : <EOL> value = float ( timing [ : - <NUM_LIT:2> ] ) * <NUM_LIT> <EOL> elif timing . endswith ( '<STR_LIT>' ) : <EOL> value = float ( timing [ : - <NUM_LIT:2> ] ) * <NUM_LIT> <EOL> else : <EOL> assert timing . endswith ( '<STR_LIT:s>' ) <EOL> value = float ( timing [ : - <NUM_LIT:1> ] ) <EOL> return <NUM_LIT:0.0> if value > limit else value <EOL> def parse_row ( row , line ) : <EOL> "<STR_LIT>" <EOL> return [ val . strip ( ) for val in row . match ( line ) . groups ( ) ] <EOL> def parse_data ( infile ) : <EOL> "<STR_LIT>" <EOL> blocks = re . compile ( '<STR_LIT:U+0020>' . join ( [ '<STR_LIT:=>' * <NUM_LIT:9> ] * <NUM_LIT:8> ) ) <EOL> dashes = re . compile ( '<STR_LIT>' ) <EOL> title = re . compile ( '<STR_LIT>' ) <EOL> row = re . compile ( '<STR_LIT:U+0020>' . join ( [ '<STR_LIT>' ] * <NUM_LIT:7> ) + '<STR_LIT>' ) <EOL> lines = infile . readlines ( ) <EOL> data = co . OrderedDict ( ) <EOL> index = <NUM_LIT:0> <EOL> while index < len ( lines ) : <EOL> line = lines [ index ] <EOL> if blocks . match ( line ) : <EOL> try : <EOL> name = title . match ( lines [ index + <NUM_LIT:1> ] ) . group ( <NUM_LIT:1> ) <EOL> except : <EOL> index += <NUM_LIT:1> <EOL> continue <EOL> data [ name ] = { } <EOL> assert dashes . match ( lines [ index + <NUM_LIT:2> ] ) <EOL> cols = parse_row ( row , lines [ index + <NUM_LIT:3> ] ) <EOL> assert blocks . match ( lines [ index + <NUM_LIT:4> ] ) <EOL> get_row = parse_row ( row , lines [ index + <NUM_LIT:5> ] ) <EOL> assert get_row [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> set_row = parse_row ( row , lines [ index + <NUM_LIT:6> ] ) <EOL> assert set_row [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> delete_row = parse_row ( row , lines [ index + <NUM_LIT:7> ] ) <EOL> assert delete_row [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> assert blocks . match ( lines [ index + <NUM_LIT:9> ] ) <EOL> data [ name ] [ '<STR_LIT>' ] = dict ( zip ( cols , get_row ) ) <EOL> data [ name ] [ '<STR_LIT>' ] = dict ( zip ( cols , set_row ) ) <EOL> data [ name ] [ '<STR_LIT>' ] = dict ( zip ( cols , delete_row ) ) <EOL> index += <NUM_LIT:10> <EOL> else : <EOL> index += <NUM_LIT:1> <EOL> return data <EOL> def make_plot ( data , action , save = False , show = False , limit = <NUM_LIT> ) : <EOL> "<STR_LIT>" <EOL> fig , ax = plt . subplots ( figsize = ( <NUM_LIT:8> , <NUM_LIT:10> ) ) <EOL> colors = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> width = <NUM_LIT> <EOL> ticks = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> index = ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> names = list ( data ) <EOL> bars = [ ] <EOL> for pos , ( name , color ) in enumerate ( zip ( names , colors ) ) : <EOL> bars . append ( ax . bar ( <EOL> [ val + pos * width for val in index ] , <EOL> [ parse_timing ( data [ name ] [ action ] [ tick ] , limit ) for tick in ticks ] , <EOL> width , <EOL> color = color , <EOL> ) ) <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> ax . set_title ( '<STR_LIT>' % action ) <EOL> ax . set_xticks ( [ val + width * ( len ( data ) / <NUM_LIT:2> ) for val in index ] ) <EOL> ax . set_xticklabels ( ticks ) <EOL> box = ax . get_position ( ) <EOL> ax . set_position ( [ box . x0 , box . y0 + box . height * <NUM_LIT> , box . width , box . height * <NUM_LIT> ] ) <EOL> ax . legend ( <EOL> [ bar [ <NUM_LIT:0> ] for bar in bars ] , <EOL> names , <EOL> loc = '<STR_LIT>' , <EOL> bbox_to_anchor = ( <NUM_LIT:0.5> , - <NUM_LIT> ) <EOL> ) <EOL> if show : <EOL> plt . show ( ) <EOL> if save : <EOL> plt . savefig ( '<STR_LIT>' % ( save , action ) , dpi = <NUM_LIT> , bbox_inches = '<STR_LIT>' ) <EOL> plt . close ( ) <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> type = argparse . FileType ( '<STR_LIT:r>' ) , <EOL> default = sys . stdin , <EOL> ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = float , default = <NUM_LIT> ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' ) <EOL> args = parser . parse_args ( ) <EOL> data = parse_data ( args . infile ) <EOL> for action in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> make_plot ( data , action , args . save , args . show , args . limit ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
