Skip to content

Commit

Permalink
Update with no utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
craig8 committed Aug 2, 2024
1 parent 2346f2a commit 7eb6240
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
13 changes: 7 additions & 6 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ gridappsd:
# GridAPPS-D API endpoint
address: 'localhost'
port: 61613
model_name: 'ieee13nodeckt'
model_name: 'imp_base_reduced_southern_withpv'
#model_name: 'ieee13nodeckt'

#simulation_id: 5023

Expand All @@ -87,13 +88,13 @@ gridappsd:
# both houses as well as utilities. When utiliities are found there will
# be 3 named inverters for each utility (utility_bat1_a, utility_bat1_b,
# utility_bat1_c, etc)
house_named_inverters_regex: '646'
utility_named_inverters_regex: '652'
# house_named_inverters_regex: 'house_\d+_\d+v'
# utility_named_inverters_regex: 'utility_bat\d+'
# house_named_inverters_regex: '646'
# utility_named_inverters_regex: '652'
house_named_inverters_regex: '.*house_\d+_\d+v'
utility_named_inverters_regex: '.*utility_bat\d+'

# Model dictionary file to use rather than querying the gridappsd server.
model_dict_file: 'model_dict.json'
# model_dict_file: 'model_dict.json'

# GridAPPS-D username
username: system
Expand Down
2 changes: 1 addition & 1 deletion ieee_2030_5/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import os
import shutil

log_level = os.environ.get('LOGGING_LEVEL', 'DEBUG').upper()
log_level = os.environ.get('LOGGING_LEVEL', 'INFO').upper()

levels = {
'DEBUG': logging.DEBUG,
Expand Down
25 changes: 17 additions & 8 deletions ieee_2030_5/adapters/gridappsd_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class HouseLookup:
mRID: str
name: str
lfdi: Lfdi
lfdi: Lfdi | None = None


class PublishTimer(Timer):
Expand All @@ -56,10 +56,10 @@ class GridAPPSDAdapter:

_publish_interval_seconds: int = 3
_default_pin: str | None = None
_inverters: list[HouseLookup] | None = None
_model_dict_file: str | None = None
_model_id: str | None = None
_model_name: str | None = None
_inverters: list[HouseLookup] | None = None
_devices: list[DeviceConfiguration] | None = None
_power_electronic_connections: list[cim.PowerElectronicsConnection] | None = None
_timer: PublishTimer | None = None
Expand Down Expand Up @@ -147,14 +147,20 @@ def get_house_and_utility_inverters(self) -> list[HouseLookup]:
# and add them to the list.
for ec in feeder['energyconsumers']:
if match_house := re.match(re_houses, ec['name']):
try:
lfdi=self.tls.lfdi(ec['mRID'])
except FileNotFoundError:
lfdi = None
self._inverters.append(HouseLookup(mRID=ec['mRID'],
name=match_house.group(0),
lfdi=self.tls.lfdi(ec['mRID'])))
lfdi=lfdi))
elif match_utility := re.match(re_utility, ec['name']):
for phase in ec['phases']:
self._inverters.append(HouseLookup(mRID=ec['mRID'],
name=match_utility.group(0) + f"_{phase}",
lfdi=self.tls.lfdi(ec['mRID'])))
pass
# TODO: Figure out about mrid for utilities.
# for phase in ec['phases']:
# self._inverters.append(HouseLookup(mRID=ec['mRID'],
# name=match_utility.group(0) + f"_{phase}",
# lfdi=self.tls.lfdi(ec['mRID'])))
return self._inverters

def get_power_electronic_connections(self) -> list[cim.PowerElectronicsConnection]:
Expand Down Expand Up @@ -233,7 +239,8 @@ def get_message_for_bus(self) -> dict:
_log.debug(f"Status is: {status}")
if status:
_log.debug(f"Status found: {status}")
for x in self._devices:
_log.debug(f"Looking for: {meta_data['lfdi']}")
for x in self._inverters:
if x.lfdi == meta_data['lfdi']:
inverter = x
_log.debug(f"Found inverter: {inverter}")
Expand Down Expand Up @@ -268,6 +275,8 @@ def create_2030_5_device_certificates_and_configurations(self) -> list[DeviceCon
if self.use_houses_as_inverters():
for house in self.get_house_and_utility_inverters():
self.tls.create_cert(house.mRID)
if house.lfdi is None:
house.lfdi = self.tls.lfdi(house.mRID)
else:
for inv in self.get_power_electronic_connections():
self.tls.create_cert(inv.mRID)
Expand Down
25 changes: 13 additions & 12 deletions ieee_2030_5/flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@
tls_repository: TLSRepository = None


class LogProtocolHandler(logging.Handler):
# class LogProtocolHandler(logging.Handler):

def __init__(self, level=0) -> None:
super().__init__(level)
super().setFormatter('%(message)s')
# def __init__(self, level=0) -> None:
# super().__init__(level)
# super().setFormatter('%(message)s')

def emit(self, record: logging.LogRecord) -> None:
pass # super().handle(record)
# def emit(self, record: logging.LogRecord) -> None:
# pass # super().handle(record)


_log_protocol = logging.getLogger("protocol")
_log_protocol.addHandler(LogProtocolHandler(logging.DEBUG))
# _log_protocol = logging.getLogger("protocol")
# _log_protocol.addHandler(LogProtocolHandler(logging.DEBUG))


class PeerCertWSGIRequestHandler(werkzeug.serving.WSGIRequestHandler):
Expand Down Expand Up @@ -183,10 +183,11 @@ def before_request():


def after_request(response: Response) -> Response:
_log_protocol.debug(f"\nREQ: {request.path}")
_log_protocol.debug(f"\nRESP HEADER: {str(response.headers).strip()}")
first_line = response.get_data().decode('utf-8').split('\n')[0]
_log_protocol.debug(f"\nRESP: {first_line}")

# _log_protocol.debug(f"\nREQ: {request.path}")
# _log_protocol.debug(f"\nRESP HEADER: {str(response.headers).strip()}")
# first_line = response.get_data().decode('utf-8').split('\n')[0]
# _log_protocol.debug(f"\nRESP: {first_line}")

# _log.debug(f"RESP HEADERS:\n{response.headers}")
# _log.debug(f"RESP:\n{response.get_data().decode('utf-8')}")
Expand Down
9 changes: 7 additions & 2 deletions ieee_2030_5/server/derfs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from dataclasses import asdict
from typing import Optional
from pprint import pformat

from flask import Response, request
from werkzeug.exceptions import NotFound
Expand Down Expand Up @@ -42,8 +44,11 @@ def put(self) -> Response:
data = request.get_data(as_text=True)
data = xml_to_dataclass(data, clstype[parser.at(2)])

_log.info(f"DER PUT {request.path} {data}")
_log.debug(f"Meta data")
# if request.path.endswith("ders") or request.path.endswith("derg"):
# print(f"----------------------DER PUT {request.path} {data}")


_log.info(f"DER PUT {request.path} {asdict(data)}")
meta_data = dict(lfdi=self.lfdi, uri=f"{request.path}")
adpt.ListAdapter.set_single_amd_meta_data(uri=f"{request.path}",
envelop=meta_data,
Expand Down

0 comments on commit 7eb6240

Please sign in to comment.