public async Task <IDictionary <CoordinatesModel, int> > GetDistributionByCoordinatesAsync() { var distribution = await Task.Run(() => _analizer.GetDistributionByCoordinates()); return(distribution.ToDictionary(keyValue => _mapper.Map <CoordinatesModel>(keyValue.Key), keyValue => keyValue.Value)); }
public void GetDistributionByCoordinatesTest_CorrectDictionaryIsReturned() { var firstKey = new Coordinates(2, 5); var secondKey = new Coordinates(1, 16); var thirdKey = new Coordinates(14, 0); var forthKey = new Coordinates(16, 5); var expected = new Dictionary <Coordinates, int> { [firstKey] = 3, [secondKey] = 3, [thirdKey] = 2, [forthKey] = 1 }; var actual = _analyzer.GetDistributionByCoordinates(); 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]); }
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(); } } }
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; } } }
public IDictionary <Coordinates, int> GetDistributionByCoordinates() => LoggerHelper.RunWithLogging(_logger, () => _innerAnalyzer.GetDistributionByCoordinates(), nameof(GetDistributionByCoordinates));
public IActionResult GetDistributionByCoordinates() { return(this.Ok(_analyzer.GetDistributionByCoordinates() .ToDictionary(pair => JsonConvert.SerializeObject(pair.Key), pair => pair.Value))); }