From 0093bc34d518d76573d83101770da10f942da44d Mon Sep 17 00:00:00 2001 From: NahcoCP Date: Thu, 8 Feb 2018 11:09:50 +0100 Subject: [PATCH] Change Playground to support evaluation table view --- senpy/extensions.py | 5 +- senpy/static/js/main.js | 105 +++++++++++++++++++++++++++++++++++-- senpy/templates/index.html | 52 +++++++++++++++++- 3 files changed, 156 insertions(+), 6 deletions(-) diff --git a/senpy/extensions.py b/senpy/extensions.py index abf237e..735f8a3 100644 --- a/senpy/extensions.py +++ b/senpy/extensions.py @@ -235,7 +235,8 @@ class Senpy(object): plugins = self._get_plugins(results) collector = list() for plugin in plugins: - collector += [eval for eval in plugin.score(datasets)] + for eval in plugin.score(datasets): + results.evaluations.append(eval) if 'with_parameters' not in results.parameters: del results.parameters logger.debug("Returning evaluation result: {}".format(results)) @@ -246,7 +247,7 @@ class Senpy(object): ex = Error(message=msg, status=500) logger.exception('Error returning evaluation result') raise ex - results.evaluations = collector + #results.evaluations = collector return results diff --git a/senpy/static/js/main.js b/senpy/static/js/main.js index be243a4..b6933ed 100644 --- a/senpy/static/js/main.js +++ b/senpy/static/js/main.js @@ -33,6 +33,10 @@ function get_plugins(response){ plugins = response.plugins; } +function get_datasets(response){ + datasets = response.datasets +} + function group_plugins(){ for (r in plugins){ ptype = plugins[r]['@type']; @@ -77,7 +81,10 @@ function draw_plugins_selection(){ } } html += "" - document.getElementById('plugins').innerHTML = html; + // Two elements with plugin class + // One from the evaluate tab and another one from the analyse tab + document.getElementsByClassName('plugin')[0].innerHTML = html; + document.getElementsByClassName('plugin')[1].innerHTML = html; } function draw_plugins_list(){ @@ -98,15 +105,29 @@ function draw_plugins_list(){ } } +function draw_datasets(){ + html = ""; + repeated_html = ""+datasets[dataset]["@id"]; + html += "
" + } + document.getElementById("datasets").innerHTML = html; +} + $(document).ready(function() { var response = JSON.parse($.ajax({type: "GET", url: "/api/plugins/" , async: false}).responseText); defaultPlugin= JSON.parse($.ajax({type: "GET", url: "/api/plugins/default" , async: false}).responseText); + var response2 = JSON.parse($.ajax({type: "GET", url: "/api/datasets/" , async: false}).responseText); + get_plugins(response); get_default_parameters(); + get_datasets(response2); draw_plugins_list(); draw_plugins_selection(); draw_parameters(); + draw_datasets(); $(window).on('hashchange', hashchanged); hashchanged(); @@ -129,7 +150,7 @@ function draw_default_parameters(){ } function draw_extra_parameters(){ - var plugin = document.getElementById("plugins").options[document.getElementById("plugins").selectedIndex].value; + var plugin = document.getElementsByClassName('plugin')[0].options[document.getElementsByClassName('plugin')[0].selectedIndex].value; get_parameters(); var extra_params = document.getElementById("extra_params"); @@ -240,13 +261,16 @@ function add_param(key, value){ return "&"+key+"="+value; } + function load_JSON(){ url = "/api"; var container = document.getElementById('results'); var rawcontainer = document.getElementById("jsonraw"); rawcontainer.innerHTML = ''; container.innerHTML = ''; - var plugin = document.getElementById("plugins").options[document.getElementById("plugins").selectedIndex].value; + + var plugin = document.getElementsByClassName("plugin")[0].options[document.getElementsByClassName("plugin")[0].selectedIndex].value; + var input = encodeURIComponent(document.getElementById("input").value); url += "?algo="+plugin+"&i="+input @@ -278,3 +302,78 @@ function load_JSON(){ // location.hash = 'raw'; } } + +function get_datasets_from_checkbox(){ + var checks = document.getElementsByClassName("checks-datasets"); + + datasets = ""; + for (var i = 0; i < checks.length; i++){ + if (checks[i].checked){ + datasets += checks[i].value + ","; + } + } + datasets = datasets.slice(0, -1); +} + + +function evaluate_JSON(){ + + url = "/api/evaluate"; + + var container = document.getElementById('results_eval'); + var rawcontainer = document.getElementById('jsonraw_eval'); + var table = document.getElementById("evaluation-table"); + + rawcontainer.innerHTML = ""; + container.innerHTML = ""; + + var plugin = document.getElementsByClassName("plugin")[0].options[document.getElementsByClassName("plugin")[0].selectedIndex].value; + + get_datasets_from_checkbox(); + + url += "?algo="+plugin+"&dataset="+datasets + + var response = $.ajax({type: "GET", url: url , async: false, dataType: 'json'}).responseText; + rawcontainer.innerHTML = replaceURLWithHTMLLinks(response); + + document.getElementById("input_request_eval").innerHTML = ""+url+"" + document.getElementById("evaluate-div").style.display = 'block'; + + try { + response = JSON.parse(response); + var options = { + mode: 'view' + }; + + var metric_html = ""; + metric_html += ""; + + if (!(Array.isArray(response.evaluations))){ + response.evaluations = [response.evaluations] + } + for (var eval in response.evaluations){ + metric_html += ""; + for (var metric in response.evaluations[eval].metrics){ + metric_html += ""; + } + metric_html += ""; + } + table.innerHTML = metric_html; + + var editor = new JSONEditor(container, options, response); + editor.expandAll(); + // $('#results-div a[href="#viewer"]').tab('show'); + $('#evaluate-div a[href="#evaluate-viewer"]').click(); + // location.hash = 'raw'; + + + } + catch(err){ + console.log("Error decoding JSON (got turtle?)"); + $('#evaluate-div a[href="#evaluate-raw"]').click(); + // location.hash = 'raw'; + } + + + +} \ No newline at end of file diff --git a/senpy/templates/index.html b/senpy/templates/index.html index 176673d..bae9e91 100755 --- a/senpy/templates/index.html +++ b/senpy/templates/index.html @@ -32,6 +32,8 @@
@@ -54,6 +56,7 @@ @@ -95,7 +98,7 @@ I cannot believe it!
-
@@ -151,6 +154,53 @@ I cannot believe it! + +
+
+
+
+ + +
+
+ +
+ +
+ + Evaluate Plugin! + + +
+ +
+ +
+ +
+
+

+                  
+
+ +
+
+

+                  
+
+
+
+
+
+ +
+
+
PluginDatasetAccuracyPrecision_macroRecall_macroF1_macroF1_weightedF1_microF1
"+response.evaluations[eval].evaluates+""+response.evaluations[eval].evaluatesOn+""+parseFloat(response.evaluations[eval].metrics[metric].value.toFixed(4))+"