Пример #1
0
        /// <summary>
        /// Parses the temperature file asynchronous.
        /// </summary>
        /// <param name="tempFile">The temporary file.</param>
        /// <returns>A collection of weather data</returns>
        public async Task <WeatherDataCollection> ParseTemperatureFileAsync(StorageFile tempFile)
        {
            var days     = new WeatherDataCollection();
            var fileText = await FileIO.ReadTextAsync(tempFile);

            var lines      = fileText.Split(Environment.NewLine);
            var lineNumber = 0;

            foreach (var day in lines)
            {
                lineNumber++;
                try
                {
                    var fields = day.Split(",");
                    var date   = DateTime.Parse(fields[(int)WeatherDataFields.Date]);
                    var high   = Convert.ToInt16(fields[(int)WeatherDataFields.High]);
                    var low    = Convert.ToInt16(fields[(int)WeatherDataFields.Low]);

                    days.Add(new WeatherData(date, high, low));
                }
                catch (Exception)
                {
                    this.ErrorMessages.Append($"Corrupt Data on line {lineNumber} {Environment.NewLine}");
                }
            }

            return(days);
        }
Пример #2
0
        private void addNonConflictingData(WeatherDataCollection updatedWeatherDataCollection)
        {
            var oldNonConflictingData = this.oldWeatherDataCollection.Where(oldDay => !this.newWeatherDataCollection.Any(newDay => newDay.Date.Equals(oldDay.Date))).ToList();
            var newNonConflictingData = this.newWeatherDataCollection.Where(newDay => !this.oldWeatherDataCollection.Any(oldDay => oldDay.Date.Equals(newDay.Date))).ToList();

            foreach (var day in oldNonConflictingData)
            {
                updatedWeatherDataCollection.Add(day);
                this.oldWeatherDataCollection.Remove(day);
            }

            foreach (var day in newNonConflictingData)
            {
                updatedWeatherDataCollection.Add(day);
                this.newWeatherDataCollection.Remove(day);
            }
        }
Пример #3
0
        /// <summary cref="Object.MemberwiseClone" />
        public new object MemberwiseClone()
        {
            WeatherDataCollection clone = new WeatherDataCollection(this.Count);

            for (int ii = 0; ii < this.Count; ii++)
            {
                clone.Add((WeatherData)Utils.Clone(this[ii]));
            }

            return(clone);
        }
Пример #4
0
        private void addConflictingDayToUpdatedCollection(WeatherData currentDay,
                                                          WeatherDataCollection updatedWeatherDataCollection)
        {
            switch (this.chosenResult)
            {
            case ContentDialogResult.Primary:
                try
                {
                    var oldDay = this.oldWeatherDataCollection.Single(x => x.Date.Equals(currentDay.Date));
                    updatedWeatherDataCollection.Add(oldDay);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                break;

            case ContentDialogResult.Secondary:
                updatedWeatherDataCollection.Add(currentDay);
                break;
            }
        }
        /// <summary>
        /// Creates the report.
        /// </summary>
        /// <param name="daysForReport">The days for report.</param>
        /// <param name="bucketSize">Size of the bucket.</param>
        /// <returns>
        /// A full report outlining specific information based the supplied weather data
        /// </returns>
        public string CreateReport(WeatherDataCollection daysForReport, int bucketSize)
        {
            var report = new StringBuilder();

            this.bucketSize = bucketSize;
            var years = daysForReport.GroupByYear();

            foreach (var year in years)
            {
                var tempWeatherCollection = new WeatherDataCollection();
                foreach (var day in year)
                {
                    tempWeatherCollection.Add(day);
                }
            }

            report.Append(Environment.NewLine);

            this.createYearlyBreakdown(daysForReport, report);
            return(report.ToString());
        }
Пример #6
0
        /// <summary>
        ///     Merges the weather data collections.
        /// </summary>
        /// <param name="currentDataCollection">The old weather data collection.</param>
        /// <param name="newWeatherData">The new weather data collection.</param>
        /// <returns> the collection with the data</returns>
        public async Task <WeatherDataCollection> MergeWeatherDataCollections(
            WeatherDataCollection currentDataCollection, WeatherDataCollection newWeatherData)
        {
            this.oldWeatherDataCollection = currentDataCollection ??
                                            throw new ArgumentNullException(nameof(this.oldWeatherDataCollection), "Current collection cannot be null.");
            this.newWeatherDataCollection = newWeatherData ??
                                            throw new ArgumentNullException(nameof(newWeatherData), "New collection cannot be null.");


            var updatedWeatherDataCollection = new WeatherDataCollection();

            this.addNonConflictingData(updatedWeatherDataCollection);

            foreach (var conflictingDay in this.newWeatherDataCollection)
            {
                if (this.oldWeatherDataCollection.Any(oldDay => oldDay.Date.Equals(conflictingDay.Date)) &&
                    !this.isDoForAllChecked)
                {
                    var keepOrReplace = new ReplaceOrKeepDialog(conflictingDay, newWeatherData.Count);
                    this.chosenResult = await keepOrReplace.ShowAsync();

                    this.isDoForAllChecked = keepOrReplace.IsDoForAllChecked;
                }

                this.addConflictingDayToUpdatedCollection(conflictingDay, updatedWeatherDataCollection);
            }

            var tempWeatherDataCollection = updatedWeatherDataCollection.ToList();

            tempWeatherDataCollection.Sort();
            updatedWeatherDataCollection.Clear();

            foreach (var day in tempWeatherDataCollection)
            {
                updatedWeatherDataCollection.Add(day);
            }
            return(updatedWeatherDataCollection);
        }
        private void createYearlyBreakdown(WeatherDataCollection daysForReport, StringBuilder report)
        {
            var years = daysForReport.GroupByYear();

            foreach (var year in years)
            {
                var tempWeatherCollection = new WeatherDataCollection();
                foreach (var day in year)
                {
                    tempWeatherCollection.Add(day);
                }

                this.createOverview(tempWeatherCollection, report);
                report.Append(Environment.NewLine);

                var upperBound = tempWeatherCollection.GetDaysWithHighestTempForAYear()[0].High;
                var lowerBound = tempWeatherCollection.GetDaysWithLowestHighTempByYear()[0].High;


                report.Append("Highest Temp Histogram" + Environment.NewLine);
                this.createHistogram(report, tempWeatherCollection, lowerBound, upperBound, this.bucketSize, HighLow.High);
                report.Append(Environment.NewLine);


                upperBound = tempWeatherCollection.GetDaysWithHighestLowTempByYear()[0].Low;
                lowerBound = tempWeatherCollection.GetDaysWithLowestTempByYear()[0].Low;


                report.Append("Lowest Temp Histogram" + Environment.NewLine);
                this.createHistogram(report, tempWeatherCollection, lowerBound, upperBound, this.bucketSize, HighLow.Low);
                report.Append(Environment.NewLine);


                this.createMonthlyBreakdown(tempWeatherCollection, report);
            }
        }