Пример #1
0
        /// <summary>
        /// Creates Summary Crop Water Use Charts
        /// </summary>
        /// <param name="cbtt"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        private static List <string> CreateSummaryReport(string cbtt, DateTime t,
                                                         CropDatesDataSet.CropDatesRow[] cropRow)
        {
            var rval = new List <string>();

            //var cropRow = CropDatesDataSet.GetCropFiles(t.Year, cbtt);

            var et = new HydrometDailySeries(cbtt, "ETRS");
            //var et = new KimberlyPenmanEtSeries(cbtt);

            // Below is the calculation to determine how many days to read back. Set to calculate based on ETr Start Date.
            var etStartDate = cropRow[0].startdate.DayOfYear;
            var etTodayDate = t.DayOfYear;
            int numDaysRead = etTodayDate - etStartDate;

            et.Read(t.AddDays(-numDaysRead), t.AddDays(-1));

            // Produces Summary Chart heading.
            rval.Add("                        " + " " + cbtt + " - " + "ET SUMMARY" + " - " + t.ToString("yyyy") + " ");
            string s1 = " DATE "; string s2 = "     "; string s5 = " ----";

            for (int i = 0; i < cropRow.Length; i++)
            {
                var row = cropRow[i];
                s1 = s1 + row.cropname.PadRight(5);
                //s2 = s2 + " " + row.UIDX.ToString("F0").PadLeft(3) + " ";
                s2 = s2 + " " + "".PadLeft(3) + " ";
                s5 = s5 + " " + "----";
            }
            rval.Add(s2);
            rval.Add(s1);
            rval.Add(s5 + " ");

            // Populates Summary Chart by generating strings of ET values.
            string dateString = " ";

            for (int dateIndex = 1; dateIndex < numDaysRead; dateIndex++)
            {
                var t1 = et[dateIndex].DateTime;
                dateString = " " + t1.ToString("MM/dd").PadLeft(4);
                string valueString = "";
                for (int cropIndex = 0; cropIndex < cropRow.Length; cropIndex++)
                {
                    var row     = cropRow[cropIndex];
                    var etValue = CropCurves.WaterUse(t1, et[dateIndex].Value, row);
                    if (t1 < cropRow[cropIndex].startdate ||
                        t1 > cropRow[cropIndex].terminatedate)
                    {
                        valueString += "  -- ";
                    }
                    else
                    {
                        valueString += etValue.ToString("F2").PadLeft(5);
                    }
                }
                rval.Add(dateString + valueString);
            }
            return(rval);
        }
Пример #2
0
        /// <summary>
        /// Calculates the Daily Crop ET.
        /// </summary>
        /// <param name="numDaysRead">Number of days between Chart Generation date and the Start Date</param>
        /// <param name="n">The number of days from today for which you want the Crop ET</param>
        /// <param name="et"></param>
        /// <param name="row"></param>
        /// <returns></returns>
        internal static string ETCropDaily(int numDaysRead, int n, HydrometDailySeries et, CropDatesDataSet.CropDatesRow row)
        {
            double val = 0.00;

            if (numDaysRead > n)
            {
                val = CropCurves.WaterUse(et[numDaysRead - n].DateTime, et[numDaysRead - n].Value, row);
            }
            else
            {
            }
            if (val < 0)
            {
                return("msng");
            }
            else
            {
                return(val.ToString("F2"));
            }
        }
