Skip to content
Snippets Groups Projects
Commit 6fe27b7b authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

First commit of the calculators app

parent e36e352b
Branches
No related tags found
No related merge requests found
from django.contrib import admin
# Register your models here.
from django.db import models
# Create your models here.
{
"_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
}
]
}
/*
* 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
{% 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
{% 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
from django.test import TestCase
# Create your tests here.
#
# 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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment