from utils import *
import requests
import json


payload=x= """
{"wf_unique_id": "4", "wf_body": {"nodes": [ { "task_name": "SelectDataset", "task_id": "flowchartNode1", "position": "left: 600px; top: 114px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [], "parameters": [{"name": "name", "type": "str", "display_name": "Dataset Name", "lookup": [{"title": "Bank Campaign Dataset",  "uuid": "ff6e6b81fe0448948656677872dd705d.csv"}], "value": "test_data/bank.csv"}, {"name": "delimiter", "type": "str", "display_name": "Dataset Name", "value": ","}]}, { "task_name": "SelectColumns", "task_id": "flowchartNode2", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode1", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "age,job,marital,education,default,balance,housing,loan,contact,day,month,duration,campaign,pdays,previous,poutcome,y"}]}, { "task_name":"FillMissingWithMean", "task_id": "flowchartNode3", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode2", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "balance,age"}]}, { "task_name":"CategoryEncoding", "task_id": "flowchartNode4", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode3", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "job,marital,education,default,housing,loan,contact,month,poutcome"}] }, { "task_name": "SplitData", "task_id": "flowchartNode5", "position": "left: 460px; top: 460px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode4", "id": "BottomCenter"}]}], "parameters": [{"name": "perc", "type": "float", "display_name": "Partition Percentage", "value": 0.7}]}, { "task_name": "RandomForestClassifier", "task_id": "flowchartNode6", "position": "left: 150px; top: 366px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [], "parameters": [ {"name": "n_estimators", "type": "integer", "display_name": "Number of Estimators", "value": 100}]}, { "task_name": "FitModel", "task_id": "flowchartNode7", "position": "left: 150px; top: 366px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopLeft", "targets": [{"nodeId": "flowchartNode6", "id": "BottomCenter"}]},  {"id": "TopRight", "targets": [{"nodeId": "flowchartNode5", "id": "BottomLeft"}]}], "parameters": [ {"name": "label_column", "type": "string", "display_name": "Number of Estimators", "value": "y"}]}, { "task_name": "RunModel", "task_id": "flowchartNode8", "position": "left: 680px; top: 567px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopLeft", "targets": [{"nodeId": "flowchartNode7", "id": "BottomCenter"}]},  {"id": "TopRight", "targets": [{"nodeId": "flowchartNode5", "id": "BottomRight"}]}], "parameters": [{"name": "label_column", "type": "string", "display_name": "Number of Estimators", "value": "y"}]}, { "task_name": "ClassificationMetrics", "task_id": "flowchartNode9", "position": "left: 680px; top: 567px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode8", "id": "BottomCenter"}]}], "parameters": [{"name": "label_column", "type": "string", "display_name": "target column", "value": "y"},{"name": "predict_column",  "type": "string",  "display_name": "predicted column",  "value": "predictions"}]}]}, "run_to_task_id": "", "execution_mode": "light", "storage": false, "deploy": "flowchartNode7", "node_name": "flowchartNode1", "output_port_id": "1", "col_1": "day", "num_bins": 10, "col_2": "previous", "col_names": "day,previous", "plot_type": "matrix", "model_name": "b03ffdaa422e450788cec3e80b308a3d", "observation": [ { "age": 36, "balance": 260, "campaign": 1, "contact": "cellular", "day": 7, "default": "no", "duration": 49, "education": "tertiary", "housing": "yes", "job": "management", "loan": "no", "marital": "single", "month": "may", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 40, "balance": 11084, "campaign": 1, "contact": "unknown", "day": 11, "default": "no", "duration": 113, "education": "secondary", "housing": "no", "job": "blue-collar", "loan": "no", "marital": "married", "month": "jun", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 52, "balance": 20, "campaign": 1, "contact": "telephone", "day": 28, "default": "no", "duration": 172, "education": "primary", "housing": "yes", "job": "unemployed", "loan": "no", "marital": "married", "month": "jan", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 30, "balance": 102, "campaign": 7, "contact": "cellular", "day": 5, "default": "no", "duration": 470, "education": "tertiary", "housing": "yes", "job": "management", "loan": "no", "marital": "married", "month": "apr", "pdays": 426, "poutcome": "other", "previous": 3 }, { "age": 42, "balance": 292, "campaign": 3, "contact": "cellular", "day": 11, "default": "no", "duration": 222, "education": "secondary", "housing": "yes", "job": "services", "loan": "no", "marital": "married", "month": "may", "pdays": -1, "poutcome": "unknown", "previous": 0 }]}
"""