Пример #3
0
        /// <summary>
        /// Creates Daily Crop Water Use Charts
        /// </summary>
        /// <param name="cbtt"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        private static void CreateDailyHTMLWebReport(string cbtt, DateTime t,
                                                     CropDatesDataSet.CropDatesRow[] cropRow)
        {
            CropDatesDataSet.CropDatesDataTable cropTable = new CropDatesDataSet.CropDatesDataTable();
            cropTable = CropDatesDataSet.GetCropDataTable(t.Year, false);
            var agrimetDir = ConfigurationManager.AppSettings["AgriMetCropOutputDirectory"];

            string html_file = Path.Combine(agrimetDir, "chart", "agricultureEmail-V2.html");

            if (!File.Exists(html_file))
            {
                Logger.WriteLine("Error: missing file :" + html_file);
                return;
            }


            //var fn = Path.Combine(agrimetDir, "chart", html_file);
            var contents = File.ReadAllText(html_file);
            var outputfn = Path.Combine(agrimetDir, "chart", t.Year.ToString(), (cbtt + ".html"));
            var et       = new HydrometDailySeries(cbtt, "ETRS", s_host);

            // Below is the calculation to determine how many days to read back. Set to calculate based on ETr Start Date.
            var etStartDate = cropRow[0].startdate.DayOfYear;
            var etTodayDate = t.DayOfYear;
            int numDaysRead = etTodayDate - etStartDate - 1;

            et.Read(t.AddDays(-numDaysRead), t.AddDays(-1));

            var pcode     = new string[] { "MX", "MN", "PP", "TA", "UA", "WG" };
            var htmlPcode = new string[] {
                "{site_high_temp}",
                "{site_low_temp}",
                "{site_precip}",
                "{site_humidity}",
                "{site_wind}",
                "{site_max_wind}"
            };

            DateTime yesterday = DateTime.Now.Date.AddDays(-1);

            for (int i = 0; i < pcode.Length; i++)
            {
                var s = new HydrometDailySeries(cbtt, pcode[i], s_host);
                s.Read(yesterday, yesterday);

                var val = "";
                if (s.Count == 1 && !s[0].IsMissing)
                {
                    val = s[0].Value.ToString("F2");
                }

                contents = contents.Replace(htmlPcode[i], val);
            }
            contents = contents.Replace("{site_name}", cbtt);
            contents = contents.Replace("{yesterday}", yesterday.ToString("yyyy-MM-dd"));


            contents = contents.Replace("{site_m1}", t.AddDays(-1).Month.ToString() + "/" + t.AddDays(-1).Day.ToString());
            contents = contents.Replace("{site_m2}", t.AddDays(-2).Month.ToString() + "/" + t.AddDays(-2).Day.ToString());
            contents = contents.Replace("{site_m3}", t.AddDays(-3).Month.ToString() + "/" + t.AddDays(-3).Day.ToString());
            contents = contents.Replace("{site_m4}", t.AddDays(-4).Month.ToString() + "/" + t.AddDays(-4).Day.ToString());

            String[] cropCode  = { "ETr", "ALFP", "ALFM", "HAYP", "HAYM", "POTA", "POTS", "WGRN", "SGRN" };
            String[] cropNames = { "site_ref", "alfalfa_peak", "alfalfa_mean", "grass_peak", "grass_mean", "russet",
                                   "shepody",  "winter_grain", "spring_grain" };
            for (int i = 0; i < cropNames.Length; i++)
            {
                var rows = cropTable.Select("cbtt= '" + cbtt + "' and cropname= '" + cropCode[i] + "'");
                if (rows.Length == 0)
                {
                    continue;
                }

                var cRow = cropTable.NewCropDatesRow();
                cRow.ItemArray = rows[0].ItemArray;

                var crop = cropNames[i];
                contents = contents.Replace("{" + crop + "_et_m1}", CropCurves.ETCropDaily(numDaysRead, 1, et, cRow));
                contents = contents.Replace("{" + crop + "_et_m2}", CropCurves.ETCropDaily(numDaysRead, 2, et, cRow));
                contents = contents.Replace("{" + crop + "_et_m3}", CropCurves.ETCropDaily(numDaysRead, 3, et, cRow));
                contents = contents.Replace("{" + crop + "_et_m4}", CropCurves.ETCropDaily(numDaysRead, 4, et, cRow));
                contents = contents.Replace("{" + crop + "_et_avg}", (CropCurves.EtSummation(4, et, cRow, numDaysRead) / 4).ToString("F2"));
                contents = contents.Replace("{" + crop + "_7_day}", CropCurves.EtSummation(7, et, cRow, numDaysRead).ToString("F1"));
                contents = contents.Replace("{" + crop + "_14_day}", CropCurves.EtSummation(14, et, cRow, numDaysRead).ToString("F1"));
                contents = contents.Replace("{" + crop + "_total}", CropCurves.EtSummation(numDaysRead, et, cRow, numDaysRead).ToString("F1"));
                contents = contents.Replace("{" + crop + "_start_date}", cRow.startdate.ToString("MM/dd"));
                contents = contents.Replace("{" + crop + "_cover_date}", cRow.fullcoverdate.ToString("MM/dd"));
                contents = contents.Replace("{" + crop + "_term_date}", cRow.terminatedate.ToString("MM/dd"));
            }


            File.WriteAllText(outputfn, contents);
        }
