Exemplo n.º 1
0
        /// <summary>Format a summary string about the weather file</summary>
        private void WriteSummary(DataTable table)
        {
            StringBuilder summary = new StringBuilder();

            summary.AppendLine("File name : " + this.weatherData.FileName);

            if (this.weatherData.ExcelWorkSheetName.Length > 0)
            {
                summary.AppendLine("Sheet Name: " + this.weatherData.ExcelWorkSheetName.ToString());
            }
            summary.AppendLine("Latitude  : " + this.weatherData.Latitude.ToString());
            summary.AppendLine("TAV       : " + String.Format("{0, 2:f2}", this.weatherData.Tav));
            summary.AppendLine("AMP       : " + String.Format("{0, 2:f2}", this.weatherData.Amp));
            summary.AppendLine("Start     : " + this.weatherData.StartDate.ToShortDateString());
            summary.AppendLine("End       : " + this.weatherData.EndDate.ToShortDateString());
            summary.AppendLine("");

            if (table != null && table.Rows.Count > 0)
            {
                dataFirstDate = DataTableUtilities.GetDateFromRow(table.Rows[0]);
                dataLastDate  = DataTableUtilities.GetDateFromRow(table.Rows[table.Rows.Count - 1]);

                TimeSpan diff = dataLastDate - dataFirstDate;
                //modLMC - 16/03/2016 - don't change dates if data is within the same year
                if (diff.Days > 365)
                {
                    if (dataFirstDate.DayOfYear != 1)
                    {
                        dataFirstDate = new DateTime(dataFirstDate.Year + 1, 1, 1);
                    }
                }

                //modLMC - 16/03/2016 - don't change dates if data is within the same year
                if (dataFirstDate.Year != dataLastDate.Year)
                {
                    if (dataLastDate.Day != 31 || dataLastDate.Month != 12)
                    {
                        dataLastDate = new DateTime(dataLastDate.Year - 1, 12, 31);
                    }
                }

                double[] yearlyRainfall  = MathUtilities.YearlyTotals(table, "Rain", dataFirstDate, dataLastDate);
                double[] monthlyRainfall = MathUtilities.AverageMonthlyTotals(table, "rain", dataFirstDate, dataLastDate);
                double[] monthlyMaxT     = MathUtilities.AverageDailyTotalsForEachMonth(table, "maxt", dataFirstDate, dataLastDate);
                double[] monthlyMinT     = MathUtilities.AverageDailyTotalsForEachMonth(table, "mint", dataFirstDate, dataLastDate);

                //what do we do if the date range is less than 1 year.
                //modlmc - 15/03/2016 - modified to pass in the "Month" values, and they may/may not contain a full year.
                if (monthlyRainfall.Length <= 12)
                {
                    monthsToDisplay = DataTableUtilities.GetDistinctMonthsasStrings(table, dataFirstDate, dataLastDate);
                }

                // long term average rainfall
                if (yearlyRainfall.Length != 0)
                {
                    double totalYearlyRainfall = MathUtilities.Sum(yearlyRainfall);
                    int    numYears            = dataLastDate.Year - dataFirstDate.Year + 1;
                    double meanYearlyRainfall  = totalYearlyRainfall / numYears;
                    double stddev = MathUtilities.StandardDeviation(yearlyRainfall);

                    summary.AppendLine(String.Format("For years : {0} - {1}", dataFirstDate.Year, dataLastDate.Year));
                    summary.AppendLine("Long term average yearly rainfall : " + String.Format("{0,3:f2}mm", meanYearlyRainfall));
                    summary.AppendLine("Yearly rainfall std deviation     : " + String.Format("{0,3:f2}mm", stddev));

                    string title = String.Format("Long term average data for years : {0} - {1}", dataFirstDate.Year, dataLastDate.Year);

                    //modlmc - 15/03/2016 - modified to pass in the "Month" values, and they may/may not contain a full year.
                    this.PopulateSummaryGraph(title,
                                              monthsToDisplay,
                                              monthlyRainfall,
                                              monthlyMaxT,
                                              monthlyMinT);
                }
                this.weatherDataView.Summarylabel = summary.ToString();
            }
        }