diff --git a/cydiapomonella/templates/cydiapomonella/index.html b/cydiapomonella/templates/cydiapomonella/index.html index 87fcade23c951b06360caec27d209a8783f38bda..36e4c7a882d0c882b10b0cf648238657158faa5f 100644 --- a/cydiapomonella/templates/cydiapomonella/index.html +++ b/cydiapomonella/templates/cydiapomonella/index.html @@ -58,22 +58,52 @@ var strEndDate = JSON.stringify(dateToday).substring(1,11); //var jsonDailyData = ""; - var jsonHourlyData = ""; + var jsonHourlyData = ""; var jsonMeasurdData = ""; $(function(){ $('#idTxtDateInput').removeClass('hasDatepicker'); }); - /* Date input */ + /* Function works on date picker onClose event */ + function funDtPickerHeatSum() + { + + var varWeatherId = $('#weatherStationId').find(':selected').val(); + if(typeof varWeatherId === "undefined") + { + varWeatherId = '$(#weatherStationId)'; + } + + var startDate = new Date($('#idTxtDateInput').val()); + console.log('date picker start date : '+JSON.stringify(startDate)); + + var strStartDate = JSON.stringify(getAdjustDate(new Date($('#idTxtDateInput').val()), 1 )).substring(1,11); + + var jsonParamUrlDataDaily = { + weatherStationId : varWeatherId, + elementMeasurementTypes : ['TM'], + logInterval : '1d', + startDate : strStartDate, + startTime : '12', + endDate : strEndDate, + endTime : '11', + timeZone : CONST_TIMEZONE + } + + var jsonDailyData = getAjaxDailyData (jsonParamUrlDataDaily); + + } + + /* Date input to get heat sum calculation */ $('#idTxtDateInput').datepicker({ dateFormat: 'yy-mm-dd', showOn: "both", firstDay:1, maxDate : 0, onClose: function( selectedDate ) { - - } + funDtPickerHeatSum(); + } }); /* On change of drop down for weather stations */ @@ -100,10 +130,16 @@ endTime : '11', timeZone : CONST_TIMEZONE } + + jsonHourlyData = getAjaxHourlyData(jsonParamUrlDataHourly); - //setConvertHourlyData(jsonHourlyData); + + $('#idTxtDateInput').datepicker("setDate",dateStartDate); + /*Calling function to calculate and place heatsum value based upon date placed on datepicker*/ + funDtPickerHeatSum(); + }); @@ -118,7 +154,7 @@ /* Convert hourly data to daily data */ function setConvertHourlyData(data) { - var TM_BASE = 10; + //var TM_BASE = 10; var resultConvertData=[]; var strDate01 = ''; @@ -132,11 +168,11 @@ var time23 = ''; var rainFall = 0.0; - var TM_NON_NEGATIVE = 0; + //var TM_NON_NEGATIVE = 0; - var TM_Daily = 0.0; - var TM_SUM = 0.0; - var TM_Calc = 0.0; + //var TM_Daily = 0.0; + //var TM_SUM = 0.0; + //var TM_Calc = 0.0; var hourCount = 0; @@ -201,9 +237,7 @@ if(strDate01.localeCompare(strDate02) !== 0) { - //TM_Daily = TM_SUM / hourCount; - //TM_Calc = TM_Daily - TM_BASE; - //TM_NON_NEGATIVE = (TM_Calc<0) ? 0 : Math.round(TM_Calc); + var decimalPlace = 2; resultConvertData.push({ @@ -214,22 +248,12 @@ 'time22' : time22.toFixed(1), 'time23' : time23.toFixed(1), 'rainFall': rainFall.toFixed(1) //getDecimalPlace(rainFall,2) - /* - 'tmNonNeg' : TM_NON_NEGATIVE, - 'tempval' : tempval, - 'hourCount' : hourCount, - 'tmDaily' : TM_Daily, - 'tmCalc' : TM_Calc - */ + }); strDate01 = JSON.stringify(getStrConvertedDate(data[i].timeMeasured)).substring(1,11); rainFall = 0.0; - //hourCount = 0; - //TM_SUM = 0.0; - //TM_Calc = 0.0; - //TM_Daily = 0.0; - //TM_NON_NEGATIVE = 0; + } @@ -255,6 +279,53 @@ return num.toString().match(/^-?\d+(?:\.\d{0,place})?/)[0]; } + /* Calculate the daily TM value for HeatSum */ + function getHeatSumValue(data) + { + var TM_BASE = 10; + var TM_Daily = 0.0; + var TM_SUM = 0.0; + var TM_Calc = 0.0; + var TM_NON_NEGATIVE = 0; + + console.log('daily data 02 : '+JSON.stringify(data)); + + console.log ('time measured 0 : '+data[0].timeMeasured); + var counter = undefined; + for (var i=0; i<data.length; i++) + { + var strStartDateDtPicker = JSON.stringify(getStrConvertedDate(data[i].timeMeasured)).substring(1,11); + console.log ('strStartDateDtPicker : '+strStartDateDtPicker); + if(strStartDateDtPicker===$('#idTxtDateInput').val()) + { + console.log('value of I : '+i); + counter = 0; + } + if(typeof counter === "undefined") + { + break; + } + else + { + TM_Daily = data[counter].value; + TM_Calc = TM_Daily - TM_BASE; + TM_NON_NEGATIVE = TM_NON_NEGATIVE + ((TM_Calc<0) ? 0 : TM_Calc); + var temp = ((TM_Calc<0) ? 0 : TM_Calc) + console.log('time measured :'+data[counter].timeMeasured+' -- TM_Daily : '+TM_Daily+'-- TM_NON_NEGATIVE : '+temp); + ++counter; + } + + + + + } + console.log('non negative : '+TM_NON_NEGATIVE); + $('#idSpanStartDate').html($('#idTxtDateInput').val()); + $('#idSpanEndDate').html(JSON.stringify(dateYesterday).substring(1,11)); + $('#idDivResultNonNegative').html(Math.round(TM_NON_NEGATIVE)); + } + + /* Populate the data table */ function getWeatherDataTable(weatherData) { @@ -365,6 +436,40 @@ + /* Fetch Daily data through ajax call */ + function getAjaxDailyData(jsonParamUrlDataHourly) + { + var resultData = ""; + + $.ajax({ + url : "https://lmt.nibio.no/services/rest/vips/getdata/forecastfallback", + type : 'GET', + cache : false, + data : jsonParamUrlDataHourly, + //async : false, + success : function (data) { + if($.trim(data)) + { + + resultData = data; + getHeatSumValue(resultData); + console.log('daily data 01 : '+JSON.stringify(resultData)); + } + else{ + //TODO + } + }, + error : function(xhr, status, error) + { + //TODO + } + }); + + return resultData; + + } + + /* Adjust the dates as per radio button click to understand start date and end date*/ function getAdjustDate(date,days) { @@ -387,8 +492,12 @@ {% block content %} +<center> +<div class="alert alert-info" role="alert"> + <h3>Calculate the risk of attack by apple wrap</h3> + </div> +</center> -<h1>Calculate the risk of attack by apple wrap</h1> <div class="container-fluid"> <div class="row "> <div class="col-sm-4"> @@ -468,6 +577,9 @@ <!-- button type="submit" class="btn btn-default">Submit</button --> </form> </div> + <div class="row alert alert-warning"> + Varmesum, med basistemperatur 10, beregnet for Bø klimastasjon for perioden fra og med <span id="idSpanStartDate">-</span> til <span id="idSpanEndDate">--</span> ( 7 dager ) er : <span class="label label-primary" id="idDivResultNonNegative"></span> graddager + </div> </div>