From 52751a5600245af7608441dbb39e99264668ecdb Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 11 Sep 2015 22:35:47 +0000 Subject: Fixed issue causing error if trying to use Heatmap or Correlation Matrix with an empty collection Fixed tables in correlation page and trait page to separate index column and checkbox column --- wqflask/wqflask/templates/correlation_page.html | 17 ++--- wqflask/wqflask/templates/empty_collection.html | 15 +++++ wqflask/wqflask/templates/show_trait.html | 2 + .../wqflask/templates/show_trait_edit_data.html | 9 +-- wqflask/wqflask/views.py | 73 +++++++++++++--------- 5 files changed, 71 insertions(+), 45 deletions(-) create mode 100644 wqflask/wqflask/templates/empty_collection.html diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index 62407555..d44fd2d4 100755 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -26,6 +26,7 @@ + {% for header in target_dataset.header_fields %} {% if header == 'Max LRS' %} @@ -78,10 +79,9 @@ {% for trait in correlation_results %} - +
Max  
LRS ?
{{ loop.index }} - + {{ loop.index }} {% endblock %} diff --git a/wqflask/wqflask/templates/empty_collection.html b/wqflask/wqflask/templates/empty_collection.html new file mode 100644 index 00000000..3f2b3786 --- /dev/null +++ b/wqflask/wqflask/templates/empty_collection.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} +{% block title %}{{ tool }}{% endblock %} +{% block content %} + + {{ header("Error") }} + +
+ +

You must select at least one trait to use the {{ tool }}.

+
+ + + + +{% endblock %} diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html index 0709a82f..55464635 100755 --- a/wqflask/wqflask/templates/show_trait.html +++ b/wqflask/wqflask/templates/show_trait.html @@ -199,6 +199,7 @@ {% if sample_groups[0].se_exists() %} $('#samples_primary, #samples_other').DataTable( { "columns": [ + { "bSortable": false }, { "type": "natural" }, { "type": "natural" }, { "type": "cust-txt" }, @@ -228,6 +229,7 @@ $('#samples_primary, #samples_other').DataTable( { "columns": [ + { "bSortable": false }, { "type": "natural" }, null, { "type": "cust-txt" } diff --git a/wqflask/wqflask/templates/show_trait_edit_data.html b/wqflask/wqflask/templates/show_trait_edit_data.html index ca8e02de..d39df976 100755 --- a/wqflask/wqflask/templates/show_trait_edit_data.html +++ b/wqflask/wqflask/templates/show_trait_edit_data.html @@ -81,6 +81,7 @@ + @@ -98,13 +99,9 @@ {% for sample in sample_type.sample_list %} - - +
Index Sample Value
- {{ loop.index }} - + {{ loop.index }} {{ sample.name }} diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 3cff9a0c..7a8a0f03 100755 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -266,38 +266,43 @@ def heatmap_page(): start_vars = request.form temp_uuid = uuid.uuid4() - version = "v5" - key = "heatmap:{}:".format(version) + json.dumps(start_vars, sort_keys=True) - print("key is:", pf(key)) - with Bench("Loading cache"): - result = Redis.get(key) + traits = [trait.strip() for trait in start_vars['trait_list'].split(',')] + if traits[0] != "": + version = "v5" + key = "heatmap:{}:".format(version) + json.dumps(start_vars, sort_keys=True) + print("key is:", pf(key)) + with Bench("Loading cache"): + result = Redis.get(key) - if result: - print("Cache hit!!!") - with Bench("Loading results"): - result = pickle.loads(result) + if result: + print("Cache hit!!!") + with Bench("Loading results"): + result = pickle.loads(result) - else: - print("Cache miss!!!") + else: + print("Cache miss!!!") - template_vars = heatmap.Heatmap(request.form, temp_uuid) - template_vars.js_data = json.dumps(template_vars.js_data, - default=json_default_handler, - indent=" ") + template_vars = heatmap.Heatmap(request.form, temp_uuid) + template_vars.js_data = json.dumps(template_vars.js_data, + default=json_default_handler, + indent=" ") - result = template_vars.__dict__ - - for item in template_vars.__dict__.keys(): - print(" ---**--- {}: {}".format(type(template_vars.__dict__[item]), item)) - - pickled_result = pickle.dumps(result, pickle.HIGHEST_PROTOCOL) - print("pickled result length:", len(pickled_result)) - Redis.set(key, pickled_result) - Redis.expire(key, 60*60) + result = template_vars.__dict__ + + for item in template_vars.__dict__.keys(): + print(" ---**--- {}: {}".format(type(template_vars.__dict__[item]), item)) - with Bench("Rendering template"): - rendered_template = render_template("heatmap.html", **result) + pickled_result = pickle.dumps(result, pickle.HIGHEST_PROTOCOL) + print("pickled result length:", len(pickled_result)) + Redis.set(key, pickled_result) + Redis.expire(key, 60*60) + with Bench("Rendering template"): + rendered_template = render_template("heatmap.html", **result) + + else: + rendered_template = render_template("empty_collection.html", **{'tool':'Heatmap'}) + return rendered_template @app.route("/mapping_results_container") @@ -470,12 +475,18 @@ def corr_compute_page(): @app.route("/corr_matrix", methods=('POST',)) def corr_matrix_page(): print("In corr_matrix, request.form is:", pf(request.form)) - template_vars = show_corr_matrix.CorrelationMatrix(request.form) - template_vars.js_data = json.dumps(template_vars.js_data, - default=json_default_handler, - indent=" ") + + start_vars = request.form + traits = [trait.strip() for trait in start_vars['trait_list'].split(',')] + if traits[0] != "": + template_vars = show_corr_matrix.CorrelationMatrix(start_vars) + template_vars.js_data = json.dumps(template_vars.js_data, + default=json_default_handler, + indent=" ") - return render_template("correlation_matrix.html", **template_vars.__dict__) + return render_template("correlation_matrix.html", **template_vars.__dict__) + else: + return render_template("empty_collection.html", **{'tool':'Correlation Matrix'}) @app.route("/corr_scatter_plot") def corr_scatter_plot_page(): -- cgit v1.2.3