Skip to content

Commit

Permalink
examples fix docker correct some leftover bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zlatsic committed Sep 24, 2024
1 parent 2dc0ea1 commit e3596ef
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 53 deletions.
2 changes: 1 addition & 1 deletion examples/0001/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10
FROM python:3.12

WORKDIR /opt/aimm

Expand Down
2 changes: 1 addition & 1 deletion examples/0002/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10
FROM python:3.12

WORKDIR /opt/aimm

Expand Down
7 changes: 3 additions & 4 deletions examples/0002/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ ports need to be mapped. All processes should be ran in the same container.
#. Default command will start hat, relevant ports:
* ``23020``: SysLog UI - system logs of all components
* ``23021``: Orchestrator UI - active Hat processes
* ``23022``: Monitor UI - system components and their redundancy statuses
* ``23023``: GUI - interface where measurments and estimations are shown
#. Simulation is started separatly with command
* ``23023``: GUI - interface where measurements and estimations are shown
#. Simulation is started separately with command
``docker exec <container_name> python ./src_py/simulation.py``
#. Measurements should be visible on the GUI
#. AIMM is started separatly with commadn ``docker exec <container_name> ./aimm.sh``
#. AIMM is started separately with command ``docker exec <container_name> ./aimm.sh``
#. Estimations are shown alongside measurements in the GUI
2 changes: 2 additions & 0 deletions examples/0002/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ jsonpatch==1.33
jsonpointer==3.0.0
jsonschema==4.22.0
jsonschema-specifications==2023.12.1
llvmlite==0.43.0
lmdb==1.4.1
multidict==6.1.0
networkx==3.3
numba==0.60.0
numpy==1.26.4
orderly-set==5.2.2
packaging==24.1
Expand Down
18 changes: 10 additions & 8 deletions examples/0002/src_py/scada/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
class Module(common.Module):
def __init__(self, _, engine, source):
self._gw_prefix = ("gateway", "gateway", "device", "device")
self._subscription = common.create_subscription([
("measurement", "?", "?"),
("event", "?", "eventer", "gateway"),
("aimm", "state"),
("aimm", "response"),
])
self._subscription = common.create_subscription(
[
("measurement", "?", "?"),
("event", "?", "eventer", "gateway/gateway"),
("aimm", "state"),
("aimm", "response"),
]
)

self._source = source

Expand Down Expand Up @@ -49,13 +51,13 @@ async def _async_generator_process(self, source, e):
return

