Пример #1
0
        public void GetDistributionByObservationTimeTest_CorrectDictionaryIsReturned()
        {
            var firstKey   = new DateTime(2019, 10, 15);
            var secondKey  = new DateTime(2019, 10, 25);
            var thirdKey   = new DateTime(2019, 10, 13);
            var forthKey   = new DateTime(2019, 10, 29);
            var fifthKey   = new DateTime(2019, 10, 30);
            var sixthKey   = new DateTime(2019, 10, 26);
            var seventhKey = new DateTime(2019, 10, 17);

            var expected = new Dictionary <DateTime, int>
            {
                [firstKey]   = 2,
                [secondKey]  = 1,
                [thirdKey]   = 1,
                [forthKey]   = 2,
                [fifthKey]   = 1,
                [sixthKey]   = 1,
                [seventhKey] = 1
            };

            var actual = _analyzer.GetDistributionByObservationTime();

            Assert.Equal(expected.Count, actual.Count);
            Assert.Equal(expected[firstKey], actual[firstKey]);
            Assert.Equal(expected[secondKey], actual[secondKey]);
            Assert.Equal(expected[thirdKey], actual[thirdKey]);
            Assert.Equal(expected[forthKey], actual[forthKey]);
            Assert.Equal(expected[fifthKey], actual[fifthKey]);
            Assert.Equal(expected[sixthKey], actual[sixthKey]);
            Assert.Equal(expected[seventhKey], actual[seventhKey]);
        }
 public async Task <IDictionary <DateTime, int> > GetDistributionByObservationTimeAsync()
 => await Task.Run(() => _analizer.GetDistributionByObservationTime());
Пример #3
0
        private static void ShowAnalizerResult(IEnergyObservationAnalizer analizer)
        {
            Console.Clear();
            Console.WriteLine("Select and press 'Enter' button:");
            Console.WriteLine("1 - GetAverageEnergy");
            Console.WriteLine("2 - GetDistributionByCoordinates");
            Console.WriteLine("3 - GetDistributionByEnergyValue");
            Console.WriteLine("4 - GetDistributionByObservationTime");
            Console.WriteLine("5 - GetMaxEnergy");
            Console.WriteLine("6 - GetMaxEnergyPosition");
            Console.WriteLine("7 - GetMaxEnergyTime");
            Console.WriteLine("8 - GetMinEnergy");
            Console.WriteLine("9 - GetMinEnergyPosition");
            Console.WriteLine("10 - GetMinEnergyTime");
            Console.WriteLine("something another - exit");

            var exit = false;

            while (!exit)
            {
                int menuIndex  = 0;
                var userChoice = Console.ReadLine();
                var isParsed   = int.TryParse(userChoice, out menuIndex);
                if (isParsed)
                {
                    switch (menuIndex)
                    {
                    case 1:
                        Console.WriteLine(" Average energy is: " + analizer.GetAverageEnergy());
                        break;

                    case 2:
                        Console.WriteLine("Distribution by coordinates is:");
                        analizer.GetDistributionByCoordinates().PrintDistribution("Coordinates");
                        break;

                    case 3:
                        Console.WriteLine("Distribution by energy value is:");
                        analizer.GetDistributionByEnergyValue().PrintDistribution("Energy value");
                        break;

                    case 4:
                        Console.WriteLine("Distribution by observation time is:");
                        analizer.GetDistributionByObservationTime().PrintDistribution("Observation time");
                        break;

                    case 5:
                        Console.WriteLine(" Max energy is: " + analizer.GetMaxEnergy());
                        break;

                    case 6:
                        Console.WriteLine(" Max energy position is: " + analizer.GetMaxEnergyPosition());
                        break;

                    case 7:
                        Console.WriteLine(" Max energyTime is: " + analizer.GetMaxEnergyTime());
                        break;

                    case 8:
                        Console.WriteLine(" Min energy is: " + analizer.GetMinEnergy());
                        break;

                    case 9:
                        Console.WriteLine(" Position of min energy is: " + analizer.GetMinEnergyPosition());
                        break;

                    case 10:
                        Console.WriteLine(" Time of min energy is: " + analizer.GetMinEnergyTime());
                        break;
                    }
                }
                else
                {
                    exit = true;
                    Console.Clear();
                    ShowMainMenu();
                }
            }
        }
Пример #4
0
        private static void ProcessAnalyzer(IEnergyObservationAnalizer analizer)
        {
            Console.Clear();
            Console.WriteLine("Choose method");
            Console.WriteLine("1 - GetAverageEnergy");
            Console.WriteLine("2 - GetDistributionByCoordinates");
            Console.WriteLine("3 - GetDistributionByEnergyValue");
            Console.WriteLine("4 - GetDistributionByObservationTime");
            Console.WriteLine("5 - GetMaxEnergy");
            Console.WriteLine("6 - GetMaxEnergyPosition");
            Console.WriteLine("7 - GetMaxEnergyTime");
            Console.WriteLine("8 - GetMinEnergy");
            Console.WriteLine("9 - GetMinEnergyPosition");
            Console.WriteLine("10 - GetMinEnergyTime");
            Console.WriteLine("Anything else to exit");

            var userChoiceToExit = false;

            while (!userChoiceToExit)
            {
                if (TryReadUserInput(0, 10, out int userChoice))
                {
                    switch (userChoice)
                    {
                    case 1:
                        Console.WriteLine(analizer.GetAverageEnergy());
                        break;

                    case 2:
                        WriteLineDictionary(analizer.GetDistributionByCoordinates());
                        break;

                    case 3:
                        WriteLineDictionary(analizer.GetDistributionByEnergyValue());
                        break;

                    case 4:
                        WriteLineDictionary(analizer.GetDistributionByObservationTime());
                        break;

                    case 5:
                        Console.WriteLine(analizer.GetMaxEnergy());
                        break;

                    case 6:
                        Console.WriteLine(analizer.GetMaxEnergyPosition());
                        break;

                    case 7:
                        Console.WriteLine(analizer.GetMaxEnergyTime());
                        break;

                    case 8:
                        Console.WriteLine(analizer.GetMinEnergy());
                        break;

                    case 9:
                        Console.WriteLine(analizer.GetMinEnergyPosition());
                        break;

                    case 10:
                        Console.WriteLine(analizer.GetMinEnergyTime());
                        break;
                    }
                }
                else
                {
                    userChoiceToExit = true;
                }
            }
        }
Пример #5
0
 public IDictionary <DateTime, int> GetDistributionByObservationTime() => LoggerHelper.RunWithLogging(_logger,
                                                                                                      () => _innerAnalyzer.GetDistributionByObservationTime(), nameof(GetDistributionByObservationTime));
Пример #6
0
 public IActionResult GetDistributionByObservationTime()
 {
     return(this.Ok(_analyzer.GetDistributionByObservationTime()
                    .ToDictionary(pair => JsonConvert.ToString(pair.Key), pair => pair.Value)));
 }