public DataTable GetHealthMointorWeather() { Serie serie = new Serie("", "", false, null, ""); List<Serie> lst = new List<Serie>(); lst.Add(new Serie("PrecipAmount_mm", "", false, null, "")); lst.Add(new Serie("RelHumidity", "", false, null, "")); lst.Add(new Serie("WindSpeedMax_ms", "", false, null, "")); lst.Add(new Serie("WindSpeed_ms", "", false, null, "")); lst.Add(new Serie("TempAir_C", "", false, null, "")); enumDataSource source = enumDataSource.glbStnFcst; enumTemporalAggregation tmpAggregation = enumTemporalAggregation.Hourly; fReq = new FeatureRequest(47.55, 7.583, 316, 250, 100); startDate = DateTime.Now; endDate = DateTime.Now.AddDays(1); wReq = new WeatherDataRequest(source, false, fReq, startDate, endDate, tmpAggregation, lst); wRes = wData.GetWeatherData(wReq); return wRes.WeatherData; }
public DataTable GetSeriesData(DataTable series, string aggregation, string dataSource, int start, int end, int startHours, int endHours) { //objLocInfo = LocationInfo.getLocationInfoObj; //objDataPoint = objLocInfo.DataPointInfo; populateObject(); Serie serie = new Serie("", "", false, null, ""); List<Serie> lst = new List<Serie>(); enumDataSource source; switch (dataSource.ToUpper()) { case "GLBSTNFCST": source = enumDataSource.glbStnFcst; break; case "GLB25ECMWF": source = enumDataSource.glb25ECMWF; break; case "GLB25OBS": source = enumDataSource.glb25Obs; break; case "GLB25OBSEXT": source = enumDataSource.glbStnObsExt; break; case "GLB25OBSSYN": source = enumDataSource.glbStnObsSyn; break; default: source = enumDataSource.glbStnFcst; break; } enumTemporalAggregation tmpAggregation; switch (aggregation.ToLower()) { case "hourly": tmpAggregation = enumTemporalAggregation.Hourly; break; case "daily": tmpAggregation = enumTemporalAggregation.Daily; break; case "decade": tmpAggregation = enumTemporalAggregation.Decade; break; case "8hourly": tmpAggregation = enumTemporalAggregation.EightHourly; break; case "12hourly": tmpAggregation = enumTemporalAggregation.TwelveHourly; break; case "weekly": tmpAggregation = enumTemporalAggregation.Weekly; break; case "monthly": tmpAggregation = enumTemporalAggregation.Monthly; break; default: tmpAggregation = enumTemporalAggregation.Hourly; break; } foreach (DataRow dr in series.Rows) { if (tmpAggregation == enumTemporalAggregation.Daily || tmpAggregation == enumTemporalAggregation.Hourly) lst.Add( new Serie( dr["Name"].ToString() , "" , false , null , "")); else lst.Add( new Serie( dr["Name"].ToString() , "" , false , (enumAggregationFunction)Enum.Parse(typeof(enumAggregationFunction), dr["aggregationfunction"].ToString(), true) , "")); } startDate = current.AddDays(start); endDate = current.AddDays(end); if (startDate > endDate) { DateTime tmp = startDate; startDate = endDate; endDate = tmp; } startDate = startDate.AddHours(startHours); endDate = endDate.AddHours(endHours); fReq = new FeatureRequest(objDataPoint.stationLatitude, objDataPoint.stationLongitude, objDataPoint.altitude, objDataPoint.NearbyPointSettings.MaxAllowedAltitude, objDataPoint.NearbyPointSettings.MaxAllowedDistance); wReq = new WeatherDataRequest(source, false, fReq, startDate, endDate, tmpAggregation, lst); wRes = wData.GetWeatherData(wReq); return wRes.WeatherData; }
DataTable getData(DataTable series, string aggregation, string dataSource, int start, int end) { Serie serie = new Serie("", "", false, null, ""); List<Serie> lst = new List<Serie>(); enumDataSource source; switch (dataSource.ToUpper()) { case "GLBSTNFCST": source = enumDataSource.glbStnFcst; break; case "GLB25ECMWF": source = enumDataSource.glb25ECMWF; break; case "GLB25OBS": source = enumDataSource.glb25Obs; break; case "GLB25OBSEXT": source = enumDataSource.glbStnObsExt; break; case "GLB25OBSSYN": source = enumDataSource.glbStnObsSyn; break; default: source = enumDataSource.glbStnFcst; break; } enumTemporalAggregation tmpAggregation; switch (aggregation.ToLower()) { case "hourly": tmpAggregation = enumTemporalAggregation.Hourly; step = 1; break; case "daily": tmpAggregation = enumTemporalAggregation.Daily; step = 24; break; case "8hourly": tmpAggregation = enumTemporalAggregation.EightHourly; step = 8; break; case "12hourly": tmpAggregation = enumTemporalAggregation.TwelveHourly; step = 12; break; default: tmpAggregation = enumTemporalAggregation.Hourly; break; } tmpAggregation = enumTemporalAggregation.Hourly; foreach (DataRow dr in series.Rows) { if (tmpAggregation == enumTemporalAggregation.Daily || tmpAggregation == enumTemporalAggregation.Hourly) lst.Add( new Serie( dr["Name"].ToString() , "" , false , null , "")); else lst.Add( new Serie( dr["Name"].ToString() , "" , false , (enumAggregationFunction)Enum.Parse(typeof(enumAggregationFunction), dr["aggregationfunction"].ToString(), true) , "")); } startDate = current.AddDays(start); //endDate = current.AddDays(end > 0 ? end - 1 : end + 1); endDate = current.AddDays(end); if (startDate > endDate) { DateTime tmp = startDate; startDate = endDate; endDate = tmp; } fReq = new FeatureRequest(objDatapoint.stationLatitude, objDatapoint.stationLongitude, objDatapoint.altitude, objDatapoint.NearbyPointSettings.MaxAllowedAltitude, objDatapoint.NearbyPointSettings.MaxAllowedDistance); wReq = new WeatherDataRequest(source, false, fReq, startDate, endDate, tmpAggregation, lst); wRes = wData.GetWeatherData(wReq); return wRes.WeatherData; }
public WeatherDataResponse GetWeatherData(WeatherDataRequest weatherDatarequest, bool IsAgrinfo = false, int stationId = 0) { try { string str = ""; switch (weatherDatarequest.temporalAggregation.ToString().ToLower()) { case "eighthourly": str = "8hourly"; break; case "twelvehourly": str = "12hourly"; break; default: str = weatherDatarequest.temporalAggregation.ToString(); break; } Database dbGrows = new SqlDatabase(ConfigurationManager.ConnectionStrings["P_Grows"].ToString()); DbCommand dbCommand = dbGrows.GetStoredProcCommand("Agriweb_Get_WeatherData"); dbCommand.CommandTimeout = 120; dbGrows.AddInParameter(dbCommand, "latitude", DbType.Decimal, weatherDatarequest.FeatureRequest.Latitude); dbGrows.AddInParameter(dbCommand, "longitude", DbType.Decimal, weatherDatarequest.FeatureRequest.Longitude); dbGrows.AddInParameter(dbCommand, "altitude", DbType.Int32, weatherDatarequest.FeatureRequest.Altitude); if (weatherDatarequest.FeatureRequest.MaxDistanceDiff == 0d) dbGrows.AddInParameter(dbCommand, "maxDistanceDiff", DbType.Int32, DBNull.Value); else dbGrows.AddInParameter(dbCommand, "maxDistanceDiff", DbType.Int32, weatherDatarequest.FeatureRequest.MaxDistanceDiff); if (weatherDatarequest.FeatureRequest.MaxAltitudeDiff == 0d) dbGrows.AddInParameter(dbCommand, "maxAltitudeDiff", DbType.String, DBNull.Value); else dbGrows.AddInParameter(dbCommand, "maxAltitudeDiff", DbType.String, weatherDatarequest.FeatureRequest.MaxAltitudeDiff); dbGrows.AddInParameter(dbCommand, "dataSource", DbType.String, weatherDatarequest.DataSource); dbGrows.AddInParameter(dbCommand, "gapFillSource", DbType.Boolean, weatherDatarequest.GapFillSource); dbGrows.AddInParameter(dbCommand, "temporalAggregation", DbType.String, str); dbGrows.AddInParameter(dbCommand, "startDate", DbType.DateTime, weatherDatarequest.StartDate); dbGrows.AddInParameter(dbCommand, "endDate", DbType.DateTime, weatherDatarequest.EndDate); for (int i = 0; i < weatherDatarequest.Series.Count; i++) { dbGrows.AddInParameter(dbCommand, "series" + (i + 1), DbType.String, weatherDatarequest.Series[i].SeriesName); } if (IsAgrinfo && stationId != 0) dbGrows.AddInParameter(dbCommand, "dataPointID", DbType.Int32, stationId); DataSet dsData = new DataSet(); dsData = dbGrows.ExecuteDataSet(dbCommand); /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/ FeatureResponse featureResponse = null; WeatherDataResponse weatherDataResponse = null; if (IsAgrinfo && stationId != 0) { featureResponse = new FeatureResponse(stationId, weatherDatarequest.FeatureRequest.Latitude, weatherDatarequest.FeatureRequest.Longitude, 0, 0, 0); weatherDataResponse = new WeatherDataResponse(featureResponse, weatherDatarequest.Series, dsData.Tables[0]); } else { featureResponse = new FeatureResponse((int)dsData.Tables[0].Rows[0]["dataPointID"], Convert.ToDouble(dsData.Tables[0].Rows[0]["latitude"]), Convert.ToDouble(dsData.Tables[0].Rows[0]["longitude"]), Convert.ToDouble(dsData.Tables[0].Rows[0]["altitude"]), Convert.ToDouble(dsData.Tables[0].Rows[0]["distance"]), Convert.ToDouble(dsData.Tables[0].Rows[0]["bearingDegrees"])); weatherDataResponse = new WeatherDataResponse(featureResponse, weatherDatarequest.Series, dsData.Tables[1]); } /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/ return weatherDataResponse; } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// this is to get the results from AIS DB /// </summary> public Tuple<DataTable, FeatureResponse> getData(DataTable series, string aggregation, string dataSource, int start, int end, bool isAgriInfo) { Serie serie = new Serie("", "", false, enumAggregationFunction.avg, ""); List<Serie> lst = new List<Serie>(); bool NotWaterModel = true; if (HttpContext.Current != null && HttpContext.Current.Session != null) { if (agriInfo != null && isAgriInfo) { startDate = DateTime.Parse(agriInfo["startDate"].ToString()); endDate = DateTime.Parse(agriInfo["endDate"].ToString()); /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/ if (cName.ToLower() == "watermodel") { /* UAT Issue - Data from Mar 1st & from Mar 6th, the moisture value are not correct - Jerrey - Start */ //you have to show data till todays date -2 days //if (endDate.Date.Subtract(DateTime.Now.Date).Days > 0) // endDate = DateTime.Now.Date.AddDays(-2); //if (startDate.Date.Subtract(DateTime.Now.Date).Days > 0 // && endDate.Date.Subtract(DateTime.Now.Date).Days > 0) //{ // HttpContext.Current.Session["ErrorMessage"] = cUtil.getTransText(Constants.INVALID_DATE_RANGE); // throw new Exception(cUtil.getTransText(Constants.INVALID_DATE_RANGE)); //} startDate = new DateTime(startDate.Year, 1, 1); NotWaterModel = false; /* UAT Issue - Data from Mar 1st & from Mar 6th, the moisture value are not correct - Jerrey - End */ } //if (cName.ToLower() != "gdd") if (cName.ToLower() != "gdd" && cName.ToLower() != "watermodel") /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/ aggregation = agriInfo["aggregation"].ToString(); else { aggregation = "daily"; NotWaterModel = false; } } else { startDate = current.AddDays(start); //endDate = current.AddDays(end>0?end-1:end+1); endDate = current.AddDays(end); } } else { startDate = current.AddDays(start); //endDate = current.AddDays(end >0 ? end-1:end+1); endDate = current.AddDays(end); } DataRow[] dt = null; /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/ //if (isAgriInfo && (!bool.Parse(agriInfo["IsGDD"]) && cName.ToLower() != "gdd")) if (isAgriInfo && (!bool.Parse(agriInfo["IsGDD"]) && cName.ToLower() != "gdd" && cName.ToLower() != "watermodel")) /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/ dt = series.Select("", "panel asc"); else dt = series.Select(""); enumDataSource source = (enumDataSource)Enum.Parse(typeof(enumDataSource), dataSource, true); enumTemporalAggregation tmpAggregation; switch (aggregation.ToLower()) { case "daily": tmpAggregation = enumTemporalAggregation.Daily; valuestep = 24; break; case "decade": tmpAggregation = enumTemporalAggregation.Decade; valuestep = 10; break; case "8hourly": tmpAggregation = enumTemporalAggregation.EightHourly; valuestep = 8; break; case "12hourly": tmpAggregation = enumTemporalAggregation.TwelveHourly; valuestep = 12; break; case "weekly": tmpAggregation = enumTemporalAggregation.Weekly; valuestep = 7; break; case "monthly": tmpAggregation = enumTemporalAggregation.Monthly; valuestep = 30; break; case "hourly": tmpAggregation = enumTemporalAggregation.Hourly; valuestep = 1; break; default: tmpAggregation = enumTemporalAggregation.Daily; valuestep = 24; break; } foreach (DataRow dr in dt) { if (tmpAggregation == enumTemporalAggregation.Daily || tmpAggregation == enumTemporalAggregation.Hourly) lst.Add( new Serie( dr["Name"].ToString() , "" , ((dr["Name"].ToString().ToLower().Contains("tempair") && NotWaterModel && isAgriInfo && agriInfo["altitude"].ToString() != string.Empty) ? true : false) , null , "")); else lst.Add( new Serie( dr["Name"].ToString() , "" , ((dr["Name"].ToString().ToLower().Contains("tempair") && NotWaterModel && isAgriInfo && agriInfo["altitude"].ToString() != string.Empty) ? true : false) , (enumAggregationFunction)Enum.Parse(typeof(enumAggregationFunction), dr["aggregationfunction"].ToString(), true) , "")); } if (startDate > endDate) { DateTime tmp = startDate; startDate = endDate; endDate = tmp; } //Get the altitude from the agriinfo object if (isAgriInfo) { fReq = new FeatureRequest(dpi.stationLatitude, dpi.stationLongitude, agriInfo["altitude"].ToString() != string.Empty ? Int32.Parse(agriInfo["altitude"].ToString()) : 0, dpi.NearbyPointSettings.MaxAllowedAltitude, dpi.NearbyPointSettings.MaxAllowedDistance); } else { fReq = new FeatureRequest(dpi.stationLatitude, dpi.stationLongitude, dpi.altitude, dpi.NearbyPointSettings.MaxAllowedAltitude, dpi.NearbyPointSettings.MaxAllowedDistance); } if (isAgriInfo) { DateTime newStartDate = startDate; DateTime newEndDate = endDate; /*IM01166165 -New Agricast - Agriinfo GDD IssueAfter providing planting date and start date and selecting GDD an error is being thrown. -BEGIN*/ int iDateDiff = (newEndDate - newStartDate).Days; /*IM01166165 -New Agricast - Agriinfo GDD IssueAfter providing planting date and start date and selecting GDD an error is being thrown. -BEGIN*/ /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - Start*/ //if (bool.Parse(agriInfo["IsGDD"].ToString()) && cName.ToLower() == "gdd") if (bool.Parse(agriInfo["IsGDD"].ToString()) && (cName.ToLower() == "gdd" || cName.ToLower() == "watermodel")) /*3.1 UC – BodenWasser Modell - display webpage as IFrame - Jerrey - End*/ { if (agriInfo.ContainsKey("plantingDate") && agriInfo["plantingDate"] != "") newStartDate = DateTime.Parse(agriInfo["plantingDate"]); /*IM01166165 -New Agricast - Agriinfo GDD IssueAfter providing planting date and start date and selecting GDD an error is being thrown. -BEGIN*/ //newEndDate = newStartDate.AddDays(iDateDiff + 1 ); /*IM01166165 -New Agricast - Agriinfo GDD IssueAfter providing planting date and start date and selecting GDD an error is being thrown. -BEGIN*/ } else { int maxyear = 0; int minyear = 0; var year = from row in series.AsEnumerable() where row.Field<string>("year") != "" group row by 1 into grp select new { min = grp.Min(r => r.Field<string>("year")), max = grp.Max(r => r.Field<string>("year")) }; if (year.ToList().Count > 0 && year.ToList()[0].min.ToString() != "") { minyear = Int32.Parse(year.ToList()[0].min.ToString()); } if (year.ToList().Count > 0 && year.ToList()[0].max.ToString() != "") { maxyear = Int32.Parse(year.ToList()[0].max.ToString()); } if (minyear != 0 && minyear < startDate.Year) newStartDate = startDate.AddYears(minyear - startDate.Year); if (maxyear != 0) { maxyear = maxyear + (endDate.Year - startDate.Year); if (maxyear > endDate.Year) { newEndDate = endDate.AddYears(maxyear - endDate.Year); } } } wReq = new WeatherDataRequest(source, false, fReq, newStartDate, (newEndDate == newStartDate ? newEndDate.AddDays(1) : newEndDate), tmpAggregation, lst); if (NotWaterModel) wRes = wData.GetWeatherData(wReq, true, dpi.DataPoint); else wRes = wData.GetWeatherData(wReq); } else { wReq = new WeatherDataRequest(source, false, fReq, startDate, (endDate == startDate ? endDate.AddDays(1) : endDate), tmpAggregation, lst); wRes = wData.GetWeatherData(wReq); } /*IM01166165 -New Agricast - Agriinfo GDD IssueAfter providing planting date and start date and selecting GDD an error is being thrown. -BEGIN*/ if (wRes.WeatherData != null) { selectedEndDate = endDate; } //if (wRes.WeatherData.Rows.Count > 0) //{ // selectedEndDate = endDate; // //if(endDate > DateTime.Parse(wRes.WeatherData.Select("date=max(date)")[0]["date"].ToString())) // // endDate = DateTime.Parse(wRes.WeatherData.Select("date=max(date)")[0]["date"].ToString()); //} /*IM01166165 -New Agricast - Agriinfo GDD IssueAfter providing planting date and start date and selecting GDD an error is being thrown. -BEGIN*/ return new Tuple<DataTable,FeatureResponse>(wRes.WeatherData,wRes.FeatureResponse); }