Beispiel #1
0
import os
import requests
from classes.KafkaPC import KafkaPC

env_vars = {'config_path': os.getenv('config_path'),
            'config_section': os.getenv('config_section')}

new_pc = KafkaPC(**env_vars)

API_URL = new_pc.config['API_URL']
ENDPOINT = "/production_parameter/x"
URL = API_URL + ENDPOINT


for msg in new_pc.consumer:
    """
    "name": "New X",
    "fields": [
        {"name": "new_x", "type": ["float"]}
        ]
    """

    new_message = new_pc.decode_avro_msg(msg)

    # defining a params dict for the parameters to be sent to the API
    params = {"value": new_message['new_x']}

    # sending get request and saving the response as response object
    print(f"Send x={round(new_message['new_x'], 3)} to the CPPS Controller")
    r = requests.put(url=URL, params=params)
Beispiel #2
0
"""

new_pc = KafkaPC(**env_vars)


for msg in new_pc.consumer:
    """
    "name": "Data",
    "fields": [
        {"name": "phase", "type": ["string"]},
        {"name": "id_x", "type": ["int"]},
        {"name": "x", "type": ["float"]},
        {"name": "y", "type": ["float"]}
        ]
    """
    new_data = new_pc.decode_avro_msg(msg)

    """
    "name": "Data",
    "fields": [
        {"name": "phase", "type": ["string"]},
        {"name": "id_x", "type": ["int"]},
        {"name": "x", "type": ["float"]},
        {"name": "y", "type": ["float"]}
        ]
    """

    new_data_point = {'phase': new_data['phase'],
                      'id': new_data['id'],
                      'x': new_data['x'],
                      'y': new_data['y']}
    "fields": [
        {"name": "phase", "type": ["enum"], "symbols": ["init", "observation"]},
        {"name": "model_name", "type": ["string"]},
        {"name": "n_data_points", "type": ["int"]},
        {"name": "id_start_x", "type": ["int"]},
        {"name": "model", "type": ["bytes"]},
        {"name": "model_size", "type": ["int"]},
        {"name": "rmse", "type": ["null", "float"]},
        {"name": "mae", "type": ["null", "float"]},
        {"name": "rsquared", "type": ["null", "float"]},
        {"name": "CPU_ms", "type": ["int"]},
        {"name": "RAM", "type": ["int"]}
        ]
    """

    new_model = new_pc.decode_avro_msg(msg)

    model = pickle.loads(new_model['model'])
    result = differential_evolution(evaluate_diff_evo,
                                    bounds,
                                    maxiter=N_MAX_ITER,
                                    popsize=N_POP_SIZE)

    surrogate_x = result.x[0]
    surrogate_y = result.fun

    print(f"The {new_model['model_name']} optimization suggests "
          f"x={round(surrogate_x, 3)}, y={round(surrogate_y, 3)}")
    """
    "name": "Model_Application",
    "fields": [