def ml_get_nodes(data):
    u = url("ml/nodes/list")
    r = data['session'].get(u)
    assert_ret_code(r, 200)
    #print("Nodes: " + r.content.decode())
    print("Nodes ok")

def ml_start_workflow(data):

    u = url("ml/workflow/execute")
    j = """{"wf_unique_id": "4", "wf_body": {"nodes": [ { "task_name": "SelectDataset", "task_id": "flowchartNode1", "position": "left: 600px; top: 114px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [], "parameters": [{"name": "name", "type": "str", "display_name": "Dataset Name", "lookup": [{"title": "Bank Campaign Dataset", "uuid": "ff6e6b81fe0448948656677872dd705d.csv"}], "value": "test_data/bank.csv"}, {"name": "delimiter", "type": "str", "display_name": "Dataset Name", "value": ","}]}, { "task_name": "SelectColumns", "task_id": "flowchartNode2", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode1", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "age,job,marital,education,default,balance,housing,loan,contact,day,month,duration,campaign,pdays,previous,poutcome,y"}]}, { "task_name":"FillMissingWithMean", "task_id": "flowchartNode3", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode2", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "balance,age"}]}, { "task_name":"CategoryEncoding", "task_id": "flowchartNode4", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode3", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "job,marital,education,default,housing,loan,contact,month,poutcome"}] }, { "task_name": "SplitData", "task_id": "flowchartNode5", "position": "left: 460px; top: 460px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode4", "id": "BottomCenter"}]}], "parameters": [{"name": "perc", "type": "float", "display_name": "Partition Percentage", "value": 0.7}]},
    { "task_name": "RandomForestClassifier", "task_id": "flowchartNode6", "position": "left: 150px; top: 366px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [], "parameters": [ {"name": "n_estimators", "type": "integer", "display_name": "Number of Estimators", "value": 100}]}, { "task_name": "FitModel", "task_id": "flowchartNode7", "position": "left: 150px; top: 366px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopLeft", "targets": [{"nodeId": "flowchartNode6", "id": "BottomCenter"}]}, {"id": "TopRight", "targets": [{"nodeId": "flowchartNode5", "id": "BottomLeft"}]}], "parameters": [ {"name": "label_column", "type": "string", "display_name": "Number of Estimators", "value": "y"}]}, { "task_name": "RunModel", "task_id": "flowchartNode8", "position": "left: 680px; top: 567px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopLeft", "targets":
    [{"nodeId": "flowchartNode7", "id": "BottomCenter"}]}, {"id": "TopRight", "targets": [{"nodeId": "flowchartNode5", "id": "BottomRight"}]}], "parameters": [{"name": "label_column", "type": "string", "display_name": "Number of Estimators", "value": "y"}]}, { "task_name": "ClassificationMetrics", "task_id": "flowchartNode9", "position": "left: 680px; top: 567px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode8", "id": "BottomCenter"}]}], "parameters": [{"name": "label_column", "type": "string", "display_name": "target column", "value": "y"},{"name": "predict_column", "type": "string", "display_name": "predicted column", "value": "predictions"}]}]}, "run_to_task_id": "", "execution_mode": "light", "storage": false, "deploy": "flowchartNode7", "node_name": "flowchartNode1", "output_port_id": "1", "col_1": "day", "num_bins": 10, "col_2": "previous", "col_names": "day,previous", "plot_type": "matrix", "model_name": "b03ffdaa422e450788cec3e80b308a3d", "observation": [ { "age": 36, "balance": 260, "campaign": 1, "contact": "cellular", "day": 7, "default": "no", "duration": 49, "education": "tertiary", "housing": "yes", "job": "management", "loan": "no", "marital": "single", "month": "may", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 40, "balance": 11084, "campaign": 1, "contact": "unknown", "day": 11, "default": "no", "duration": 113, "education": "secondary", "housing": "no", "job": "blue-collar", "loan": "no", "marital": "married", "month": "jun", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 52, "balance": 20, "campaign": 1, "contact": "telephone", "day": 28, "default": "no", "duration": 172, "education": "primary", "housing": "yes", "job": "unemployed", "loan": "no", "marital": "married", "month": "jan", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 30, "balance": 102, "campaign": 7, "contact": "cellular", "day": 5, "default": "no", "duration": 470, "education": "tertiary", "housing": "yes", "job": "management", "loan": "no", "marital": "married", "month": "apr", "pdays": 426, "poutcome": "other", "previous": 3 }, { "age": 42, "balance": 292, "campaign": 3, "contact": "cellular", "day": 11, "default": "no", "duration": 222, "education": "secondary", "housing": "yes", "job": "services", "loan": "no", "marital": "married", "month": "may", "pdays": -1, "poutcome": "unknown", "previous": 0 }]}"""

    r = data['session'].post(u, data=j)
    assert_ret_code(r, 200)