payload = e.payload.data
if e.type == ("event", "0", "eventer", "gateway"):
if e.type == ("event", "0", "eventer", "gateway/gateway"):
if payload == "CONNECTED":
yield _register_event(
(
"gateway",
"device",
"device",
"example",
"system",
"enable",
),
Expand Down
2 changes: 1 addition & 1 deletion examples/0003/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10
FROM python:3.12

RUN apt update
RUN apt install -y npm
Expand Down
2 changes: 1 addition & 1 deletion examples/0003/src_js/views/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function plot() {
}

const generate_model_buttons = function (prediction_type) {
if (!r.get('remote','timeseries','info',prediction_type,'supported_models')) return;
if (!r.get('remote','timeseries','info',prediction_type,'supported_models')) return [];

const cur_model_name = prediction_type === 'anomaly' ? cur_anomaly_model_name : cur_forecast_model_name;

Expand Down
18 changes: 10 additions & 8 deletions examples/0003/src_py/air_supervision/adapters/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def __init__(self, _, event_client):
self._series_values = {
"reading": deque(maxlen=72),
"anomaly": deque(maxlen=21),
"forecast": []
"forecast": [],
}
self._series_timestamps = {
"reading": deque(maxlen=72),
"anomaly": deque(maxlen=21),
"forecast": []
"forecast": [],
}

self._state_change_cb_registry = hat.util.CallbackRegistry()
Expand All @@ -58,7 +58,7 @@ async def create_session(self, user, roles, state, notify_cb):
state,
notify_cb,
self._async_group.create_subgroup(),
self._event_client
self._event_client,
)
self._state_change_cb_registry.register(session.on_state_change)
session.on_state_change()
Expand Down Expand Up @@ -104,18 +104,20 @@ async def _update_series(self, event):
value_key = "result" if series_id == "forecast" else "value"
self._series_values[series_id].append(event.payload.data[value_key])

self._series_timestamps[series_id].append(datetime.strptime(
event.payload.data["timestamp"], "%Y-%m-%d %H:%M:%S"
))
self._series_timestamps[series_id].append(
datetime.strptime(
event.payload.data["timestamp"], "%Y-%m-%d %H:%M:%S"
)
)

forecast_t = self._series_timestamps["forecast"]
if not forecast_t:
return
forecast_v = self._series_values["forecast"]
forecast_v, forecast_t = _truncate_lists(forecast_v, forecast_t)

oldest_forecast = (
max(self._series_timestamps["reading"]) - timedelta(days=2)
oldest_forecast = max(self._series_timestamps["reading"]) - timedelta(
days=2
)
if min(forecast_t) < oldest_forecast:
forecast_t = [i for i in forecast_t if i >= oldest_forecast]
Expand Down
20 changes: 11 additions & 9 deletions examples/0003/src_py/air_supervision/devices/air_readings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ async def _main_loop(self):
timestamp = self._df.iloc[index]["timestamp"]
value = (float(value) - 32) * 5 / 9

await self._event_client.register([
hat.event.common.RegisterEvent(
type=(*self._event_type_prefix, "gateway", "reading"),
source_timestamp=hat.event.common.Timestamp(index, 0),
payload=hat.event.common.EventPayloadJson(
{"timestamp": timestamp, "value": value},
),
)
])
await self._event_client.register(
[
hat.event.common.RegisterEvent(
type=(*self._event_type_prefix, "gateway", "reading"),
source_timestamp=hat.event.common.Timestamp(index, 0),
payload=hat.event.common.EventPayloadJson(
{"timestamp": timestamp, "value": value},
),
)
]
)


info = hat.gateway.common.DeviceInfo(type="example", create=AirReading)
37 changes: 18 additions & 19 deletions examples/0003/src_py/air_supervision/modules/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ def __init__(self, conf, engine, source):
self._min_readings = conf["min_readings"]
self._models_conf = conf["models"]

self._subscription = hat.event.common.create_subscription([
("user_action", self._model_family, "*"),
("aimm", "*"),
("gui", "system", "timeseries", "reading"),
])
self._subscription = hat.event.common.create_subscription(
[
("user_action", self._model_family, "*"),
("aimm", "*"),
("gui", "system", "timeseries", "reading"),
]
)

self._model_prefix = f"air_supervision.aimm.{self._model_family}"

Expand Down Expand Up @@ -59,16 +61,11 @@ async def process(self, source, event):
return list(events)

async def register_with_action_id(
self,
model_type,
request_id,
return_type,
events
self, model_type, request_id, return_type, events
):
await self._engine.register(self._source, events)
self._request_ids[request_id] = (return_type, model_type)


def _process_aimm(self, event):
msg_type = event.type[1]
if msg_type == "state":
Expand Down Expand Up @@ -288,7 +285,7 @@ async def _register_event(self, event_type, data, return_type):
source_timestamp=None,
payload=hat.event.common.EventPayloadJson(data),
)
]
],
)


Expand Down Expand Up @@ -326,13 +323,15 @@ def _ext_anomaly_dataset():
)
value = float(line[0].split(",")[1])
value = (float(value) - 32) * 5 / 9
train_data.append([
value,
timestamp.hour,
int((timestamp.hour >= 7) & (timestamp.hour <= 22)),
timestamp.weekday(),
int(timestamp.weekday() < 5),
])
train_data.append(
[
value,
timestamp.hour,
int((timestamp.hour >= 7) & (timestamp.hour <= 22)),
timestamp.weekday(),
int(timestamp.weekday() < 5),
]
)
fit_start = int(len(train_data) * 0.25)
return [train_data[fit_start:], None]

Expand Down
2 changes: 1 addition & 1 deletion examples/0003/src_py/air_supervision/modules/enable_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EnableAll(common.Module):
def __init__(self, _, engine, source):
self._source = source
self._subscription = common.create_subscription(
[("event", "?", "eventer", "gateway")]
[("event", "?", "eventer", "gateway/gateway")]
)
self._async_group = hat.aio.Group()
self._engine = engine
Expand Down

0 comments on commit e3596ef

Please sign in to comment.