import time
import requests
import json
#
import numpy
#
import Engine as E


# settings
URI = 'http://localhost:8007'
id = 0


# helper functions
def create_message(method_name, params):
    global id
    id += 1
    message = {
        'jsonrpc': '2.0',
        'method': method_name,
        'params': params,
        'id': str(id),
        }
    return json.dumps(message)

def call_and_print(method_name, args_dict):
    message = create_message(method_name, args_dict)
    print 'trying message:', message
    r = requests.put(URI, data=message)
    r.raise_for_status()
    print json.loads(r.content)
    print

# non-stub functions
non_stub = set(['initialize', 'initialize_and_analyze'])
#
method_name = 'initialize'
args_dict = dict()
args_dict['M_c'] = 'M_c'
args_dict['M_r'] = 'M_r'
args_dict['i'] = ''
T_dim = (3, 4)
T = (numpy.arange(numpy.prod(T_dim)).reshape(T_dim) * 1.0).tolist()
args_dict['T'] = T
call_and_print(method_name, args_dict)
time.sleep(1)
#
method_name = 'initialize_and_analyze'
args_dict = dict()
args_dict['n_steps'] = 10
args_dict['SEED'] = 0
T_dim = (3, 4)
T = (numpy.arange(numpy.prod(T_dim)).reshape(T_dim) * 1.0).tolist()
args_dict['T'] = T
call_and_print(method_name, args_dict)
time.sleep(1)

# programmatically call all the other method calls
method_name_to_args = E.get_method_name_to_args()
for method_name, arg_str_list in method_name_to_args.iteritems():
    if method_name in non_stub:
        print 'skipping non-stub method:', method_name
        print
        continue
    args_dict = dict(zip(arg_str_list, arg_str_list))
    call_and_print(method_name, args_dict)
    time.sleep(1)

@@ -574,21 +574,21 @@
 s()%0A    
-print
+out =
  json.lo
@@ -611,16 +611,239 @@
    print
+ out%0A    print%0A    if isinstance(out, dict) and 'result' in out:%0A        return out%5B'result'%5D%0A    else:%0A        # error?%0A        return out%0A%0AT_dim = (3, 4)%0AT = (numpy.arange(numpy.prod(T_dim)).reshape(T_dim) * 1.0).tolist()
 %0A%0A# non-
@@ -911,16 +911,27 @@
 analyze'
+, 'analyze'
 %5D)%0A#%0Amet
@@ -1047,90 +1047,193 @@
  ''%0A
-T_dim = (3, 4)%0AT = (numpy.arange(numpy.prod(T_dim)).reshape(T_dim) * 1.0).tolist()
+args_dict%5B'T'%5D = T%0Aout = call_and_print(method_name, args_dict)%0Atime.sleep(1)%0A#%0Amethod_name = 'initialize_and_analyze'%0Aargs_dict = dict()%0Aargs_dict%5B'n_steps'%5D = 10%0Aargs_dict%5B'SEED'%5D = 0
 %0Aarg
@@ -1240,32 +1240,38 @@
 s_dict%5B'T'%5D = T%0A
+out = 
 call_and_print(m
@@ -1299,33 +1299,60 @@
 )%0Atime.sleep(1)%0A
-#
+%0A%0AX_L_prime, X_D_prime = out
 %0Amethod_name = '
@@ -1347,39 +1347,24 @@
 hod_name = '
-initialize_and_
 analyze'%0Aarg
@@ -1386,38 +1386,56 @@
 %0Aargs_dict%5B'
-n_steps
+M_c'%5D = 'M_c'%0Aargs_dict%5B'T
 '%5D = 
-10
+T
 %0Aargs_dict%5B'
@@ -1438,121 +1438,251 @@
 ct%5B'
-SEED
+X_L
 '%5D = 
-0%0AT_dim = (3, 4)%0AT = (numpy.arange(numpy.prod(T_dim)).reshape(T_dim) * 1.0).tolist()%0Aargs_dict%5B'T'%5D = T%0A
+X_L_prime%0Aargs_dict%5B'X_D'%5D = X_D_prime%0Aargs_dict%5B'kernel_list'%5D = 'kernel_list'%0Aargs_dict%5B'n_steps'%5D = 2%0Aargs_dict%5B'c'%5D = 'c'%0Aargs_dict%5B'r'%5D = 'r'%0Aargs_dict%5B'max_iterations'%5D = 'max_iterations'%0Aargs_dict%5B'max_time'%5D = 'max_time'%0Aout = 
 call

call analyze