Ejemplo n.º 1
0
        private StationsLevelReportViewModel GetStationsReportViewModel(CommandLineViewModel commandLine)
        {
            try
            {
                var reportView = new StationsLevelReportViewModel
                {
                    ReportType = string.IsNullOrEmpty(commandLine.Parameter) ?
                                 _config.GetDefaultParameter() : commandLine.Parameter.ToLower()
                };

                var stations = _monitor.GetStationReferencesAndNamesForRiver(commandLine.RiverName).Result;

                if (stations != null && stations.Any())
                {
                    reportView.RiverBasedStationNames = string.Join(", ", stations.Values);

                    var stationReferences = stations.Keys.ToList();

                    foreach (var stationRef in stationReferences)
                    {
                        reportView.StationBasedRiverLevels.Add(
                            _monitor.GetRiverWaterLevelDataAtStation(stationRef, commandLine).Result);
                    }
                }

                return(reportView);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex, _config.GetDefaultLoggingPath());
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void DisplayData(StationsLevelReportViewModel reportView)
        {
            try
            {
                if (reportView == null)
                {
                    Console.WriteLine("\nSorry, there is no data to display");
                }
                else
                {
                    Console.WriteLine("\nSTATION NAMES ===================================");
                    Console.WriteLine();
                    Console.WriteLine(string.IsNullOrEmpty(reportView.RiverBasedStationNames) ? "Sorry, there is no data to display" : reportView.RiverBasedStationNames);
                    Console.WriteLine();
                    Console.WriteLine("DATA FOR EACH STATION ===========================");
                    Console.WriteLine();

                    if (reportView.StationBasedRiverLevels == null || !reportView.StationBasedRiverLevels.Any())
                    {
                        Console.WriteLine("Sorry, there is no data to display\n");
                    }
                    else
                    {
                        foreach (var station in reportView.StationBasedRiverLevels)
                        {
                            if (station != null)
                            {
                                Console.WriteLine("Station name: {0}", station.StationName.ToUpper());

                                Console.WriteLine("Minimum {0}: {1} occurred on {2} at {3}", new string[] {
                                    reportView.ReportType,
                                    station.MinValue.ToString(),
                                    station.MinValueDate.ToLongDateString(),
                                    station.MinValueDate.ToShortTimeString()
                                });

                                Console.WriteLine("Maximum {0}: {1} occurred on {2} at {3}", new string[] {
                                    reportView.ReportType,
                                    station.MaxValue.ToString(),
                                    station.MaxValueDate.ToLongDateString(),
                                    station.MaxValueDate.ToShortTimeString()
                                });

                                Console.WriteLine("The average (mean) river {0}: {1}", new string[] {
                                    reportView.ReportType,
                                    station.AverageValue.ToString("0.###")
                                });
                            }
                            else
                            {
                                Console.WriteLine("Sorry, there is no data to display");
                            }

                            Console.WriteLine("\n===============================================\n");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogException(ex, _config.GetDefaultLoggingPath());
                Console.WriteLine("\nERROR OCCURRED!!!\n");
            }
            finally
            {
                Run(null);
            }
        }