From 67bae9a20d3285fdf19660b312b0af613c63dc8b Mon Sep 17 00:00:00 2001 From: NahcoCP Date: Mon, 22 Jan 2018 11:17:34 +0100 Subject: [PATCH] Implementing the evaluation service inside the Senpy api --- senpy/api.py | 15 +++++++++++++++ senpy/blueprints.py | 22 +++++++++++++++++++++- senpy/client.py | 7 +++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/senpy/api.py b/senpy/api.py index 358bb66..08a8a6d 100644 --- a/senpy/api.py +++ b/senpy/api.py @@ -53,6 +53,21 @@ API_PARAMS = { } } +EVAL_PARAMS = { + "algorithm": { + "aliases": ["plug", "p", "plugins", "algorithms", 'algo', 'a', 'plugin'], + "description": "Plugins to be evaluated", + "required": True, + "help": "See activated plugins in /plugins" + }, + "dataset": { + "aliases": ["datasets", "data", "d"], + "description": "Datasets to be evaluated", + "required": True, + "help": "See avalaible datasets in /datasets" + } +} + PLUGINS_PARAMS = { "plugin_type": { "@id": "pluginType", diff --git a/senpy/blueprints.py b/senpy/blueprints.py index 6a4fbe0..c453665 100644 --- a/senpy/blueprints.py +++ b/senpy/blueprints.py @@ -19,7 +19,7 @@ Blueprints for Senpy """ from flask import (Blueprint, request, current_app, render_template, url_for, jsonify) -from .models import Error, Response, Help, Plugins, read_schema +from .models import Error, Response, Help, Plugins, read_schema, Datasets from . import api from .version import __version__ from functools import wraps @@ -133,6 +133,17 @@ def api_root(): req = api.parse_call(request.parameters) return current_app.senpy.analyse(req) +@api_blueprint.route('/evaluate/', methods=['POST', 'GET']) +@basic_api +def evaluate(): + if request.parameters['help']: + dic = dict(api.EVAL_PARAMS) + response = Help(parameters=dic) + return response + else: + params = api.parse_params(request.parameters, api.EVAL_PARAMS) + response = current_app.senpy.evaluate(params) + return response @api_blueprint.route('/plugins/', methods=['POST', 'GET']) @basic_api @@ -150,3 +161,12 @@ def plugins(): def plugin(plugin=None): sp = current_app.senpy return sp.get_plugin(plugin) + + +@api_blueprint.route('/datasets/', methods=['POST','GET']) +@basic_api +def datasets(): + sp = current_app.senpy + datasets = sp.datasets + dic = Datasets(datasets = list(datasets.values())) + return dic \ No newline at end of file diff --git a/senpy/client.py b/senpy/client.py index ae1e375..892e77a 100644 --- a/senpy/client.py +++ b/senpy/client.py @@ -12,10 +12,17 @@ class Client(object): def analyse(self, input, method='GET', **kwargs): return self.request('/', method=method, input=input, **kwargs) + def evaluate(self, input, method='GET', **kwargs): + return self.request('/evaluate', method = method, input=input, **kwargs) + def plugins(self, *args, **kwargs): resp = self.request(path='/plugins').plugins return {p.name: p for p in resp} + def datasets(self): + resp = self.request(path='/datasets').datasets + return {d.name: d for d in resp} + def request(self, path=None, method='GET', **params): url = '{}{}'.format(self.endpoint, path) response = requests.request(method=method, url=url, params=params)