Commit f54ef6d7 authored by maciek riedl's avatar maciek riedl
Browse files

Merge branch 'iccs-eshybrid' into 'morphemic-rc1.5'

Iccs eshybrid

See merge request !173
parents fdb56126 95b72196
Pipeline #16619 passed with stages
in 15 minutes and 35 seconds
......@@ -12,11 +12,13 @@ class Connection:
def __init__(self, username, password,
host='localhost',
port=61613,
debug=False):
debug=False,
**kwargs):
self.username = username
self.password = password
self.hosts = [(host, port)]
self.conn = stomp.Connection(host_and_ports=self.hosts, auto_content_length=False)
self.conn = stomp.Connection(host_and_ports=self.hosts, auto_content_length=False,
timeout=kwargs.get('timeout',180000),keepalive=kwargs.get('keepalive', True))
if debug:
logging.debug("Enabling debug")
......
FROM ubuntu:20.04
ADD https://bootstrap.pypa.io/get-pip.py /tmp/get-pip.py
RUN apt-get update && apt-get install -y \
wget \
python3 \
python3-pip \
wget curl \
software-properties-common \
&& add-apt-repository ppa:deadsnakes/ppa \
&& apt install -y python3.9 python3.9-distutils \
&& python3.9 /tmp/get-pip.py \
&& rm -rf /var/lib/apt/lists/*
COPY . /app
ADD https://gitlab.ow2.org/melodic/morphemic-preprocessor/-/archive/morphemic-rc1.5/morphemic-preprocessor-morphemic-rc1.5.tar.gz /var/lib/morphemic/
......@@ -27,4 +33,4 @@ RUN pip3 install -r requirements.txt \
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["python3", "main.py"]
\ No newline at end of file
CMD ["python3.9", "main.py"]
......@@ -21,7 +21,9 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
config['messaging']['username'],
config['messaging']['password'],
host=config['messaging']['host'],
port=config['messaging']['port']
port=config['messaging']['port'],
timeout=6000,
keepalive=True
)
self.model = morphemic.model.Model(self)
self.application = config['persistence']['application']
......@@ -60,10 +62,6 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
self.run()
pass
def cleanup(self):
logging.debug("Cleaning Up...")
scheduler=False
pass
def signal_handler(self, signum, frame):
logging.debug("SIGHUP")
......@@ -72,7 +70,6 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
def stop(self):
logging.debug("Stopping...")
self._run = False
self.cleanup()
def start(self):
logging.debug("Starting ESHybrid")
......@@ -85,36 +82,31 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
if self.scheduler:
self.scheduler.check(self)
time.sleep(1)
self.connector.disconnect()
def on_schedule(self, times):
for m in self.metrics:
# predictions = self.model.predict(self.application, m, times)
# if not predictions:
# continue
predictions = self.model.predict(
self.application,
m,
times
)
for t in times:
logging.debug("Sending prediction for time %s(%s) " % (datetime.datetime.fromtimestamp(t), t))
self.connector.send_to_topic(
"intermediate_prediction.eshybrid.%s" % m,
{
"metricValue": 12.43,
"metricValue": predictions[t],
"timestamp": int(time.time()),
"probability": 0.98,
"confidence_interval": [float(8),float(15)],
"predictionTime":t,
}
)
# for p in predictions[m['metric']]:
def on_train(self):
self.connector.send_to_topic("training_models",
{
"metrics": self.metrics,
"forecasting_method": self.id,
"timestamp": int(time.time() * 1000)
})
def _train_model(self):
......@@ -122,6 +114,14 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
data = self.dataset.getData()
self.model.train(self.metrics, data)
def on_train(self):
self.connector.send_to_topic("training_models",
{
"metrics": self.metrics,
"forecasting_method": self.id,
"timestamp": int(time.time() * 1000)
})
def on_metrics_to_predict(self,res):
logging.debug("[2] Metrics to predics %s " % res)
......@@ -166,14 +166,14 @@ class ESHybrid(morphemic.handler.ModelHandler,messaging.listener.MorphemicListen
horizon= res[messaging.events.StartForecasting.PREDICTION_HORIZON]
)
def on_error(self, headers, body):
logging.error("Headers %s",headers)
logging.error(" %s",body)
def on_disconnected(self):
print('disconnected')
self.reconnect()
if self._run:
self.reconnect()
def on(self, headers, res):
......
......@@ -15,9 +15,7 @@ def main():
print("Config file %s ", config_file)
config = configparser.RawConfigParser()
config.read(config_file)
config_dict = dict(config)
e = eshybrid.ESHybrid(config)
e = eshybrid.ESHybrid(dict(config))
try:
e.start()
except KeyboardInterrupt:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment