<s> __author__ = '<STR_LIT>' <EOL> import rethinkdb as r <EOL> class Pair ( object ) : <EOL> def __init__ ( self , timestamp1 , timestamp2 , direction ) : <EOL> self . timestamp1 = timestamp1 <EOL> self . timestamp2 = timestamp2 <EOL> self . direction = direction <EOL> def makeit_dict ( obj ) : <EOL> if isinstance ( obj , set ) : <EOL> return list ( obj ) <EOL> return obj . __dict__ <EOL> class MapperUtil ( ) : <EOL> @ staticmethod <EOL> def add_pair ( timestamp1 , timestamp2 , direction ) : <EOL> conn = r . connect ( "<STR_LIT:localhost>" , <NUM_LIT> ) <EOL> r . db ( '<STR_LIT:test>' ) . table ( "<STR_LIT>" ) . insert ( [ <EOL> { "<STR_LIT>" : timestamp1 , <EOL> "<STR_LIT>" : timestamp2 , <EOL> "<STR_LIT>" : direction <EOL> } <EOL> ] ) . run ( conn ) <EOL> conn . close ( ) <EOL> @ staticmethod <EOL> def get_pair_by_direction ( direction ) : <EOL> conn = r . connect ( "<STR_LIT:localhost>" , <NUM_LIT> ) <EOL> cursor = r . db ( '<STR_LIT:test>' ) . table ( "<STR_LIT>" ) . filter ( { '<STR_LIT>' : direction } ) . run ( conn ) <EOL> r . db ( '<STR_LIT:test>' ) . table ( "<STR_LIT>" ) . filter ( { '<STR_LIT>' : direction } ) . delete ( ) . run ( conn ) <EOL> conn . close ( ) <EOL> return cursor <EOL> @ staticmethod <EOL> def get_allpairs ( ) : <EOL> conn = r . connect ( "<STR_LIT:localhost>" , <NUM_LIT> ) <EOL> cursor = r . db ( '<STR_LIT:test>' ) . table ( "<STR_LIT>" ) . run ( conn ) <EOL> conn . close ( ) <EOL> return cursor </s>