def ml_get_status(data):
    u = url("ml/workflow/progress/4")
    r = data['session'].get(u)
    assert_ret_code(r, 200)


def ml_get_node_output(data):
    u = url("ml/node/output")
    j = """
{"wf_unique_id": "4", "wf_body": {"nodes": [ { "task_name": "SelectDataset", "task_id": "flowchartNode1", "position": "left: 600px; top: 114px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [], "parameters": [{"name": "name", "type": "str", "display_name": "Dataset Name", "lookup": [{"title": "Bank Campaign Dataset",  "uuid": "ff6e6b81fe0448948656677872dd705d.csv"}], "value": "test_data/bank.csv"}, {"name": "delimiter", "type": "str", "display_name": "Dataset Name", "value": ","}]}, { "task_name": "SelectColumns", "task_id": "flowchartNode2", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode1", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "age,job,marital,education,default,balance,housing,loan,contact,day,month,duration,campaign,pdays,previous,poutcome,y"}]}, { "task_name":"FillMissingWithMean", "task_id": "flowchartNode3", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode2", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "balance,age"}]}, { "task_name":"CategoryEncoding", "task_id": "flowchartNode4", "position": "left: 480px; top: 280px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode3", "id": "BottomCenter"}]}], "parameters": [{"name": "col_name", "type": "str", "display_name": "Column Name(s)", "value": "job,marital,education,default,housing,loan,contact,month,poutcome"}] }, { "task_name": "SplitData", "task_id": "flowchartNode5", "position": "left: 460px; top: 460px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode4", "id": "BottomCenter"}]}], "parameters": [{"name": "perc", "type": "float", "display_name": "Partition Percentage", "value": 0.7}]}, { "task_name": "RandomForestClassifier", "task_id": "flowchartNode6", "position": "left: 150px; top: 366px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [], "parameters": [ {"name": "n_estimators", "type": "integer", "display_name": "Number of Estimators", "value": 100}]}, { "task_name": "FitModel", "task_id": "flowchartNode7", "position": "left: 150px; top: 366px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopLeft", "targets": [{"nodeId": "flowchartNode6", "id": "BottomCenter"}]},  {"id": "TopRight", "targets": [{"nodeId": "flowchartNode5", "id": "BottomLeft"}]}], "parameters": [ {"name": "label_column", "type": "string", "display_name": "Number of Estimators", "value": "y"}]}, { "task_name": "RunModel", "task_id": "flowchartNode8", "position": "left: 680px; top: 567px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopLeft", "targets": [{"nodeId": "flowchartNode7", "id": "BottomCenter"}]},  {"id": "TopRight", "targets": [{"nodeId": "flowchartNode5", "id": "BottomRight"}]}], "parameters": [{"name": "label_column", "type": "string", "display_name": "Number of Estimators", "value": "y"}]}, { "task_name": "ClassificationMetrics", "task_id": "flowchartNode9", "position": "left: 680px; top: 567px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;", "inputs": [{"id": "TopCenter", "targets": [{"nodeId": "flowchartNode8", "id": "BottomCenter"}]}], "parameters": [{"name": "label_column", "type": "string", "display_name": "target column", "value": "y"},{"name": "predict_column",  "type": "string",  "display_name": "predicted column",  "value": "predictions"}]}]}, "run_to_task_id": "", "execution_mode": "light", "storage": false, "deploy": "flowchartNode7", "node_name": "flowchartNode1", "output_port_id": "1", "col_1": "day", "num_bins": 10, "col_2": "previous", "col_names": "day,previous", "plot_type": "matrix", "model_name": "b03ffdaa422e450788cec3e80b308a3d", "observation": [ { "age": 36, "balance": 260, "campaign": 1, "contact": "cellular", "day": 7, "default": "no", "duration": 49, "education": "tertiary", "housing": "yes", "job": "management", "loan": "no", "marital": "single", "month": "may", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 40, "balance": 11084, "campaign": 1, "contact": "unknown", "day": 11, "default": "no", "duration": 113, "education": "secondary", "housing": "no", "job": "blue-collar", "loan": "no", "marital": "married", "month": "jun", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 52, "balance": 20, "campaign": 1, "contact": "telephone", "day": 28, "default": "no", "duration": 172, "education": "primary", "housing": "yes", "job": "unemployed", "loan": "no", "marital": "married", "month": "jan", "pdays": -1, "poutcome": "unknown", "previous": 0 }, { "age": 30, "balance": 102, "campaign": 7, "contact": "cellular", "day": 5, "default": "no", "duration": 470, "education": "tertiary", "housing": "yes", "job": "management", "loan": "no", "marital": "married", "month": "apr", "pdays": 426, "poutcome": "other", "previous": 3 }, { "age": 42, "balance": 292, "campaign": 3, "contact": "cellular", "day": 11, "default": "no", "duration": 222, "education": "secondary", "housing": "yes", "job": "services", "loan": "no", "marital": "married", "month": "may", "pdays": -1, "poutcome": "unknown", "previous": 0 }]}
"""
    r = data['session'].post(u, data=j)
    assert_ret_code(r, 200)

