Beispiel #1
0
        public async Task <Task> GenerateAlgorithmsStatistics()
        {
            var mockList = await dataManager.GetMocks();

            foreach (var mock in mockList)
            {
                Console.WriteLine(mock.Id);
                Task <Dictionary <string, long> >[] taskArray =
                {
                    Task <Dictionary <string, long> > .Factory.StartNew(() =>
                                                                        DoComputation(() => GetIntArray(mock.SetOfData).BubbleSort(), AlgorithmsEnum.BubbleSorter.ToString())
                                                                        ),
                    Task <Dictionary <string, long> > .Factory.StartNew(() =>
                                                                        DoComputation(() => GetIntArray(mock.SetOfData).BucketSort(), AlgorithmsEnum.BucketSorter.ToString())
                                                                        ),
                    Task <Dictionary <string, long> > .Factory.StartNew(() =>
                                                                        DoComputation(() => GetIntArray(mock.SetOfData).CombSort(), AlgorithmsEnum.ComboSorter.ToString())
                                                                        )
                };

                Task.WaitAll(taskArray);

                for (int i = 0; i < taskArray.Length; i++)
                {
                    var data = taskArray[i].Result;

                    if (data != null)
                    {
                        foreach (KeyValuePair <string, long> item in data)
                        {
                            var algorithm = await dataManager.GetAlgorithmAsync(item.Key);

                            if (algorithm != null)
                            {
                                var algStat = new AlgorithmStatistic()
                                {
                                    AlgorithmId  = algorithm.Id,
                                    Date         = DateTime.Now,
                                    ExecutedTime = item.Value,
                                    MockDataId   = mock.Id
                                };
                                await dataManager.AddAloritmStatisticAsync(algStat);
                            }
                            Console.WriteLine("Key: {0}, Value: {1}", item.Key, item.Value);
                        }
                    }
                }
            }

            return(Task.CompletedTask);
        }
        public async Task <bool> AddAloritmStatisticAsync(AlgorithmStatistic algorithmsStatistic)
        {
            try
            {
                _context.AlgorithmStatistics.Add(algorithmsStatistic);
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #3
0
        public void TestAll(IReadOnlyList <TAlgorithm> algorithms, IReadOnlyList <TProblem> problems)
        {
            Assert(algorithms.Any());
            Assert(problems.Any());

            _progressCounter = 0;
            _maxProgress     = algorithms.Count * problems.Count;

            var algorithmsStatistics = new AlgorithmStatistic[algorithms.Count];

            for (var i = 0; i < algorithms.Count; i++)
            {
                algorithmsStatistics[i] = TestOne(algorithms[i], problems);
            }

            Writer.WriteAll($";{string.Join(';', problems.Select(function => function.Name))}",
                            algorithmsStatistics);
        }