Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        /// <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);
        }