From fb749976fa7922e54ed7d613303e16abb1d5ef2b Mon Sep 17 00:00:00 2001 From: Hiroyuki Eguchi Date: Sat, 7 Jan 2017 14:37:33 +0900 Subject: [PATCH] Online Prediction This patch allows user to load a Prediction Model in advance for online prediction. In online prediction, user can retrieve a predicted data immediately. implements blueprint online-prediction Change-Id: Ic65fb8ba4eabdbd460d1f0c99fa2972cb64f3aa9 --- meteosclient/api/base.py | 2 +- meteosclient/api/models.py | 14 ++++++++++++++ meteosclient/api/shell.py | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/meteosclient/api/base.py b/meteosclient/api/base.py index 6bf3c6b..5c6166b 100644 --- a/meteosclient/api/base.py +++ b/meteosclient/api/base.py @@ -148,7 +148,7 @@ class ResourceManager(object): resp = self.api.post(url, **kwargs) - if resp.status_code != 202: + if resp.status_code != 202 and resp.status_code != 200: self._raise_api_exception(resp) if response_key is not None: diff --git a/meteosclient/api/models.py b/meteosclient/api/models.py index 5a8d4b9..c6bfb45 100644 --- a/meteosclient/api/models.py +++ b/meteosclient/api/models.py @@ -70,3 +70,17 @@ class ModelManager(base.ResourceManager): def delete(self, model_id): """Delete a Model Model.""" self._delete('/models/%s' % model_id) + + def load(self, model_id): + """Load a Model.""" + url = '/models/%s/action' % model_id + body = {'os-load': None} + + self._post(url, body) + + def unload(self, model_id): + """Unload a Model.""" + url = '/models/%s/action' % model_id + body = {'os-unload': None} + + self._post(url, body) diff --git a/meteosclient/api/shell.py b/meteosclient/api/shell.py index 1a2dc71..4bf204c 100644 --- a/meteosclient/api/shell.py +++ b/meteosclient/api/shell.py @@ -225,6 +225,10 @@ def do_dataset_delete(cs, args): # # model-delete # +# model-load +# +# model-unload +# def do_model_list(cs, args): @@ -268,6 +272,22 @@ def do_model_delete(cs, args): cs.models.delete(args.id) +@utils.arg('id', + metavar='', + help='ID of the model to load.') +def do_model_load(cs, args): + """Load a model for online prediction.""" + cs.models.load(args.id) + + +@utils.arg('id', + metavar='', + help='ID of the model to unload.') +def do_model_unload(cs, args): + """Unload a model.""" + cs.models.unload(args.id) + + # # Learnings # ~~~~~~~~