From 2ae0dcc21edd49ba865de28bb0172165634bdd51 Mon Sep 17 00:00:00 2001 From: jsimpson Date: Thu, 5 Aug 2021 16:16:44 -0600 Subject: [PATCH 1/2] Updated to use simulation time and gridappsd-python command --- pyvvo/app.py | 4 ++-- pyvvo/gridappsd_platform.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pyvvo/app.py b/pyvvo/app.py index 3f8a129..234305e 100644 --- a/pyvvo/app.py +++ b/pyvvo/app.py @@ -221,11 +221,11 @@ def main(sim_id: str, sim_request: dict): cap_cmd = cap_mgr.build_equipment_commands(cap_forward) # Send 'em! - reg_msg = platform.send_command(sim_id=sim_id, **reg_cmd) + reg_msg = platform.send_command(sim_id=sim_id, sim_epoch=router.sim_epoch, **reg_cmd) if reg_msg is not None: LOG.info('Regulator commands sent in.') - cap_msg = platform.send_command(sim_id=sim_id, **cap_cmd) + cap_msg = platform.send_command(sim_id=sim_id, sim_epoch=router.sim_epoch, **cap_cmd) if cap_msg is not None: LOG.info('Capacitor commands sent in.') diff --git a/pyvvo/gridappsd_platform.py b/pyvvo/gridappsd_platform.py index eeb5589..ab1cdd9 100644 --- a/pyvvo/gridappsd_platform.py +++ b/pyvvo/gridappsd_platform.py @@ -69,8 +69,8 @@ def get_gad_object(**kwargs): # TODO: handle connection failures? # TODO: flexibility for different username/password? - gad = GridAPPSD(address=address, username=gad_utils.get_gridappsd_user(), - password=gad_utils.get_gridappsd_pass(), **kwargs) + gad = GridAPPSD(address=address, username="system", + password='manager', **kwargs) LOG.debug('GridAPPSD object created and connected to the platform.') return gad @@ -155,6 +155,13 @@ def __init__(self, platform_manager, sim_id, fn_mrid_list): self.platform.gad.subscribe(topic=self.output_topic, callback=self._on_message) + # Simulation time + self._sim_epoch = 0 + + @property + def sim_epoch(self): + return self._sim_epoch + @utils.wait_for_lock def add_funcs_and_mrids(self, fn_mrid_list): """Helper to add functions and MRIDs to the router. @@ -213,6 +220,7 @@ def _on_message(self, header, message): # Log simulation time. sim_dt = simulation_dt(int(message['message']['timestamp'])) + self._sim_epoch = message['message']['timestamp'] self.log.debug( 'Simulation timestamp: {}'.format(sim_dt.strftime(DATE_FORMAT))) @@ -297,7 +305,7 @@ def __init__(self, timeout=60, stomp_log_level=logging.WARNING, self.last_sim_config = None def send_command(self, object_ids, attributes, forward_values, - reverse_values, sim_id=None): + reverse_values, sim_id=None, sim_epoch=0): """Function for sending a command into a running simulation. This is partly a wrapper to DifferenceBuilder, but also sends the command into the simulation. @@ -315,6 +323,7 @@ def send_command(self, object_ids, attributes, forward_values, :param sim_id: Simulation ID. If None, will attempt to use self.sim.simulation_id. If that is also None, ValueError will be raised. + :param sim_epoch: Simulation epoch time. Default 0. :returns: Dictionary representing the message that gets sent in. If no message will be sent (if input lists are empty), @@ -366,7 +375,7 @@ def send_command(self, object_ids, attributes, forward_values, reverse_value=reverse_values[k]) # Get the message and log it. - msg = diff_builder.get_message() + msg = diff_builder.get_message(epoch=sim_epoch) msg_str = json.dumps(msg) self.log.info('Preparing to send following command: {}' .format(msg_str)) From 900ffe224f64c96419087f06b9cf9d767fe71327 Mon Sep 17 00:00:00 2001 From: jsimpson Date: Wed, 13 Oct 2021 14:50:36 -0600 Subject: [PATCH 2/2] Removed 'message' from glm = REGEX_2.sub('', REGEX_1.sub('', response)) --- pyvvo/gridappsd_platform.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyvvo/gridappsd_platform.py b/pyvvo/gridappsd_platform.py index ab1cdd9..f8e0a58 100644 --- a/pyvvo/gridappsd_platform.py +++ b/pyvvo/gridappsd_platform.py @@ -399,7 +399,8 @@ def get_glm(self, model_id): # Fix bad json return. # TODO: remove when platform is fixed. - glm = REGEX_2.sub('', REGEX_1.sub('', response['message'])) + # glm = REGEX_2.sub('', REGEX_1.sub('', response['message'])) + glm = REGEX_2.sub('', REGEX_1.sub('', response)) return glm def _query_weather(self, start_time, end_time):