def ml_get_node_metrics(data):
    global payload
    u = url("ml/node/get_eval_metrics")
    r = data['session'].post(u, data=payload)
    assert_ret_code(r, 200)


def ml_get_node_roc_chart(data):
    global payload
    u = url("ml/node/get_roc_chart")
    r = data['session'].post(u, data=payload)
    assert_ret_code(r, 200)

def ml_get_workflow_ports_md(data):
    global payload
    u = url("ml/node/get_workflow_ports_md")
    r = data['session'].post(u, data=payload)
    assert_ret_code(r, 200)

def ml_get_node_output_pairwise(data):
    global payload
    u = url("ml/node/get_node_output_pairwise")
    r = data['session'].post(u, data=payload)
    assert_ret_code(r, 200)


def ml_get_node_output_corr_matrix(data):
    global payload
    u = url("ml/node/get_node_output_corr_matrix")
    r = data['session'].post(u, data=payload)
    assert_ret_code(r, 200)


def ml_get_node_output_hist(data):
    global payload
    u = url("ml/node/get_node_output_hist")
    r = data['session'].post(u, data=payload)
    assert_ret_code(r, 200)


def ml_get_exp_create(data):
    p = """
    {"wf_unique_id": "5", "wf_body": {"nodes": [{"task_name": "SelectDataset", "task_id": "flowchartNode1", "position": "left: 400px; top: 87px; line-height: 35px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode2", "id": "TopCenter"}]}], "parameters": [{"name": "dataset_name", "type": "string", "display_name": "Dataset Name", "lookup": [{"title": "2019 Bank Campaign Dataset", "uuid": "f106668b05e146ebb3f65c62f20db8f4.csv"}, {"title": "Loans Dataset", "uuid": "ff6e6b81fe0448948656677872dd705d.csv"}], "value": "f106668b05e146ebb3f65c62f20db8f4.csv"}]}, {"task_name": "SelectColumns", "task_id": "flowchartNode2", "position": "left: 394px; top: 248px; line-height: 35px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode3", "id": "TopCenter"}]}], "parameters": [{"name": "col_names", "type": "multiple_columns", "display_name": "Column Name(s)", "value": "age,default,balance,housing,loan,day,duration,campaign,previous,y"}]}, {"task_name": "SplitData", "task_id": "flowchartNode3", "position": "left: 400px; top: 390px; line-height: 35px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);", "outputs": [{"id": "BottomLeft", "targets": [{"nodeId": "flowchartNode5", "id": "TopRight"}]}, {"id": "BottomRight", "targets": [{"nodeId": "flowchartNode6", "id": "TopRight"}]}], "parameters": [{"name": "partition_percentage", "type": "float", "display_name": "Partition Percentage", "value": "0.6"}]}, {"task_name": "RandomForestClassifier", "task_id": "flowchartNode4", "position": "left: 134px; top: 329px; line-height: 35px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode5", "id": "TopLeft"}]}], "parameters": [{"name": "n_estimators", "type": "string", "display_name": "Number of Estimators", "value": "100"}]}, {"task_name": "FitModel", "task_id": "flowchartNode5", "position": "left: 140px; top: 540px; line-height: 35px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode6", "id": "TopLeft"}]}], "parameters": [{"name": "label_column", "type": "single_column", "display_name": "Label Column", "value": "y"}]}, {"task_name": "RunModel", "task_id": "flowchartNode6", "position": "left: 380px; top: 660px; line-height: 35px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode7", "id": "TopCenter"}]}], "parameters": [{"name": "label_column", "type": "single_column", "display_name": "Label Column", "value": "y"}]}, {"task_name": "ClassificationMetrics", "task_id": "flowchartNode7", "position": "left: 660px; top: 640px; line-height: 35px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);", "outputs": [], "parameters": [{"name": "label_column", "type": "single_column", "display_name": "Label Column", "value": "y"}, {"name": "predict_column", "type": "single_column", "display_name": "Predicted Column", "value": "predictions"}]}]}, "run_to_task_id": "", "experimentName": "my deployed service", "userId": "1"}
    """
    u = url("ml/experiment/create")
    r = data['session'].post(u, data=p)
    assert_ret_code(r, 200)