Пример #4
0
        /// <summary>
        /// Creates Daily Crop Water Use Charts
        /// </summary>
        /// <param name="cbtt"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        private static List <string> CreateDailyReport(string cbtt, DateTime t,
                                                       CropDatesDataSet.CropDatesRow[] cropRow)
        {
            var rval = new List <string>();

            //var cropRow = CropDatesDataSet.GetCropFiles(t.Year, cbtt);

            // Produces Crop Chart heading
            rval.Add("");
            rval.Add(" ************************************************************************");
            rval.Add(" *                                                                      *");
            rval.Add(" *" + "  " + "ESTIMATED CROP WATER USE - " + t.ToString("MMM dd, yyyy") + "   " + cbtt + "\t\t\t" + "*");
            rval.Add(" *                                                                      *");
            rval.Add(" ************************************************************************");
            rval.Add(" *           *        DAILY        *      *     *     *      *    *     *");
            rval.Add(" *           * CROP WATER USE-(IN) * DAILY*     *     *      *  7 *  14 *");
            rval.Add(" * CROP START*  PENMAN ET  -  " + t.ToString("MMM") + "  * FORE *COVER* TERM* SUM  * DAY* DAY *");
            rval.Add(" *       DATE*---------------------* CAST * DATE* DATE*  ET  * USE* USE *");

            rval.Add(" *           *"
                     + t.AddDays(-4).Day.ToString().PadLeft(4)
                     + t.AddDays(-3).Day.ToString().PadLeft(5)
                     + t.AddDays(-2).Day.ToString().PadLeft(5)
                     + t.AddDays(-1).Day.ToString().PadLeft(5)
                     + "  *      *     *     *      *    *     *");

            var et = new HydrometDailySeries(cbtt, "ETRS");
            //var et = new KimberlyPenmanEtSeries(cbtt);

            // Below is the calculation to determine how many days to read back. Set to calculate based on ETr Start Date.
            var etStartDate = cropRow[0].startdate.DayOfYear;
            var etTodayDate = t.DayOfYear;
            int numDaysRead = etTodayDate - etStartDate - 1;

            et.Read(t.AddDays(-numDaysRead), t.AddDays(-1));

            // For-Loop to populate chart
            for (int i = 0; i < cropRow.Length; i++)
            {
                rval.Add(" *-----------*---------------------*------*------------------*----------*");
                var    row = cropRow[i];
                string s   = " * " + row.cropname.PadRight(4) + " " + row.startdate.ToString("MM/dd").PadLeft(4) + "*"
                             // Calculates Daily Crop ET values
                             + " " + CropCurves.ETCropDaily(numDaysRead, 4, et, row).PadLeft(4)
                             + " " + CropCurves.ETCropDaily(numDaysRead, 3, et, row).PadLeft(4)
                             + " " + CropCurves.ETCropDaily(numDaysRead, 2, et, row).PadLeft(4)
                             + " " + CropCurves.ETCropDaily(numDaysRead, 1, et, row).PadLeft(4)
                             // Today's forecast is the average of previous 3 days
                             + " * " + (CropCurves.EtSummation(3, et, row, numDaysRead) / 3).ToString("F2").PadLeft(3)
                             + " *" + row.fullcoverdate.ToString("MM/dd").PadRight(4) + "*" + row.terminatedate.ToString("MM/dd").PadLeft(4)
                             // Cumulative summation from Crop Start Date to today
                             + "* " + CropCurves.EtSummation(numDaysRead, et, row, numDaysRead).ToString("F1").PadLeft(4) + " * "
                             // 7 and 14 day use
                             + CropCurves.EtSummation(7, et, row, numDaysRead).ToString("F1") + "* "
                             + CropCurves.EtSummation(14, et, row, numDaysRead).ToString("F1") + " *";

                rval.Add(s);
            }

            rval.Add(" ************************************************************************");
            return(rval);
        }
