diff --git a/cerealblotchmodels/templates/cerealblotchmodels/wheatleafblotchform.html b/cerealblotchmodels/templates/cerealblotchmodels/wheatleafblotchform.html deleted file mode 100755 index dd9c8e9af4d30df2582301fc4771cb1c0fd5d407..0000000000000000000000000000000000000000 --- a/cerealblotchmodels/templates/cerealblotchmodels/wheatleafblotchform.html +++ /dev/null @@ -1,454 +0,0 @@ -{% extends "base_with_date_picker.html" %} -{% load static %} -{% comment %} - -# -# Copyright (c) 2015 NIBIO <http://www.nibio.no/>. -# -# This file is part of VIPSWeb. -# VIPSWeb is free software: you can redistribute it and/or modify -# it under the terms of the NIBIO Open Source License as published by -# NIBIO, either version 1 of the License, or (at your option) any -# later version. -# -# VIPSWeb is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# NIBIO Open Source License for more details. -# -# You should have received a copy of the NIBIO Open Source License -# along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>. -# - -{% endcomment %} -{% load i18n %} -{% block title %}{% trans "Wheat leaf blotch" %}{% endblock %} -{% block customCSS %} -<!--[if lte IE 9]> - <style type="text/css">#oldIEWarning{display: block !important;}</style> -<![endif]--> - -{% endblock %} -{% block content %} -<div class="singleBlockContainer"> - <h1>{% trans "Wheat leaf blotch" %}</h1> - <form role="form" id="{{ form_id }}"> - <input type="hidden" name="wheatType" id="wheatType" value="-1"/> - <div class="row"> - <div class="col-md-12"> - <h2>{% trans "Background data for the wheat leaf blotch model" %}</h2> - </div> - </div> - <div class="row"> - <div class="col-md-6"> - <input type="hidden" name="timeZone" value="Europe/Oslo"/> - <div class="form-group"> - <label for="cropStadium">{% trans "Growth stage" %}</label> - <input type="number" name="cropStadium" class="form-control" onblur="validateCropStadium(this.value);"/> - <span class="help-block" id="{{ form_id }}_cropStadium_validation"></span> - </div> - <div class="form-group"> - <label for="weatherStationId">{% trans "Weather station" %}</label> - <select name="weatherStationId" id="weatherStationId" class="form-control" onblur="validateField(this);"> - </select> - <span class="help-block" id="{{ form_id }}_weatherStationId_validation"></span> - </div> - <div class="form-group"> - <label for="sowingDate">{% trans "Sowing date" %}</label> - <input type="date" name="sowingDate" class="form-control" max="" onblur="validateField(this);"/> - <span class="help-block" id="{{ form_id }}_sowingDate_validation"></span> - </div> - <div class="form-group"> - <label for="cropOrganismId">{% trans "Wheat variety" %}</label> - <select name="cropOrganismId" id="cropOrganismId" class="form-control" onblur="validateField(this);"> - </select> - <span class="help-block" id="{{ form_id }}_cropOrganismId_validation"></span> - </div> - <div class="form-group"> - <input type="checkbox" name="sameCropAsLastSeason"/> - <label for="sameCropAsLastSeason">{% trans "Previous crop was wheat" %}</label><br/> - <span class="help-block" id="{{ form_id }}_sameCropAsLastSeason_validation"></span> - </div> - <div class="form-group"> - <input type="checkbox" name="plowed"/> - <label for="plowed"><span>{% trans "Plowed" %}</span></label><br/> - <span class="help-block" id="{{ form_id }}_plowed_validation"></span> - </div> - <div class="form-group"> - <label for="observationDate">{% trans "Observation date" %}</label> - <input type="date" name="observationDate" class="form-control"/> - <span class="help-block" id="{{ form_id }}_observationDate_validation"></span> - </div> - <div class="form-group"> - <label for ="observationValue">{% trans "% Infected leaves" %}</label> - <span>(Tell opp antall blad med bladflekksjukdommer på de 4 øverste fullt utviklede blad på hver av 25 planter (4 * 25 = til sammen 100 blader.)</span> - <input type="number" name="observationValue" class="form-control" min="0" max="100"/> - <span class="help-block" id="{{ form_id }}_observationValue_validation"></span> - </div> - </div> - <div class="col-md-6 form-group"> - - <fieldset> - <legend>{% trans "Spraying" %}</legend> - <div class="form-group"> - <label for="sprayingDate">{% trans "Spraying date" %}</label> - <input type="date" name="sprayingDate" class="form-control"/> - <span class="help-block" id="{{ form_id }}_sprayingDate_validation"></span> - </div> - <div class="form-group"> - <label for="preparationId1">{% trans "Preparation 1" %}</label> - <select name="preparationId1" id="preparationId1" class="form-control"> - </select> - <span class="help-block" id="{{ form_id }}_preparationId1_validation"></span> - </div> - <div class="form-group"> - <label for="preparationDose1">{% trans "Preparation dose" %} (ml/daa)</label> - <input type="number" name="preparationDose1" class="form-control"/> - <span class="help-block" id="{{ form_id }}_preparationDose1_validation"></span> - </div> - <div class="form-group"> - <label for="preparationId2">{% trans "Preparation 2" %}</label> - <select name="preparationId2" id="preparationId2" class="form-control"> - </select> - <span class="help-block" id="{{ form_id }}_preparationId2_validation"></span> - </div> - <div class="form-group"> - <label for="preparationDose2">{% trans "Preparation dose" %} (ml/daa)</label> - <input type="number" name="preparationDose2" class="form-control"/> - <span class="help-block" id="{{ form_id }}_preparationDose2_validation"></span> - </div> - <div class="form-group"> - <label for="preparationId3">{% trans "Preparation 3" %}</label> - <select name="preparationId3" id="preparationId3" class="form-control"> - </select> - <span class="help-block" id="{{ form_id }}_preparationId3_validation"></span> - </div> - <div class="form-group"> - <label for="preparationDose3">{% trans "Preparation dose" %} (ml/daa)</label> - <input type="number" name="preparationDose3" class="form-control"/> - <span class="help-block" id="{{ form_id }}_preparationDose3_validation"></span> - </div> - </fieldset> - </div> - </div> - <div class="row"> - <div class="col-md-6 form-group"> - <button type="button" class="btn btn-primary" onclick="if(validateForm(document.getElementById('{{ form_id }}')) & validateFormExtra()){runModel();}">{% trans "Run model" %}</button> - </div> - </div> - - </form> - <div class="row" id="runningModelMessage" style="display:none"> - <div class="col-md-12"> - <div class="alert alert-info" role="alert">{% trans "Model is running, please wait" %}</div> - </div> - </div> - <div class="row" id="errorMessageContainer" style="display:none"> - <div class="col-md-12"> - <div class="alert alert-danger" role="alert" id="errorMessage"></div> - </div> - </div> - - <div id="results" style="display:none;"> - <div class="alert alert-info" role="info" id="scrollHelp" style="display:none;"> - {% trans "Scroll past chart by swiping the dotted line on the right" %} - </div> - <div id="chartContainer" style="width: 100%; height:400px;"></div> - <div class="table-responsive"> - <table id="resultsTable" class="table table-striped"></table> - </div> - </div> -</div> -{% endblock %} -{% block customJS %} -<script type="text/javascript" src="{% url "javascript-catalog" %}"></script> -<script type="text/javascript" src="{% url "views.settings_js" %}"></script> -<script type="text/javascript" src="{% static "js/3rdparty/moment.min.js" %}"></script> -<script type="text/javascript" src="{% static "js/3rdparty/highcharts.js" %}"></script> -<script type="text/javascript" src="{% static "js/util.js" %}"></script> -<script type="text/javascript" src="{% static "js/validateForm.js" %}"></script> -<script type="text/javascript" src="{% static "organisms/organismsUtil.js" %}"></script> -<script type="text/javascript" src="{% static "forecasts/js/forecasts.js" %}"></script> -<script type="text/javascript"> - - function validateFormExtra() - { - var theForm = document.getElementById("{{ form_id }}"); - // Observation: Either no fields or all fields must be set - if(theForm["observationDate"].value.trim() == "" ^ theForm["observationValue"].value.trim() == "") - { - alert("{% trans "Missing observation information" %}"); - return false; - } - // Spraying: Either no fields or all fields must be set - var truthies = (theForm["sprayingDate"].value.trim() == "" ? 1 : 0) - + (theForm["preparationId1"].options[theForm["preparationId1"].selectedIndex].value == "-1" ? 1 : 0) - + (theForm["preparationDose1"].value.trim() == "" ? 1 : 0); - if(truthies != 0 && truthies != 3) - { - alert("{% trans "Missing spraying information" %}"); - return false; - } - // Optinally, spraying 2 is also completed - truthies = (theForm["preparationId2"].options[theForm["preparationId2"].selectedIndex].value == "-1" ? 1 : 0) - + (theForm["preparationDose2"].value.trim() == "" ? 1 : 0) - if(truthies != 0 && truthies != 2) - { - alert("{% trans "Missing spraying information on second preparation" %}"); - return false; - } - return true; - } - - - function validateCropStadium(cropStadium) - { - if(parseInt(cropStadium) < 31) - { - alert("{% trans "Too early to calculate risk" %}"); - } - - } - - - var VIPSOrganizationId = {{vips_organization_id}}; - function runModel() - { - document.getElementById("results").style.display="none"; - document.getElementById("errorMessageContainer").style.display="none"; - document.getElementById("runningModelMessage").style.display="block"; - // Setting the wheatType - var cropId = document.getElementById("cropOrganismId").options[document.getElementById("cropOrganismId").selectedIndex].value; - var currentType = null; - for(var i in allWheatVarieties) - { - var crop = allWheatVarieties[i]; - var wheatType = getOrganismLocalNameWithFallback(crop.extraProperties.type,"nb","nb"); - console.info(wheatType); - if(currentType == null || currentType != wheatType) - { - currentType = wheatType; - } - if(crop.organismId == cropId) - { - document.getElementById("wheatType").value = currentType == "Vårhvete" ? 1 : 2; - break; - } - } - // TODO: Validate form - // - var formStr = $("#{{ form_id }}").serialize(); - var request = $.ajax({ - type:"GET", - url: settings.vipslogicProtocol + "://" + settings.vipslogicServerName + "/rest/wheatleafblotchmodel/runmodel/" + VIPSOrganizationId + "?" + formStr, - statusCode:{ - 200: renderResults, - 400: handleAjaxError, - 401: handleAjaxError, - 404: handleAjaxError, - 500: handleAjaxError - } - }); - //console.log(formStr); - } - - var paramDict = { - "WEATHER.TMD": "{% trans "Temperature, daily mean" %}", - "WLEAFBLTCH.THRESHOLD_SUM" : "{% trans "Threshold" %}", - "WLEAFBLTCH.DISEASE_SUM" : "{% trans "Disease" %}", - }; - - var renderResults = function(data,textStatus, jqXHR) - { - data.sort(compareForecastResults).reverse(); - // First attempt: A table! - var headingLine = "<tr><td style=\"font-weight: bold;\">{% trans "Time" %}</td>"; - if(data.length > 0) - { - var allKeys = JSON.parse(data[0]["keys"]); - for(var i in allKeys) - { - var aKey = allKeys[i]; - console.info(aKey); - headingLine +="<td style=\"font-weight: bold;\">" + paramDict[aKey] + "</td>"; - } - headingLine +="<td style=\"font-weight: bold;\">{% trans "Warning status" %}</td>"; - headingLine += "</tr>"; - - var table = ["<table border=\"1\">",headingLine]; - for(var i in data) - { - //console.info(data[i]); - var aResult = data[i]; - var allValues = JSON.parse(aResult["allValues"]); - if(aResult["validTimeStart"] == null) - { - continue; - } - var resultLine = "<tr><td>" + moment(aResult["validTimeStart"]).format() + "</td>"; - for(var i in allKeys) - { - var value = allValues[allKeys[i]]; - console.info(value); - if(value != null && $.isNumeric(value)) - { - value = parseFloat(value).toFixed(2); - } - resultLine +="<td>" + value + "</td>"; - } - resultLine +="<td style=\"background-color:"; - var st = aResult["warningStatus"]; - resultLine += st===0 ? "gray" : st===1 ? "blue" : st===2 ? "green" : st===3 ? "yellow" : "red"; - resultLine +=";\">" + st + "</td>"; - resultLine += "</tr>"; - table.push(resultLine); - } - table.push("</table>"); - document.getElementById("resultsTable").innerHTML=table.join(""); - - } - else - { - document.getElementById("resultsTable").innerHTML="<h2>{% trans "No data returned" %}</h2>"; - } - document.getElementById("runningModelMessage").style.display="none"; - document.getElementById("errorMessageContainer").style.display="none"; - document.getElementById("results").style.display="block"; - // Then: The chart - // We must sort data ascending again - data.reverse(); - var warningStatusPlotBandData = getWarningStatusPlotBandData(data); - //console.log(warningStatusPlotBandData); - var data = getHighChartsSeries( - data, - [ - {"color": "#6600FF", "opposite": false, "abbr": " ", "title": "{% trans "Disease value" %}"} - ], - [ - {key: "WLEAFBLTCH.THRESHOLD_SUM", type: "spline", color: "orange", name: "{% trans "Threshold" %}", yAxis: 0}, - {key: "WLEAFBLTCH.DISEASE_SUM", type: "spline", color: "black", name: "{% trans "Disease" %}", yAxis: 0} - ] - ); - renderForecastChart("chartContainer", "{% trans "Wheat leaf blotch development" %}", warningStatusPlotBandData, data); - }; - - - function initWeatherStations(){ - // Fetching information asynchronously from server - var request = $.ajax({ - type:"GET", - url: settings.vipslogicProtocol + "://" + settings.vipslogicServerName + "/rest/poi/organization/" + VIPSOrganizationId, - statusCode:{ - 200: function(data,textStatus, jqXHR){ - // Building result HTML - var wsHTML=["<option value=\"-1\">-- {% trans "Select weather station" %} --</option>"]; - data.sort(compareWeatherStations); - for(var i in data) - { - var ws = data[i]; - wsHTML.push("<option value=\"" + ws["pointOfInterestId"] + "\">" + ws["name"] + "</option>"); - } - document.getElementById("weatherStationId").innerHTML = wsHTML.join(""); - }, - 400: handleAjaxError, - 401: handleAjaxError, - 404: handleAjaxError, - 500: handleAjaxError - } - }); - } - - - var allWheatVarieties = null; - - function initCrops() - { - // Fetching information asynchronously from server - var request = $.ajax({ - type:"GET", - url: settings.vipslogicProtocol + "://" + settings.vipslogicServerName + "/rest/wheatleafblotchmodel/wheatvarieties/" + VIPSOrganizationId, - statusCode:{ - 200: function(data,textStatus, jqXHR){ - // Building result HTML - var cropHTML=["<option value=\"-1\">-- {% trans "Select crop" %} --</option>"]; - data.sort(function(a,b){ - var syntheticNameA = getOrganismLocalNameWithFallback(a.extraProperties.type,settings.currentLanguage,settings.defaultLanguage) + "_" + getOrganismLocalNameWithFallback(a,settings.currentLanguage,settings.defaultLanguage); - var syntheticNameB = getOrganismLocalNameWithFallback(b.extraProperties.type,settings.currentLanguage,settings.defaultLanguage) + "_" + getOrganismLocalNameWithFallback(b,settings.currentLanguage,settings.defaultLanguage); - return syntheticNameA.localeCompare(syntheticNameB); - }); - currentType = null; - allWheatVarieties = data; - for(var i in data) - { - var crop = data[i]; - var wheatType = getOrganismLocalNameWithFallback(crop.extraProperties.type,settings.currentLanguage,settings.defaultLanguage); - if(currentType == null || currentType != wheatType) - { - currentType = wheatType; - cropHTML.push("<option value=\"-1\">-- " + wheatType + " --</option>"); - } - - //console.log(ws); - cropHTML.push("<option value=\"" + crop["organismId"] + "\">" + getOrganismLocalNameWithFallback(crop,settings.currentLanguage,settings.defaultLanguage) + "</option>"); - } - document.getElementById("cropOrganismId").innerHTML = cropHTML.join(""); - }, - 400: handleAjaxError, - 401: handleAjaxError, - 404: handleAjaxError, - 500: handleAjaxError - } - }); - } - - function initPreparations() - { - // Fetching information asynchronously from server - var request = $.ajax({ - type:"GET", - url: settings.vipslogicProtocol + "://" + settings.vipslogicServerName + "/rest/wheatleafblotchmodel/preparations/" + VIPSOrganizationId, - statusCode:{ - 200: function(data,textStatus, jqXHR){ - // Building result HTML - var preparationHTML=["<option value=\"-1\">-- {% trans "Select preparation" %} --</option>"]; - - data.sort(comparePreparations); - for(var i in data) - { - var preparation = data[i]; - //console.log(ws); - preparationHTML.push("<option value=\"" + preparation["preparationId"] + "\">" + preparation["preparationName"] + "</option>"); - } - document.getElementById("preparationId1").innerHTML = preparationHTML.join(""); - document.getElementById("preparationId2").innerHTML = preparationHTML.join(""); - document.getElementById("preparationId3").innerHTML = preparationHTML.join(""); - }, - 400: handleAjaxError, - 401: handleAjaxError, - 404: handleAjaxError, - 500: handleAjaxError - } - }); - } - - // Error handling when collecting forecast information from server fails - var handleAjaxError = function(jqXHR,textStatus,errorThrown){ - var message = jqXHR.responseJSON !== undefined ? jqXHR.responseJSON.message : jqXHR.responseText; - document.getElementById("runningModelMessage").style.display="none"; - document.getElementById("errorMessage").innerHTML = "<h1>Error</h1><pre>" + message + "</pre>"; - document.getElementById("errorMessageContainer").style.display="block"; - }; - - $(document).ready(function() { - if(settings.userIsIE) - { - alert("{% trans "WARNING: We suspect you are using Internet Explorer to view this site. VIPS is not designed to work with Internet Explorer, you may experience errors and missing features. Please use a different browser, like Microsoft Edge or Google Chrome." %}"); - } - initWeatherStations(); - initCrops(); - initPreparations(); - // Init form validation - loadFormDefinition("{{ form_id }}","/static/cerealblotchmodels/formdefinitions/"); - }); -</script> -{% endblock %} \ No newline at end of file diff --git a/cerealblotchmodels/urls.py b/cerealblotchmodels/urls.py index 8a6bd76d63cdb53ffa12ea6a47d1146419095def..375b0ccd0435ca8014d7f834ae6be8f8bcda0a25 100755 --- a/cerealblotchmodels/urls.py +++ b/cerealblotchmodels/urls.py @@ -24,6 +24,5 @@ urlpatterns = [ # ex: /forecasts/ url(r'^$', views.index, name='index'), url(r'barleynetblotch/', views.barleynetblotchform, name='barleynetblotchform'), - url(r'wheatleafblotch/', views.wheatleafblotchform, name='wheatleafblotchform'), url(r'septoriahumidity/', views.septoriahumidityform, name='septoriahumidityform') ] \ No newline at end of file diff --git a/cerealblotchmodels/views.py b/cerealblotchmodels/views.py index c5617766bb24485b1e69ac067ad0caa6681f6d5f..b968b1012f836adde8f57af346e98f5acc4c54f8 100755 --- a/cerealblotchmodels/views.py +++ b/cerealblotchmodels/views.py @@ -31,24 +31,6 @@ def barleynetblotchform(request): } return render(request, 'cerealblotchmodels/barleynetblotchform.html', context) -def wheatleafblotchform(request): - - # We must calculate the maximum sowing date, which is 14 days before - # system date - #max_sowing_date = datetime.now() + relativedelta(months = settings.SYSTEM_TIME_OFFSET_MONTHS) - relativedelta(days = 14) - vips_organization_id = settings.VIPS_ORGANIZATION_ID - if request.GET.get("organizationId") != None: - vips_organization_id = request.GET.get("organizationId") - - wheat_type = request.GET.get("wheat_type", "spring") - context = { - "vips_organization_id": vips_organization_id, - "form_id" : "wheatLeafBlotchForm", - "wheat_type" : wheat_type - #"max_sowing_date" : max_sowing_date - } - return render(request, 'cerealblotchmodels/wheatleafblotchform.html', context) - def septoriahumidityform(request): model = Model.get_model("SEPTORIAHU") context = {