Exemplo n.º 1
0
        /// <summary>This refreshes data being displayed on the graphs, based on the value of the startYear and showYear values  </summary>
        /// <param name="table">The data set</param>
        /// <param name="startDate">The start date</param>
        /// <param name="endDate">The end date</param>
        /// <param name="updateYears">Update the years</param>
        private void DisplayGraphMonthlyRain(DataTable table, DateTime startDate, DateTime endDate, bool updateYears)
        {
            try
            {
                if (table != null && table.Rows.Count > 0)
                {
                    double[] monthlyRainfall = DataTableUtilities.AverageMonthlyTotals(table, "rain", startDate, endDate);

                    if (monthlyRainfall.Length != 0)
                    {
                        double[] avgMonthlyRainfall = DataTableUtilities.AverageMonthlyTotals(table, "rain", this.dataFirstDate, this.dataLastDate);
                        this.PopulateMonthlyRainfallGraph(
                            "Monthly Rainfall",
                            this.monthsToDisplay,
                            monthlyRainfall,
                            avgMonthlyRainfall);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception("Unable to display Detailed Graphs due to insufficient data: " + e.Message.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>Format a summary string about the weather file</summary>
        /// <param name="table">The data set</param>
        private void WriteSummary(DataTable table)
        {
            StringBuilder summary = new StringBuilder();

            summary.AppendLine("File name : " + this.weatherData.FileName);
            if (!string.IsNullOrEmpty(this.weatherData.ExcelWorkSheetName))
            {
                summary.AppendLine("Sheet Name: " + this.weatherData.ExcelWorkSheetName.ToString());
            }

            summary.AppendLine("Latitude  : " + this.weatherData.Latitude.ToString());
            summary.AppendLine("Longitude : " + this.weatherData.Longitude.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.dataStartDate.ToShortDateString());
            summary.AppendLine("End       : " + this.dataEndDate.ToShortDateString());
            summary.AppendLine(string.Empty);

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

                TimeSpan diff = this.dataLastDate - this.dataFirstDate;

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

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

                double[] yearlyRainfall  = DataTableUtilities.YearlyTotals(table, "Rain", this.dataFirstDate, this.dataLastDate);
                double[] monthlyRainfall = DataTableUtilities.AverageMonthlyTotals(table, "rain", this.dataFirstDate, this.dataLastDate);
                double[] monthlyMaxT     = DataTableUtilities.AverageDailyTotalsForEachMonth(table, "maxt", this.dataFirstDate, this.dataLastDate);
                double[] monthlyMinT     = DataTableUtilities.AverageDailyTotalsForEachMonth(table, "mint", this.dataFirstDate, this.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)
                {
                    this.monthsToDisplay = DataTableUtilities.GetDistinctMonthsasStrings(table, this.dataFirstDate, this.dataLastDate);
                }

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

                    summary.AppendLine(string.Format("For years : {0} - {1}", this.dataFirstDate.Year, this.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}", this.dataFirstDate.Year, this.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,
                        this.monthsToDisplay,
                        monthlyRainfall,
                        monthlyMaxT,
                        monthlyMinT);
                }

                this.weatherDataView.Summarylabel = summary.ToString();
            }
        }