<s> """<STR_LIT>""" <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> from bigml . resourcehandler import ResourceHandler <EOL> from bigml . resourcehandler import ( check_resource_type , get_resource_type , <EOL> check_resource , <EOL> get_anomaly_score_id , get_anomaly_id ) <EOL> from bigml . constants import ( ANOMALY_SCORE_PATH , ANOMALY_PATH , <EOL> TINY_RESOURCE ) <EOL> class AnomalyScoreHandler ( ResourceHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . anomaly_score_url = self . url + ANOMALY_SCORE_PATH <EOL> def create_anomaly_score ( self , anomaly , input_data = None , <EOL> args = None , wait_time = <NUM_LIT:3> , retries = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> anomaly_id = None <EOL> resource_type = get_resource_type ( anomaly ) <EOL> if resource_type == ANOMALY_PATH : <EOL> anomaly_id = get_anomaly_id ( anomaly ) <EOL> check_resource ( anomaly_id , <EOL> query_string = TINY_RESOURCE , <EOL> wait_time = wait_time , retries = retries , <EOL> raise_on_error = True , api = self ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % resource_type ) <EOL> if input_data is None : <EOL> input_data = { } <EOL> create_args = { } <EOL> if args is not None : <EOL> create_args . update ( args ) <EOL> create_args . update ( { <EOL> "<STR_LIT>" : input_data } ) <EOL> create_args . update ( { <EOL> "<STR_LIT>" : anomaly_id } ) <EOL> body = json . dumps ( create_args ) <EOL> return self . _create ( self . anomaly_score_url , body , <EOL> verify = self . verify ) <EOL> def get_anomaly_score ( self , anomaly_score ) : <EOL> """<STR_LIT>""" <EOL> check_resource_type ( anomaly_score , ANOMALY_SCORE_PATH , <EOL> message = "<STR_LIT>" ) <EOL> anomaly_score_id = get_anomaly_score_id ( anomaly_score ) <EOL> if anomaly_score_id : <EOL> return self . _get ( "<STR_LIT>" % ( self . url , anomaly_score_id ) ) <EOL> def list_anomaly_scores ( self , query_string = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> return self . _list ( self . anomaly_score_url , query_string ) <EOL> def update_anomaly_score ( self , anomaly_score , changes ) : <EOL> """<STR_LIT>""" <EOL> check_resource_type ( anomaly_score , ANOMALY_SCORE_PATH , <EOL> message = "<STR_LIT>" ) <EOL> anomaly_score_id = get_anomaly_score_id ( anomaly_score ) <EOL> if anomaly_score_id : <EOL> body = json . dumps ( changes ) <EOL> return self . _update ( "<STR_LIT>" % ( self . url , anomaly_score_id ) , body ) <EOL> def delete_anomaly_score ( self , anomaly_score ) : <EOL> """<STR_LIT>""" <EOL> check_resource_type ( anomaly_score , ANOMALY_SCORE_PATH , <EOL> message = "<STR_LIT>" ) <EOL> anomaly_score_id = get_anomaly_score_id ( anomaly_score ) <EOL> if anomaly_score_id : <EOL> return self . _delete ( "<STR_LIT>" % ( self . url , anomaly_score_id ) ) </s>
