from __future__ import print_function

import numpy as np
from .config import Config
from .trials import Trial


def execute(args, parser):
    config = Config(args.config, verbose=False)

    session = config.trials()

    items = [curr.to_dict() for curr in session.query(Trial).all()]
    if not items:
        print('No Models Found')
    else:
        c_b_m = items[np.argmax([i["mean_test_score"] for i in items])]
        parameter_dict = c_b_m["parameters"]
        print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
        print('Best Current Model = %f +- %f' % (c_b_m["mean_test_score"],
                                                 np.std(c_b_m["test_scores"])))
        print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
        print('PipelineStep\tParamter \t Value')
        for i in config.estimator().steps:
            print(i[0])
            for param in sorted(parameter_dict.keys()):
                if str(param).startswith(i[0]):
                    print("\t\t", param.split("__")[1], "\t",
                          parameter_dict[param])

    return

@@ -104,16 +104,45 @@
 t Trial%0A
+from sklearn import Pipeline%0A
 %0A%0Adef ex
@@ -737,32 +737,89 @@
 ~~~~~~~~~~~~~')%0A
+        if isinstance(config.estimator(), Pipeline):%0A    
         print('P
@@ -855,24 +855,28 @@
 e')%0A        
+ 
+   
 for i in con
@@ -906,24 +906,28 @@
             
+    
 print(i%5B0%5D)%0A
@@ -926,16 +926,20 @@
 t(i%5B0%5D)%0A
+    
         
@@ -1002,16 +1002,20 @@
         
+    
 if str(p
@@ -1038,16 +1038,20 @@
 (i%5B0%5D):%0A
+    
         
@@ -1125,24 +1125,314 @@
             
+     parameter_dict%5Bparam%5D)%0A        else:%0A            print(config.estimator())%0A            search_space = config.search_space().variables.keys()%0A            for param in sorted(parameter_dict.keys()):%0A                if param in search_space:%0A                    print(%22%5Ct%5Ct%22, param, %22%5Ct%22,
  parameter_d

modify current best