diff --git a/calculators/__init__.py b/calculators/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/calculators/admin.py b/calculators/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/calculators/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/calculators/models.py b/calculators/models.py new file mode 100644 index 0000000000000000000000000000000000000000..71a836239075aa6e6e4ecb700e9c42c95c022d91 --- /dev/null +++ b/calculators/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/calculators/static/calculators/formdefinitions/EILForm.json b/calculators/static/calculators/formdefinitions/EILForm.json new file mode 100644 index 0000000000000000000000000000000000000000..dee2c4878ee6909de54c6dc16a54198e89a58d1a --- /dev/null +++ b/calculators/static/calculators/formdefinitions/EILForm.json @@ -0,0 +1,47 @@ +{ + "_licenseNote": [ + "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/>. " + ], + "_comment" : "Structure of the EILForm and how to validate it", + "fields": [ + { + "name" : "C", + "dataType" : "DOUBLE", + "required" : true + }, + { + "name" : "V", + "dataType" : "DOUBLE", + "required" : true + }, + { + "name" : "Yp", + "dataType" : "DOUBLE", + "required" : true + }, + { + "name" : "K", + "dataType" : "DOUBLE", + "required" : true + }, + { + "name" : "D", + "dataType" : "DOUBLE", + "required" : true + } + ] +} diff --git a/calculators/static/calculators/js/eil.js b/calculators/static/calculators/js/eil.js new file mode 100644 index 0000000000000000000000000000000000000000..d738f277bb7ed776ee03feac3f587f7c38452e3f --- /dev/null +++ b/calculators/static/calculators/js/eil.js @@ -0,0 +1,55 @@ +/* + * 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/>. + * + */ + +/** + * JS for the EIL (Economic Injury Level) calculator + * + * @author Tor-Einar Skog <tor-einar.skog@nibio.no> + */ + +/** + * + * @param C Control cost (purchase & application of pesticide: [monetary unit / area unit] (e.g. NOK/daa) + * @param V market value of crop ([monetary unit / weight unit], e.g. NOK/tonn) + * @param Yp yield potential, maximum yield per production unit [weight unit / area unit], e.g. tonn/daa + * @param K pesticide efficacy, the proportion of pest population killed. Range 0-1 (1=100% killed) + * @param D damage per pest, expressed as a percentage of crop yield loss per pest inidividual(?) + */ +function calculateEIL(C,V,Yp,K,D) +{ + // From Pedigo et al (1986) + return C / (V * Yp * K * D); +} + +function renderResult(formId) +{ + var theForm = document.getElementById(formId); + var resultParameters = " = " + theForm["C"].value + " / (" + theForm["V"].value + " * " + theForm["Yp"].value + " * " + theForm["K"].value + " * " + theForm["D"].value + ")"; + var resultValue = calculateEIL( + theForm["C"].value, + theForm["V"].value, + theForm["Yp"].value, + theForm["K"].value, + theForm["D"].value + ); + + document.getElementById("resultParameters").innerHTML = resultParameters; + document.getElementById("resultValue").innerHTML = resultValue; + +} \ No newline at end of file diff --git a/calculators/templates/calculators/eil.html b/calculators/templates/calculators/eil.html new file mode 100644 index 0000000000000000000000000000000000000000..bb1d2764e350f6e67fec5071f2944721a1410506 --- /dev/null +++ b/calculators/templates/calculators/eil.html @@ -0,0 +1,85 @@ +{% extends "base.html" %} +{% load staticfiles %} +{% 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 "Economic injury level (EIL) calculator" %}{%endblock%} +{% block content %} +<h1>{% trans "Economic injury level (EIL) calculator" %}</h1> +<p>(Forklaring...)</p> +<form role="form" id="{{ form_id }}"> + <div class="row"> + <div class="col-md-6"> + <div class="form-group"> + <label for="C">{% trans "Control cost" %}</label> + <input type="number" name="C" class="form-control" min="0" onblur="validateField(this);"/> + <span class="help-block" id="{{ form_id }}_C_validation"></span> + </div> + <div class="form-group"> + <label for="V">{% trans "Market value" %}</label> + <input type="number" name="V" class="form-control" min="0" onblur="validateField(this);"/> + <span class="help-block" id="{{ form_id }}_V_validation"></span> + </div> + <div class="form-group"> + <label for="Yp">{% trans "Yield potential" %}</label> + <input type="number" name="Yp" class="form-control" min="0" onblur="validateField(this);"/> + <span class="help-block" id="{{ form_id }}_Yp_validation"></span> + </div> + <div class="form-group"> + <button type="button" class="btn btn-default" onclick="if(validateForm(document.getElementById('{{ form_id }}'))){renderResult('{{ form_id }}');}">{% trans "Run model" %}</button> + </div> + </div> + <div class="col-md-6"> + + <div class="form-group"> + <label for="K">{% trans "Insecticide efficacy" %}</label> + <input type="number" name="K" class="form-control" min="0" max="1" onblur="validateField(this);"/> + <span class="help-block" id="{{ form_id }}_K_validation"></span> + </div> + <div class="form-group"> + <label for="D">{% trans "Damage per pest individual" %} (?)</label> + <input type="number" name="D" class="form-control" min="0" onblur="validateField(this);"/> + <span class="help-block" id="{{ form_id }}_D_validation"></span> + </div> + + </div> + </div> + <div class="row"> + <div class="col-md-12"> + <div id="result" style="font-weight: bold;"> + {% trans "Calculated EIL" %} = C / (V * Yp * D * K)<span id="resultParameters"></span>: <span id="resultValue"></span> + </div> + </div> + </div> +</form> + +{% endblock %} +{% block customJS %} +<script type="text/javascript" src="{% url "django.views.i18n.javascript_catalog" %}"></script> +<script type="text/javascript" src="{% static "js/validateForm.js" %}"></script> +<script type="text/javascript" src="{% static "calculators/js/eil.js" %}"></script> +<script type="text/javascript"> +$(document).ready(function() { + loadFormDefinition("{{ form_id }}","/static/calculators/formdefinitions/"); +}); +</script> +{% endblock %} \ No newline at end of file diff --git a/calculators/templates/calculators/index.html b/calculators/templates/calculators/index.html new file mode 100644 index 0000000000000000000000000000000000000000..a544cb7e29e7c86537aad515ae6a88f7eead1087 --- /dev/null +++ b/calculators/templates/calculators/index.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} +{% load staticfiles %} +{% 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 "Calculators" %}{%endblock%} +{% block content %} +<h1>{% trans "Calculators" %}</h1> + + +{% endblock %} \ No newline at end of file diff --git a/calculators/tests.py b/calculators/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/calculators/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/calculators/urls.py b/calculators/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..d1e7b61de50460a0ad10c60c6f8d69b3106ad443 --- /dev/null +++ b/calculators/urls.py @@ -0,0 +1,25 @@ +# +# 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/>. +# +from django.conf.urls import patterns, url +from calculators import views + +urlpatterns = patterns('calculators.views', + # ex: /forecasts/ + url(r'^$', views.index, name='index'), + url(r'eil/', views.eil, name='eil') +) \ No newline at end of file diff --git a/calculators/views.py b/calculators/views.py new file mode 100644 index 0000000000000000000000000000000000000000..bcaeb63e2b53c31c637727f649e0577306c10089 --- /dev/null +++ b/calculators/views.py @@ -0,0 +1,15 @@ +from django.shortcuts import render + +# Create your views here. +def index(request): + + context = { + + } + return render(request, 'calculators/index.html', context) + +def eil(request): + context = { + "form_id" : "EILForm" + } + return render(request, 'calculators/eil.html', context) \ No newline at end of file