<s> import decorators <EOL> import datetime <EOL> def stdout ( counter , elapsed_time , argv , logger = None ) : <EOL> prepared_lines = prepare ( counter , argv , elapsed_time , logger ) <EOL> output = '<STR_LIT:\n>' . join ( prepared_lines ) <EOL> print ( output ) <EOL> def csv ( counter , argv , logger = None ) : <EOL> sum_lines = sum ( counter . values ( ) ) <EOL> sorted_counter = sorter ( counter , argv ) <EOL> for author , contributions in sorted_counter : <EOL> relative = float ( contributions ) / float ( sum_lines ) <EOL> print ( '<STR_LIT>' . format ( relative , contributions , author ) ) <EOL> @ decorators . null_logger <EOL> def prepare ( counter , argv , elapsed_time = None , logger = None ) : <EOL> blue = '<STR_LIT>' <EOL> grey = '<STR_LIT>' <EOL> endcolor = '<STR_LIT>' <EOL> italic = '<STR_LIT>' <EOL> eitalic = '<STR_LIT>' <EOL> template = '<STR_LIT>' <EOL> if argv . show_absolute > <NUM_LIT:0> : <EOL> template = '<STR_LIT>' <EOL> sum_lines = sum ( counter . values ( ) ) <EOL> prepared_lines = [ ] <EOL> for author , contributions in sorter ( counter , argv ) : <EOL> relative = float ( contributions ) / float ( sum_lines ) <EOL> output = template . format ( relative , contributions , author , blue , <EOL> endcolor , italic , eitalic ) <EOL> prepared_lines . append ( output ) <EOL> top_n = check_top_n ( counter , argv ) <EOL> n_contributors = '<STR_LIT>' . format ( top_n , len ( counter ) ) <EOL> elapsed = '<STR_LIT>' . format ( datetime . timedelta ( seconds = elapsed_time ) ) <EOL> logger . info ( n_contributors ) <EOL> logger . info ( elapsed ) <EOL> prepared_lines . append ( '<STR_LIT>' . format ( n_contributors , elapsed ) ) <EOL> return prepared_lines <EOL> def sorter ( counter , argv ) : <EOL> top_n = check_top_n ( counter , argv ) <EOL> sorted_counter = counter . most_common ( top_n ) <EOL> if argv . alphabetically : <EOL> sorted_counter = sorted ( sorted_counter , key = lambda s : s [ <NUM_LIT:0> ] . lower ( ) ) <EOL> if argv . reverse : <EOL> sorted_counter = reversed ( sorted_counter ) <EOL> return sorted_counter <EOL> def check_top_n ( counter , argv ) : <EOL> top_n = argv . top_n <EOL> if top_n < <NUM_LIT:0> or top_n > len ( counter ) : <EOL> top_n = len ( counter ) <EOL> return top_n </s>
