internal void setRainfallData(RainfallData raindata) { this.rain = raindata; this.index = 0; }
public ActionResult Index(lineDataTimeSpan model) { string startDate = model.start; if (startDate == null) { startDate = Convert.ToString(DateTime.Now.AddMonths(-1)); } DateTime theStartDate = Convert.ToDateTime(startDate); theStartDate = theStartDate.AddDays(-1); //get the day before the startDate data for daily et calcualting startDate = Convert.ToString(theStartDate); string strYear5 = ""; string strMonth5 = ""; string strDay5 = ""; strYear5 = Convert.ToString(theStartDate.Year); if (theStartDate.Month < 10) { strMonth5 = "0" + Convert.ToString(theStartDate.Month); } else { strMonth5 = Convert.ToString(theStartDate.Month); } if (theStartDate.Day < 10) { strDay5 = "0" + Convert.ToString(theStartDate.Day); } else { strDay5 = Convert.ToString(theStartDate.Day); } startDate = strYear5 + "-" + strMonth5 + "-" + strDay5; string endDate = model.end; if (endDate == null) { endDate = Convert.ToString(DateTime.Now); } DateTime theEndDate = Convert.ToDateTime(endDate); string strYear6 = ""; string strMonth6 = ""; string strDay6 = ""; strYear6 = Convert.ToString(theEndDate.Year); if (theEndDate.Month < 10) { strMonth6 = "0" + Convert.ToString(theEndDate.Month); } else { strMonth6 = Convert.ToString(theEndDate.Month); } if (theEndDate.Day < 10) { strDay6 = "0" + Convert.ToString(theEndDate.Day); } else { strDay6 = Convert.ToString(theEndDate.Day); } endDate = strYear6 + "-" + strMonth6 + "-" + strDay6; TimeSpan timeSpan = theEndDate - theStartDate; int days = timeSpan.Days; days++;//including the day of both startDate and endDate string[] allDate = new string[days]; double[] allData = new double[days]; double[] allRain = new double[days]; double[] originalAllData = new double[days]; double[] allData2 = new double[days - 1]; string[] allDate2 = new string[days - 1]; double[] allRain2 = new double[days - 1]; RainfallData rainfallData = new RainfallData(); etData theEtData = new etData(); for (int i = 0; i < days; i++) { DateTime tempDate2 = theStartDate.AddDays(i); string strYear2 = ""; string strMonth2 = ""; string strDay2 = ""; strYear2 = Convert.ToString(tempDate2.Year); if (tempDate2.Month < 10) { strMonth2 = "0" + Convert.ToString(tempDate2.Month); } else { strMonth2 = Convert.ToString(tempDate2.Month); } if (tempDate2.Day < 10) { strDay2 = "0" + Convert.ToString(tempDate2.Day); } else { strDay2 = Convert.ToString(tempDate2.Day); } string standartDate2 = strYear2 + "-" + strMonth2 + "-" + strDay2; allDate[i] = standartDate2; allData[i] = 0; //DataTable rainfallDataTable = rainfallData.DoSelect("2016-03-02"); //get each day's rain data double theDayRainFall = 0; DataTable rainfallDataTable = rainfallData.DoSelect(standartDate2); if ((rainfallDataTable != null) && (rainfallDataTable.Rows.Count > 0)) { string tempstr = Convert.ToString(rainfallDataTable.Rows[0]["totalRain"]); if (double.TryParse(tempstr, out theDayRainFall)) { theDayRainFall = Math.Round(theDayRainFall, 2); } } allRain[i] = theDayRainFall; //get each day's et data double theDayEt = 0; DataTable etDataTable = theEtData.DoSelect(standartDate2); if ((etDataTable != null) && (etDataTable.Rows.Count > 0)) { string tempstr = Convert.ToString(etDataTable.Rows[0]["etDailyData"]); if (double.TryParse(tempstr, out theDayEt)) { theDayEt = Math.Round(theDayEt, 2); } } allData[i] = theDayEt; } //calculatting final et for (int i = 0; i < days; i++) { originalAllData[i] = allData[i]; } for (int i = 0; i < (days - 1); i++) { allData[0] = 0; allData[i + 1] = allData[i] - originalAllData[i + 1] + allRain[i + 1]; allData2[i] = Math.Round(allData[i + 1], 2); allRain2[i] = Math.Round(allRain[i + 1], 2); allDate2[i] = allDate[i + 1]; } //Geting final et data of each day within the seleted period ////////for (int i = 0; i < (days - 1); i++) ////////{ //////// allData[i + 1] = allData[i] - originalAllData[i + 1] + allRain[i + 1]; //////// allData2[i] = Math.Round(allData[i + 1], 2); //////// allRain2[i] = Math.Round(allRain[i + 1], 2); //////// allDate2[i] = allDate[i + 1]; ////////} //////return the input data for test ViewBag.startDate = startDate; ViewBag.endDate = endDate; ViewBag.test = "This is test__"; //get the latest date D1 from database and check if more sensor data is required to be stored in database int theResult = checkAndStoreSensorData(); //get the time span on which ET data is required by the users //check if the hourly .dat files after D1 exist. If yes, put these data in to database one by one. If no, go to next step. //seleting the raw hourly data into different datatables //NetTot_Avg //SHF_mean_Avg //LE_wpl //Hc TableSelect dataselect = new TableSelect(); //////DataTable dt = dataselect.DoSelect("etc", "[ETC].[dbo]", "recordNum" ////// + ",ts" ////// + ",cast([ts] as date) as theDay" ////// + ",NetTot_Avg" ////// + ",isnull((select NetTot_Avg where NetTot_Avg > 0),0) as NetTot_Avg1" ////// + ",SHF_mean_Avg" ////// + ",LE_wpl" ////// + ",Hc" ////// + ",Hc/isnull((select LE_wpl where LE_wpl <> 0),0.00000001) as br" ////// + ",(LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)) as leadjust1" ////// + ",((LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)))/(28.36*24) as leadjust2" ////// + ",isnull((select (((LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)))/(28.36*24))*-1 where (((LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)))/(28.36*24)) <0),((LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)))/(28.36*24)) as leadjust3", "convert(date,ts)>='" + startDate + "' and convert(date,ts)<='" + endDate + "'", " recordNum"); ////DataTable dt = dataselect.DoSelect("etc", "[ETC].[dbo]", "recordNum" //// + ",ts" //// + ",cast([ts] as date) as theDay" //// + ",NetTot_Avg" //// + ",isnull((select NetTot_Avg where NetTot_Avg > 0),0) as NetTot_Avg1" //// + ",SHF_mean_Avg" //// + ",LE_wpl" //// + ",Hc" //// + ",Hc/isnull((select LE_wpl where LE_wpl <> 0),0.00000001) as br" //// + ",(LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)) as leadjust1" //// + ",((LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)))/(28.36*24) as leadjust2" //// + ",isnull((select (((LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)))/(28.36*24))*-1 where (((LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)))/(28.36*24)) <0),((LE_wpl-SHF_mean_Avg)/(isnull((select (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) where (isnull((select LE_wpl where LE_wpl <> 0),0.00000001)) <> 0),0.00000001)))/(28.36*24)) as leadjust3", "convert(date,ts)>='" + startDate + "' and convert(date,ts)<='" + endDate + "'", " recordNum"); ////if (dt != null) ////{ //// if (dt.Rows.Count > 0) //// { //// ////string[] x = new string[dt.Rows.Count]; //// ////double[] y = new double[dt.Rows.Count]; ////for (int i = 0; i < dt.Rows.Count; i++) ////{ //// x[i] = dt.Rows[i]["theDay"].ToString(); //// y[i] = Convert.ToDouble(dt.Rows[i]["leadjust3"]); ////} ////string tempDay = ""; ////double sumHourlyData = 0; ////if (x.Length > 0) ////{ //// tempDay = x[0]; ////} ////////for (int i = 0; i < dt.Rows.Count; i++) ////////{ //////// if (x[i] == tempDay) //////// { //////// sumHourlyData = sumHourlyData + y[i]; //////// tempDay = x[i]; //////// } //////// else //////// { //////// DateTime tempDate1 = Convert.ToDateTime(tempDay); //////// string strYear = ""; //////// string strMonth = ""; //////// string strDay = ""; //////// strYear = Convert.ToString(tempDate1.Year); //////// if (tempDate1.Month < 10) //////// { //////// strMonth = "0" + Convert.ToString(tempDate1.Month); //////// } //////// else //////// { //////// strMonth = Convert.ToString(tempDate1.Month); //////// } //////// if (tempDate1.Day < 10) //////// { //////// strDay = "0" + Convert.ToString(tempDate1.Day); //////// } //////// else //////// { //////// strDay = Convert.ToString(tempDate1.Day); //////// } //////// string standartDate1 = strYear + "-" + strMonth + "-" + strDay; //////// for (int j = 0; j < days; j++) //////// { //////// string standartDate2 = allDate[j]; //////// if (standartDate1 == standartDate2) //////// { //////// allData[j] = sumHourlyData; //////// sumHourlyData = 0; //////// } //////// } //////// tempDay = x[i]; //////// sumHourlyData = sumHourlyData + y[i]; //////// } ////////} // for the day of endDate data ////if (x.Length > 0) ////{ //// DateTime tempDate8 = Convert.ToDateTime(tempDay); //// string strYear8 = ""; //// string strMonth8 = ""; //// string strDay8 = ""; //// strYear8 = Convert.ToString(tempDate8.Year); //// if (tempDate8.Month < 10) //// { //// strMonth8 = "0" + Convert.ToString(tempDate8.Month); //// } //// else //// { //// strMonth8 = Convert.ToString(tempDate8.Month); //// } //// if (tempDate8.Day < 10) //// { //// strDay8 = "0" + Convert.ToString(tempDate8.Day); //// } //// else //// { //// strDay8 = Convert.ToString(tempDate8.Day); //// } //// string standartDate8 = strYear8 + "-" + strMonth8 + "-" + strDay8; //// for (int j = 0; j < days; j++) //// { //// string standartDate2 = allDate[j]; //// if (standartDate8 == standartDate2) //// { //// allData[j] = sumHourlyData; //// sumHourlyData = 0; //// } //// } ////} //ETecv (final et) //rainfall data is just for testing //////for (int i = 0; i < days; i++) //////{ ////// originalAllData[i] = allData[i]; ////// allRain[i] = GetRandomNumber(0, 10.34); //////} //////////Geting final et data of each day within the seleted period ////////for (int i = 0; i < (days - 1); i++) ////////{ //////// allData[i + 1] = allData[i] - originalAllData[i + 1] + allRain[i + 1]; //////// allData2[i] = Math.Round(allData[i + 1], 2); //////// allRain2[i] = Math.Round(allRain[i + 1], 2); //////// allDate2[i] = allDate[i + 1]; ////////} //// } ////} //Highcharts //For rainfall data Series rainfall = new Series(); object[] objRainfall = new object[days - 1]; for (int i = 0; i < (days - 1); i++) { objRainfall[i] = allRain2[i]; } rainfall.Data = new Data(objRainfall); //for et data Series et = new Series(); object[] objEt = new Object[days - 1]; for (int i = 0; i < (days - 1); i++) { objEt[i] = allData2[i]; } et.Data = new Data(objEt); rainfall.Name = "Rainfall"; rainfall.Type = ChartTypes.Column; et.Name = "ET"; et.Type = ChartTypes.Line; Series[] theSeries = new Series[] { rainfall, et }; Highcharts theChart = new Highcharts("ET") .SetTitle(new Title { Text = "ET and Rainfall Data Analysis" }) .SetSubtitle(new Subtitle { Text = "ET and Rainfall Data" } ) .SetXAxis(new XAxis { Categories = allDate2 } ).SetSeries(theSeries); ViewBag.theChartModel = theChart; //get hourly data of et and rainfall within the same periond //get hourly data of et and rainfall within the same periond string dateTime1 = startDate + " 00:00:00"; string dateTime2 = endDate + " 23:00:00"; etAndRainfallHourlyData theEtRainfallHourlydata = new etAndRainfallHourlyData(); DataTable dt = theEtRainfallHourlydata.DoSelect(dateTime1, dateTime2); ViewData["hourlyData"] = dt; //get the period data between start date and end date to display //string dateTime1 = theYear + "-" + theMonth + "-" + theDay + " 00:00:00"; //string dateTime2 = theYear + "-" + theMonth + "-" + theDay + " 23:00:00"; //dt = dataselect.DoSelect("rainfall", "dbo", "ts,rainfall", " ts>='" + dateTime1 + "' and ts<='" + dateTime2 + "'", "recordNum"); //ViewData["oneDayData"] = dt; //calculating daily data and put them into ////Create Series 1 //var series1 = new Series(); //series1.Name = "Area Series: ET "; //Point[] series1Points = // { // new Point() {X = 0.0, Y = 0.0}, // new Point() {X = 10.0, Y = 0.0}, // new Point() {X = 10.0, Y = 10.0}, // new Point() {X = 0.0, Y = 10.0} // }; //series1.Data = new Data(series1Points); ////Create Series 2 //var series2 = new Series(); //series2.Name = "Area Series: Rainfall"; //Point[] series2Points = // { // new Point() {X = 5.0, Y = 5.0}, // new Point() {X = 15.0, Y =5.0}, // new Point() {X = 15.0, Y = 15.0}, // new Point() {X = 5.0, Y = 15.0} // }; //series2.Data = new Data(series2Points); ////Create List of Series and Add both series to the collection //var chartSeries = new List<Series>(); //chartSeries.Add(series1); //chartSeries.Add(series2); ////Create chart Model //var chart1 = new Highcharts("Chart1"); //chart1 // .InitChart(new Chart() { DefaultSeriesType = ChartTypes.Area }) // .SetTitle(new Title() { Text = "ET and Rainfall data" }) // .SetSeries(chartSeries.ToArray()); ////pass Chart1Model using ViewBag //ViewBag.Chart1Model = chart1; return(View()); }