<s> import sys <EOL> infile = open ( sys . argv [ <NUM_LIT:1> ] ) <EOL> curr = None <EOL> slots = [ ] <EOL> for line in infile : <EOL> if line == '<STR_LIT>' : <EOL> if curr : <EOL> break <EOL> curr = <NUM_LIT:1> <EOL> else : <EOL> attr , val = [ s . strip ( ) for s in line . split ( '<STR_LIT::>' ) ] <EOL> slots . append ( attr ) <EOL> class DictInfo ( object ) : <EOL> __slots__ = slots <EOL> infile = open ( sys . argv [ <NUM_LIT:1> ] ) <EOL> infos = [ ] <EOL> for line in infile : <EOL> if line == '<STR_LIT>' : <EOL> curr = object . __new__ ( DictInfo ) <EOL> infos . append ( curr ) <EOL> else : <EOL> attr , val = [ s . strip ( ) for s in line . split ( '<STR_LIT::>' ) ] <EOL> if '<STR_LIT:.>' in val : <EOL> val = float ( val ) <EOL> else : <EOL> val = int ( val ) <EOL> setattr ( curr , attr , val ) <EOL> def histogram ( infos , keyattr , * attrs ) : <EOL> r = { } <EOL> for info in infos : <EOL> v = getattr ( info , keyattr ) <EOL> l = r . setdefault ( v , [ <NUM_LIT:0> , { } ] ) <EOL> l [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> for a in attrs : <EOL> d2 = l [ <NUM_LIT:1> ] . setdefault ( a , { } ) <EOL> v2 = getattr ( info , a ) <EOL> d2 [ v2 ] = d2 . get ( v2 , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> return sorted ( r . items ( ) ) <EOL> def reportDictInfos ( ) : <EOL> d = { } <EOL> stillAlive = <NUM_LIT:0> <EOL> totLifetime = <NUM_LIT:0.0> <EOL> for info in infos : <EOL> for attr in slots : <EOL> if attr == '<STR_LIT>' : <EOL> continue <EOL> v = getattr ( info , attr ) <EOL> if not isinstance ( v , int ) : <EOL> continue <EOL> d [ attr ] = d . get ( attr , <NUM_LIT:0> ) + v <EOL> if info . lifetime != - <NUM_LIT:1.0> : <EOL> totLifetime += info . lifetime <EOL> else : <EOL> stillAlive += <NUM_LIT:1> <EOL> print '<STR_LIT>' , len ( infos ) , '<STR_LIT>' <EOL> if stillAlive != len ( infos ) : <EOL> print '<STR_LIT>' , totLifetime / ( len ( infos ) - stillAlive ) , <EOL> print '<STR_LIT:(>' + str ( stillAlive ) , '<STR_LIT>' <EOL> print d <EOL> def Rify ( fname , * attributes ) : <EOL> output = open ( fname , '<STR_LIT:w>' ) <EOL> for attr in attributes : <EOL> print >> output , attr , <EOL> print >> output <EOL> for info in infos : <EOL> for attr in attributes : <EOL> print >> output , getattr ( info , attr ) , <EOL> print >> output <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import __builtin__ <EOL> def displayhook ( v ) : <EOL> if v is not None : <EOL> __builtin__ . _ = v <EOL> pprint . pprint ( v ) <EOL> sys . displayhook = displayhook <EOL> import pprint <EOL> try : <EOL> import readline <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> import rlcompleter <EOL> readline . parse_and_bind ( '<STR_LIT>' ) <EOL> if len ( sys . argv ) > <NUM_LIT:2> : <EOL> attrs = sys . argv [ <NUM_LIT:2> ] . split ( '<STR_LIT:U+002C>' ) <EOL> if attrs == [ '<STR_LIT:all>' ] : <EOL> attrs = slots <EOL> Rify ( "<STR_LIT>" , * attrs ) </s>