def ml_exp_listByUserId(data):
    p = '{"userId": "1"}'
    u = url("ml/experiment/listByUserId")
    r = data['session'].post(u, data=p)
    assert_ret_code(r, 200)

def ml_exp_save(data):
    p = """
{"experimentId": "5", "workflowJson": {"wf_unique_id": "5", "wf_body": {"nodes": [{"task_name": "SelectDataset", "task_id": "flowchartNode1", "position": "left: 400px; top: 87px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode2", "id": "TopCenter"}]}], "parameters": [{"name": "dataset_name", "type": "string", "display_name": "Dataset Name", "lookup": [{"title": "2019 Bank Campaign Dataset", "uuid": "f106668b05e146ebb3f65c62f20db8f4.csv"}, {"title": "Loans Dataset", "uuid": "ff6e6b81fe0448948656677872dd705d.csv"}], "value": "f106668b05e146ebb3f65c62f20db8f4.csv"}]}, {"task_name": "SelectColumns", "task_id": "flowchartNode2", "position": "left: 394px; top: 248px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode3", "id": "TopCenter"}]}], "parameters": [{"name": "col_names", "type": "multiple_columns", "display_name": "Column Name(s)", "value": "age,default,balance,housing,loan,day,duration,campaign,previous,y"}]}, {"task_name": "SplitData", "task_id": "flowchartNode3", "position": "left: 400px; top: 390px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;", "outputs": [{"id": "BottomLeft", "targets": [{"nodeId": "flowchartNode5", "id": "TopRight"}]}, {"id": "BottomRight", "targets": [{"nodeId": "flowchartNode6", "id": "TopRight"}]}], "parameters": [{"name": "partition_percentage", "type": "float", "display_name": "Partition Percentage", "value": "0.6"}]}, {"task_name": "RandomForestClassifier", "task_id": "flowchartNode4", "position": "left: 134px; top: 329px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode5", "id": "TopLeft"}]}], "parameters": [{"name": "n_estimators", "type": "string", "display_name": "Number of Estimators", "value": "100"}]}, {"task_name": "FitModel", "task_id": "flowchartNode5", "position": "left: 140px; top: 540px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode6", "id": "TopLeft"}]}], "parameters": [{"name": "label_column", "type": "single_column", "display_name": "Label Column", "value": "y"}]}, {"task_name": "RunModel", "task_id": "flowchartNode6", "position": "left: 380px; top: 660px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;", "outputs": [{"id": "BottomCenter", "targets": [{"nodeId": "flowchartNode7", "id": "TopCenter"}]}], "parameters": [{"name": "label_column", "type": "single_column", "display_name": "Label Column", "value": "y"}]}, {"task_name": "ClassificationMetrics", "task_id": "flowchartNode7", "position": "left: 660px; top: 640px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); line-height: 35px;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;color: #000000;background-color: #ffffff;", "outputs": [], "parameters": [{"name": "label_column", "type": "single_column", "display_name": "Label Column", "value": "y"}, {"name": "predict_column", "type": "single_column", "display_name": "Predicted Column", "value": "predictions"}]}]}, "run_to_task_id": ""}}
    """
    u = url("ml/experiment/save")
    r = data['session'].post(u, data=p)
    assert_ret_code(r, 200)

def ml_exp_retrieve(data):
    p = "{'experimentId': '5'}"
    u = url("ml/experiment/retrieve")
    r = data['session'].post(u, data=p)
    assert_ret_code(r, 200)
