<s> import time <EOL> from graphwalker import codeloader <EOL> class StopCond ( object ) : <EOL> def start ( self , g , context = None ) : <EOL> self . context = context <EOL> self . seen = set ( ) <EOL> return self <EOL> def __nonzero__ ( self ) : <EOL> return False <EOL> def add ( self , thing ) : <EOL> self . seen . add ( thing [ <NUM_LIT:1> ] ) <EOL> return bool ( self ) <EOL> def progress ( self ) : <EOL> return '<STR_LIT>' <EOL> class Never ( StopCond ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class Seconds ( StopCond ) : <EOL> """<STR_LIT>""" <EOL> clock = time . time <EOL> def __init__ ( self , * al , ** kw ) : <EOL> self . timeout = float ( al [ <NUM_LIT:0> ] if al else kw . pop ( '<STR_LIT>' , <NUM_LIT:30> ) ) <EOL> def start ( self , g , context = None ) : <EOL> self . t0 = t = self . clock ( ) <EOL> self . t1 = t + self . timeout <EOL> return self <EOL> def __nonzero__ ( self ) : <EOL> return self . clock ( ) >= self . t1 <EOL> add = lambda * al , ** kw : None <EOL> def progress ( self ) : <EOL> return '<STR_LIT>' % ( <NUM_LIT:100> * ( self . clock ( ) - self . t0 ) / self . timeout ) <EOL> class SeenSteps ( StopCond ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * al , ** kw ) : <EOL> self . targets = set ( al ) <EOL> def __nonzero__ ( self ) : <EOL> return self . targets . issubset ( self . seen ) <EOL> def progress ( self ) : <EOL> return '<STR_LIT>' % ( len ( self . seen . intersection ( self . targets ) ) , <EOL> len ( self . targets ) ) <EOL> class CountSteps ( StopCond ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * al , ** kw ) : <EOL> self . i , self . n = <NUM_LIT:0> , int ( al [ <NUM_LIT:0> ] ) if al else kw . get ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> def __nonzero__ ( self ) : <EOL> return self . i >= self . n <EOL> def add ( self , thing ) : <EOL> self . i += <NUM_LIT:1> <EOL> return bool ( self ) <EOL> class Coverage ( StopCond ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * al , ** kw ) : <EOL> kw [ '<STR_LIT>' ] = kw . pop ( '<STR_LIT>' , kw . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . edge_cov = min ( <NUM_LIT:1.0> , float ( kw . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) / <NUM_LIT> ) <EOL> self . vert_cov = min ( <NUM_LIT:1.0> , float ( kw . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) / <NUM_LIT> ) <EOL> if self . edge_cov == <NUM_LIT:0.0> and self . vert_cov == <NUM_LIT:0.0> : <EOL> self . edge_cov = <NUM_LIT:1.0> <EOL> def start ( self , g , context = None ) : <EOL> self . g = g <EOL> self . edges_seen = set ( ) <EOL> self . edges_count = float ( len ( g . E . keys ( ) ) ) <EOL> self . verts_seen = set ( ) <EOL> self . verts_count = float ( len ( g . V . keys ( ) ) ) <EOL> return self <EOL> def __nonzero__ ( self ) : <EOL> return ( <EOL> len ( self . edges_seen ) / self . edges_count >= self . edge_cov and <EOL> len ( self . verts_seen ) / self . verts_count >= self . vert_cov ) <EOL> def progress ( self ) : <EOL> x , y = <NUM_LIT:0> , <NUM_LIT:0> <EOL> if self . edge_cov > <NUM_LIT:0> : <EOL> x , y = x + len ( self . edges_seen ) , y + self . edges_count <EOL> if self . vert_cov > <NUM_LIT:0> : <EOL> x , y = x + len ( self . verts_seen ) , y + self . verts_count <EOL> assert y > <NUM_LIT:0> <EOL> return "<STR_LIT>" % ( x , y , <NUM_LIT> * x / y ) <EOL> def add ( self , thing ) : <EOL> x_id = thing [ <NUM_LIT:0> ] <EOL> if x_id in self . g . V : <EOL> self . verts_seen . add ( x_id ) <EOL> elif x_id in self . g . E : <EOL> self . edges_seen . add ( x_id ) <EOL> return bool ( self ) <EOL> def build ( spec ) : <EOL> return codeloader . construct ( <EOL> spec , <EOL> default_module = __name__ , <EOL> call_by_default = True ) <EOL> conditions = [ cls <EOL> for cls in locals ( ) . values ( ) <EOL> if type ( cls ) is type <EOL> and issubclass ( cls , StopCond ) <EOL> and cls . __doc__ <EOL> and cls is not StopCond ] </s>
