From d227905fa6d81bcccc7a0f6306c66c170799dc00 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 22 Oct 2024 09:07:03 +0200 Subject: [PATCH] Added support for new definition of the connection --- configuration/modelling-example.yaml | 61 +++++++++++++++++++++------- configuration/parse_yaml.py | 21 +++++++--- 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/configuration/modelling-example.yaml b/configuration/modelling-example.yaml index 41e1f5b..8909e83 100644 --- a/configuration/modelling-example.yaml +++ b/configuration/modelling-example.yaml @@ -22,11 +22,9 @@ models: # list of models for the energy network - capacity - soc_min scenario_data: 'path/to/file' #path to the scenario data file for the model. This should be optional - method: - type: connect # can be python for local or connect for remote - location: null - connect_ip: 192.168.0.1 - connect_port: 5123 + connect: + ip: 192.168.0.1 + port: 5000 - name: Battery2 type: Battery # models can reuse the same type inputs: @@ -38,11 +36,47 @@ models: # list of models for the energy network charge_power_max: 100 states: soc: 0.5 # initial value for the state, optional - method: - type: connect # can be python for local or connect for remote - location: null - connect_ip: 192.168.0.2 - connect_port: 5123 + connect: + ip: 192.168.0.2 + port: 5000 +- name: Battery3 + type: Battery # models can reuse the same type + inputs: + input1: 0 # input-name: initial value, default value will be used if not defined + outputs: + output1: 0 + output2: null + parameters: + charge_power_max: 100 + states: + soc: 0.5 # initial value for the state, optional + connect: + port: 5000 +- name: Battery4 + type: Battery # models can reuse the same type + inputs: + input1: 0 # input-name: initial value, default value will be used if not defined + outputs: + output1: 0 + output2: null + parameters: + charge_power_max: 100 + states: + soc: 0.5 # initial value for the state, optional + connect: + ip: + port: 5000 +- name: Battery5 + type: Battery # models can reuse the same type + inputs: + input1: 0 # input-name: initial value, default value will be used if not defined + outputs: + output1: 0 + output2: null + parameters: + charge_power_max: 100 + states: + soc: 0.5 # initial value for the state, optional - name: PV1 type: PV inputs: @@ -54,11 +88,8 @@ models: # list of models for the energy network power_max: 100 states: initial_soc: 0.5 - method: - type: connect # can be python for local or connect for remote - location: null - connect_ip: 192.168.0.3 - connect_port: 5123 + connect: + ip: 192.168.0.3 connections: - from: Battery1.output2 # start model, pattern: model_name.output_name/input_name to: PV1.input1 # end model diff --git a/configuration/parse_yaml.py b/configuration/parse_yaml.py index 60c75d0..2a524b0 100644 --- a/configuration/parse_yaml.py +++ b/configuration/parse_yaml.py @@ -1,5 +1,12 @@ import yaml +""" +This script reads a yaml file of an illuminator model. It extracts the connection information. +If an IP port is not specified it will default to 5123. +If both IP address and port are known than a line will be prined that can be used in the run.sh file. +The run.sh file is used to start the processes on remote pi's. +""" + # Open and load the YAML file with open('modelling-example.yaml', 'r') as _file: data = yaml.safe_load(_file) @@ -10,13 +17,15 @@ for model in data['models']: model_type = model.get('type') - method = model.get('method', {}) - method_type = method.get('type') - location = method.get('location') - connect_ip = method.get('connect_ip') - connect_port = method.get('connect_port') + connect = model.get('connect', {}) + + if connect: + connect_ip = connect.get('ip') + connect_port = connect.get('port') + + if not connect_port: + connect_port = 5123 - if method_type == 'connect': if connect_ip and connect_port: print(f"lxterminal -e ssh illuminator@{connect_ip} '{run_path}run{model_type}.sh {connect_ip} {connect_port} {run_model}'&")