from locust import HttpUser, task, between 
import json
 
class APIUser(HttpUser):
    wait_time = between(1, 2)
    #load the prediction component
    @task(3)  
    def request_preds(self):
        headers = {'content-type': 'application/json'}
        self.client.post("http://34.123.122.129:5002/prediction-cp/flower",data= json.dumps([
            {"sepal_length":6.1, 
            "sepal_width":2.8, 
            "petal_length":4.7, 
            "petal_width":1.2}, 
            {"sepal_length":5.7, 
            "sepal_width":3.8, 
            "petal_length":1.7, 
            "petal_width":0.3}, 
            {"sepal_length":7.7, 
            "sepal_width":2.6, 
            "petal_length":6.9, 
            "petal_width":2.3}, 
            {"sepal_length":6.0, 
            "sepal_width":2.9, 
            "petal_length":4.5, 
            "petal_width":1.5}, 
            {"sepal_length":6.8, 
            "sepal_width":2.8, 
            "petal_length":4.8, 
            "petal_width":1.4}, 
            {"sepal_length":5.4, 
            "sepal_width":3.4, 
            "petal_length":1.5, 
            "petal_width":0.4}, 
            {"sepal_length":5.6, 
            "sepal_width":2.9, 
            "petal_length":3.6, 
            "petal_width":1.3}, 
            {"sepal_length":6.9, 
            "sepal_width":3.1, 
            "petal_length":5.1, 
            "petal_width":2.3}, 
            {"sepal_length":6.2, 
            "sepal_width":2.2, 
            "petal_length":4.5, 
            "petal_width":1.5}, 
            {"sepal_length":5.8, 
            "sepal_width":2.7, 
            "petal_length":3.9, 
            "petal_width":1.2}, 
            {"sepal_length":6.5, 
            "sepal_width":3.2, 
            "petal_length":5.1, 
            "petal_width":2.0}, 
            {"sepal_length":4.8, 
            "sepal_width":3.0, 
            "petal_length":1.4, 
            "petal_width":0.1}, 
            {"sepal_length":5.5, 
            "sepal_width":3.5, 
            "petal_length":1.3, 
            "petal_width":0.2}, 
            {"sepal_length":4.9, 
            "sepal_width":3.1, 
            "petal_length":1.5, 
            "petal_width":0.1}, 
            {"sepal_length":5.1, 
            "sepal_width":3.8, 
            "petal_length":1.5, 
            "petal_width":0.3}, 
            {"sepal_length":6.3, 
            "sepal_width":3.3, 
            "petal_length":4.7, 
            "petal_width":1.6}, 
            {"sepal_length":6.5, 
            "sepal_width":3.0, 
            "petal_length":5.8, 
            "petal_width":2.2}, 
            {"sepal_length":5.6, 
            "sepal_width":2.5, 
            "petal_length":3.9, 
            "petal_width":1.1}, 
            {"sepal_length":5.7, 
            "sepal_width":2.8, 
            "petal_length":4.5, 
            "petal_width":1.3}, 
            {"sepal_length":6.4, 
            "sepal_width":2.8, 
            "petal_length":5.6, 
            "petal_width":2.2}, 
            {"sepal_length":4.7, 
            "sepal_width":3.2, 
            "petal_length":1.6, 
            "petal_width":0.2}, 
            {"sepal_length":6.1, 
            "sepal_width":3.0, 
            "petal_length":4.9, 
            "petal_width":1.8}, 
            {"sepal_length":5.0, 
            "sepal_width":3.4, 
            "petal_length":1.6, 
            "petal_width":0.4}, 
            {"sepal_length":6.4, 
            "sepal_width":2.8, 
            "petal_length":5.6, 
            "petal_width":2.1}]), 
        headers=headers, 
        name = "prediction request")
    
    #load the db component
    @task
    def get_db_data(self):        
        self.client.get("http://34.68.51.82:5000/training-db/iris", name="get data")
    #load the training component (requires slower wait time, test separately)    
    # @task(1)
    # def train_model_req(self):
        # self.client.post("http://34.122.10.73:5001/training-cp/flower", name="train model") 
