<s> import time <EOL> import json <EOL> import os <EOL> import nose . tools <EOL> from datetime import datetime , timedelta <EOL> from world import world <EOL> from bigml . api import HTTP_OK <EOL> from bigml . api import HTTP_CREATED <EOL> from bigml . api import HTTP_ACCEPTED <EOL> from bigml . api import FINISHED <EOL> from bigml . api import FAULTY <EOL> from bigml . api import get_status <EOL> import read_model_steps as read <EOL> NO_MISSING_SPLITS = { '<STR_LIT>' : False } <EOL> def i_create_a_model ( step ) : <EOL> dataset = world . dataset . get ( '<STR_LIT>' ) <EOL> resource = world . api . create_model ( dataset , args = NO_MISSING_SPLITS ) <EOL> world . status = resource [ '<STR_LIT:code>' ] <EOL> assert world . status == HTTP_CREATED <EOL> world . location = resource [ '<STR_LIT:location>' ] <EOL> world . model = resource [ '<STR_LIT:object>' ] <EOL> world . models . append ( resource [ '<STR_LIT>' ] ) <EOL> def i_create_a_model_from_dataset_list ( step ) : <EOL> resource = world . api . create_model ( world . dataset_ids , <EOL> args = NO_MISSING_SPLITS ) <EOL> world . status = resource [ '<STR_LIT:code>' ] <EOL> assert world . status == HTTP_CREATED <EOL> world . location = resource [ '<STR_LIT:location>' ] <EOL> world . model = resource [ '<STR_LIT:object>' ] <EOL> world . models . append ( resource [ '<STR_LIT>' ] ) <EOL> def wait_until_model_status_code_is ( step , code1 , code2 , secs ) : <EOL> start = datetime . utcnow ( ) <EOL> read . i_get_the_model ( step , world . model [ '<STR_LIT>' ] ) <EOL> status = get_status ( world . model ) <EOL> while ( status [ '<STR_LIT:code>' ] != int ( code1 ) and <EOL> status [ '<STR_LIT:code>' ] != int ( code2 ) ) : <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> assert datetime . utcnow ( ) - start < timedelta ( seconds = int ( secs ) ) <EOL> read . i_get_the_model ( step , world . model [ '<STR_LIT>' ] ) <EOL> status = get_status ( world . model ) <EOL> assert status [ '<STR_LIT:code>' ] == int ( code1 ) <EOL> def the_model_is_finished_in_less_than ( step , secs ) : <EOL> wait_until_model_status_code_is ( step , FINISHED , FAULTY , secs ) <EOL> def i_create_a_model_with ( step , data = "<STR_LIT:{}>" ) : <EOL> args = json . loads ( data ) <EOL> if not '<STR_LIT>' in args : <EOL> args . update ( NO_MISSING_SPLITS ) <EOL> resource = world . api . create_model ( world . dataset . get ( '<STR_LIT>' ) , <EOL> args = args ) <EOL> world . status = resource [ '<STR_LIT:code>' ] <EOL> assert world . status == HTTP_CREATED <EOL> world . location = resource [ '<STR_LIT:location>' ] <EOL> world . model = resource [ '<STR_LIT:object>' ] <EOL> world . models . append ( resource [ '<STR_LIT>' ] ) <EOL> def i_create_a_model_with_missing_splits ( step ) : <EOL> i_create_a_model_with ( step , data = '<STR_LIT>' ) <EOL> def make_the_model_public ( step ) : <EOL> resource = world . api . update_model ( world . model [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : False , '<STR_LIT>' : True } ) <EOL> world . status = resource [ '<STR_LIT:code>' ] <EOL> if world . status != HTTP_ACCEPTED : <EOL> print "<STR_LIT>" % world . status <EOL> assert world . status == HTTP_ACCEPTED <EOL> world . location = resource [ '<STR_LIT:location>' ] <EOL> world . model = resource [ '<STR_LIT:object>' ] <EOL> def model_from_public_url ( step ) : <EOL> world . model = world . api . get_model ( "<STR_LIT>" % world . model [ '<STR_LIT>' ] ) <EOL> assert get_status ( world . model ) [ '<STR_LIT:code>' ] == FINISHED <EOL> def make_the_model_shared ( step ) : <EOL> resource = world . api . update_model ( world . model [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : True } ) <EOL> world . status = resource [ '<STR_LIT:code>' ] <EOL> assert world . status == HTTP_ACCEPTED <EOL> world . location = resource [ '<STR_LIT:location>' ] <EOL> world . model = resource [ '<STR_LIT:object>' ] <EOL> def get_sharing_info ( step ) : <EOL> world . shared_hash = world . model [ '<STR_LIT>' ] <EOL> world . sharing_key = world . model [ '<STR_LIT>' ] <EOL> def model_from_shared_url ( step ) : <EOL> world . model = world . api . get_model ( "<STR_LIT>" % world . shared_hash ) <EOL> assert get_status ( world . model ) [ '<STR_LIT:code>' ] == FINISHED <EOL> def model_from_shared_key ( step ) : <EOL> username = os . environ . get ( "<STR_LIT>" ) <EOL> world . model = world . api . get_model ( world . model [ '<STR_LIT>' ] , <EOL> shared_username = username , shared_api_key = world . sharing_key ) <EOL> assert get_status ( world . model ) [ '<STR_LIT:code>' ] == FINISHED <EOL> def field_name_to_new_name ( step , field_id , new_name ) : <EOL> nose . tools . assert_equals ( <EOL> world . local_model . tree . fields [ field_id ] [ '<STR_LIT:name>' ] , new_name ) <EOL> def i_create_a_model_from_cluster ( step , centroid_id ) : <EOL> resource = world . api . create_model ( <EOL> world . cluster [ '<STR_LIT>' ] , <EOL> args = { '<STR_LIT>' : centroid_id } ) <EOL> world . status = resource [ '<STR_LIT:code>' ] <EOL> assert world . status == HTTP_CREATED <EOL> world . location = resource [ '<STR_LIT:location>' ] <EOL> world . model = resource [ '<STR_LIT:object>' ] <EOL> world . models . append ( resource [ '<STR_LIT>' ] ) <EOL> def is_associated_to_centroid_id ( step , centroid_id ) : <EOL> cluster = world . api . get_cluster ( world . cluster [ '<STR_LIT>' ] ) <EOL> world . status = cluster [ '<STR_LIT:code>' ] <EOL> assert world . status == HTTP_OK <EOL> assert "<STR_LIT>" % ( <EOL> cluster [ '<STR_LIT:object>' ] [ '<STR_LIT>' ] [ <EOL> centroid_id ] ) == world . model [ '<STR_LIT>' ] <EOL> def i_create_a_logistic_model ( step ) : <EOL> dataset = world . dataset . get ( '<STR_LIT>' ) <EOL> resource = world . api . create_logistic_regression ( dataset ) <EOL> world . status = resource [ '<STR_LIT:code>' ] <EOL> assert world . status == HTTP_CREATED <EOL> world . location = resource [ '<STR_LIT:location>' ] <EOL> world . logistic_regression = resource [ '<STR_LIT:object>' ] <EOL> world . logistic_regressions . append ( resource [ '<STR_LIT>' ] ) <EOL> def i_create_a_logistic_model_with_objective ( step , objective ) : <EOL> dataset = world . dataset . get ( '<STR_LIT>' ) <EOL> resource = world . api . create_logistic_regression ( dataset , { "<STR_LIT>" : objective } ) <EOL> world . status = resource [ '<STR_LIT:code>' ] <EOL> assert world . status == HTTP_CREATED <EOL> world . location = resource [ '<STR_LIT:location>' ] <EOL> world . logistic_regression = resource [ '<STR_LIT:object>' ] <EOL> world . logistic_regressions . append ( resource [ '<STR_LIT>' ] ) <EOL> def wait_until_logistic_model_status_code_is ( step , code1 , code2 , secs ) : <EOL> start = datetime . utcnow ( ) <EOL> read . i_get_the_logistic_model ( step , world . logistic_regression [ '<STR_LIT>' ] ) <EOL> status = get_status ( world . logistic_regression ) <EOL> while ( status [ '<STR_LIT:code>' ] != int ( code1 ) and <EOL> status [ '<STR_LIT:code>' ] != int ( code2 ) ) : <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> assert datetime . utcnow ( ) - start < timedelta ( seconds = int ( secs ) ) <EOL> read . i_get_the_logistic_model ( step , world . logistic_regression [ '<STR_LIT>' ] ) <EOL> status = get_status ( world . logistic_regression ) <EOL> assert status [ '<STR_LIT:code>' ] == int ( code1 ) <EOL> def the_logistic_model_is_finished_in_less_than ( step , secs ) : <EOL> wait_until_logistic_model_status_code_is ( step , FINISHED , FAULTY , secs ) </s>