Пример #5
0
        /// <summary>
        /// Creates Daily Crop Water Use Charts
        /// </summary>
        /// <param name="cbtt"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        private static List <string> CreateDailyHTMLReport(string cbtt, DateTime t,
                                                           CropDatesDataSet.CropDatesRow[] cropRow)
        {
            var rval = new List <string>();

            //var cropRow = CropDatesDataSet.GetCropFiles(t.Year, cbtt);
            DataTable heading_tbl = new DataTable();

            // Produces Crop Chart heading
            heading_tbl.Columns.Add("\t" + "ESTIMATED CROP WATER USE " + t.ToString("MMM dd, yyyy") + "   " + cbtt + "			");

            DataTable tbl = new DataTable();

            tbl.Columns.Add("Crop");
            tbl.Columns.Add("Start Date");
            tbl.Columns.Add("ET(IN) " + t.Month.ToString() + "/" + t.AddDays(-4).Day.ToString());
            tbl.Columns.Add("ET(IN) " + t.Month.ToString() + "/" + t.AddDays(-3).Day.ToString());
            tbl.Columns.Add("ET(IN) " + t.Month.ToString() + "/" + t.AddDays(-2).Day.ToString());
            tbl.Columns.Add("ET(IN) " + t.Month.ToString() + "/" + t.AddDays(-1).Day.ToString());
            tbl.Columns.Add("Daily Forecast");
            tbl.Columns.Add("Cover Date");
            tbl.Columns.Add("Termination Date");
            tbl.Columns.Add("Sum of ET");
            tbl.Columns.Add("7 Day Use");
            tbl.Columns.Add("14 Day Use");

            var et = new HydrometDailySeries(cbtt, "ETRS", s_host);


            // Below is the calculation to determine how many days to read back. Set to calculate based on ETr Start Date.
            var etStartDate = cropRow[0].startdate.DayOfYear;
            var etTodayDate = t.DayOfYear;
            int numDaysRead = etTodayDate - etStartDate - 1;

            et.Read(t.AddDays(-numDaysRead), t.AddDays(-1));

            // For-Loop to populate chart
            for (int i = 0; i < cropRow.Length; i++)
            {
                var row  = tbl.NewRow();
                var cRow = cropRow[i];
                row[0] = cRow.cropname;
                row[1] = cRow.startdate.ToString("MM/dd");
                row[2] = CropCurves.ETCropDaily(numDaysRead, 4, et, cRow);
                row[3] = CropCurves.ETCropDaily(numDaysRead, 3, et, cRow);
                row[4] = CropCurves.ETCropDaily(numDaysRead, 2, et, cRow);
                row[5] = CropCurves.ETCropDaily(numDaysRead, 1, et, cRow);

                // Today's forecast is the average of previous 3 days
                row[6] = (CropCurves.EtSummation(3, et, cRow, numDaysRead) / 3).ToString("F2");
                row[7] = cRow.fullcoverdate.ToString("MM/dd");
                row[8] = cRow.terminatedate.ToString("MM/dd");

                // Cumulative summation from Crop Start Date to today
                row[9] = CropCurves.EtSummation(numDaysRead, et, cRow, numDaysRead).ToString("F1");

                // 7 and 14 day use
                row[10] = CropCurves.EtSummation(7, et, cRow, numDaysRead).ToString("F1");
                row[11] = CropCurves.EtSummation(14, et, cRow, numDaysRead).ToString("F1");
                tbl.Rows.Add(row);
            }
            rval.Add("");
            rval.Add("<html>");
            rval.Add(DataTableOutput.ToHTML(heading_tbl));
            rval.Add(DataTableOutput.ToHTML(tbl));
            rval.Add("</html>");

            return(rval);
        }