<s> """<STR_LIT>""" <EOL> import json <EOL> from pyproct . clustering . cluster import Cluster <EOL> from pyproct . clustering . clustering import Clustering <EOL> from functools import cmp_to_key <EOL> class SerializerRegistry ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _classes = { } <EOL> def add ( self , cls ) : <EOL> self . _classes [ cls . __module__ , cls . __name__ ] = cls <EOL> return cls <EOL> def object_hook ( self , dct ) : <EOL> module , cls_name = dct . pop ( '<STR_LIT>' , ( None , None ) ) <EOL> if cls_name is not None : <EOL> return self . _classes [ module , cls_name ] . from_dic ( dct ) <EOL> else : <EOL> return dct <EOL> def default ( self , obj ) : <EOL> return obj . to_dic ( ) <EOL> def sort_clustering_results ( c_results ) : <EOL> def compare_func ( a , b ) : <EOL> if a [ <NUM_LIT:1> ] [ "<STR_LIT:type>" ] == b [ <NUM_LIT:1> ] [ "<STR_LIT:type>" ] : <EOL> if "<STR_LIT:k>" in a [ <NUM_LIT:1> ] [ "<STR_LIT>" ] : <EOL> return a [ <NUM_LIT:1> ] [ "<STR_LIT>" ] [ "<STR_LIT:k>" ] - b [ <NUM_LIT:1> ] [ "<STR_LIT>" ] [ "<STR_LIT:k>" ] <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return cmp ( a [ <NUM_LIT:1> ] [ "<STR_LIT:type>" ] , b [ <NUM_LIT:1> ] [ "<STR_LIT:type>" ] ) <EOL> return sorted ( [ ( cid , c_results [ cid ] ) for cid in c_results ] , key = cmp_to_key ( compare_func ) ) <EOL> class ClusteringResultsGatherer ( object ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> def gather ( self , timer_handler , data_handler , workspace_handler , clustering_results , files ) : <EOL> results = { } <EOL> results [ "<STR_LIT>" ] = timer_handler . get_elapsed ( ) <EOL> results [ "<STR_LIT>" ] = [ s . source for s in data_handler . sources ] <EOL> if ( clustering_results is not None ) : <EOL> results [ "<STR_LIT>" ] = clustering_results [ <NUM_LIT:0> ] <EOL> results [ "<STR_LIT>" ] = dict ( sort_clustering_results ( clustering_results [ <NUM_LIT:1> ] ) ) <EOL> results [ "<STR_LIT>" ] = dict ( sort_clustering_results ( clustering_results [ <NUM_LIT:2> ] ) ) <EOL> results [ "<STR_LIT>" ] = clustering_results [ <NUM_LIT:3> ] <EOL> results [ "<STR_LIT>" ] = files <EOL> results [ "<STR_LIT>" ] = workspace_handler . data <EOL> serializer = SerializerRegistry ( ) <EOL> serializer . add ( Clustering ) <EOL> serializer . add ( Cluster ) <EOL> return json . dumps ( results , <EOL> sort_keys = False , <EOL> indent = <NUM_LIT:4> , <EOL> separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) , <EOL> default = serializer . default ) </s>
