Exemple #1
0
        static void Main(string[] args)
        {
            //List<string> filePaths = GetFilePathsFromFolderRecursively("Levels\\Old_Format\\comp_levels_2017"); // 68.37
            //List<string> filePaths = GetFilePathsFromFolderRecursively("Levels\\Old_Format\\real_levels"); // 81.41
            List <string> filePaths = GetFilePathsFromFolderRecursively("Levels\\New_Format\\comp_levels"); // 66.44
            ConcurrentBag <SolveStatistic> statisticsBag      = new ConcurrentBag <SolveStatistic>();
            ConcurrentBag <LevelStatistic> levelStatisticsBag = new ConcurrentBag <LevelStatistic>();

            Stopwatch watch = new Stopwatch();

            watch.Start();
            Parallel.ForEach(filePaths, x =>
            {
                var statistic  = ProblemSolver.GetSolveStatistics(x, TimeSpan.FromSeconds(20), false);
                int?movesCount = null;

                if (statistic.Status == SolverStatus.SUCCESS)
                {
                    try
                    {
                        long startTime = watch.ElapsedMilliseconds;
                        var sc         = new ServerCommunicator();
                        var commands   = sc.NonAsyncSolve(statistic.Level, statistic.Solution);
                        movesCount     = CommandParallelizer.Parallelize(commands, statistic.Level).Length;
                        long endTime   = watch.ElapsedMilliseconds;

                        levelStatisticsBag.Add(new LevelStatistic(x, statistic.LevelName, movesCount.Value, endTime - startTime));
                    }
                    catch (Exception e)
                    {
                        statistic.Status      = SolverStatus.ERROR;
                        statistic.ErrorThrown = e;
                    }
                }

                Console.WriteLine($"{statistic.Status.ToString()} {Path.GetFileName(x)} Time: {statistic.RunTimeInMiliseconds} Moves: {(movesCount ?? -1)}");
                statisticsBag.Add(statistic);
            });
            watch.Stop();
            List <SolveStatistic> statistics = statisticsBag.ToList();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            var errorGroups = statistics.Where(x => x.Status == SolverStatus.ERROR)
                              .GroupBy(x => string.Join(Environment.NewLine, x.ErrorThrown.StackTrace.Split(Environment.NewLine).Take(2)))
                              .OrderByDescending(x => x.Count())
                              .ToList();

            foreach (var errorGroup in errorGroups)
            {
                var orderedErrors = errorGroup.OrderBy(x => x.ErrorThrown.StackTrace.Split(Environment.NewLine).Length);
                Console.WriteLine("Levels with this error:");
                Console.WriteLine(string.Join(Environment.NewLine, orderedErrors.Select(x => x.LevelName)));
                Console.WriteLine();
                Console.WriteLine("Error: ");
                var splittedError = orderedErrors.First().ErrorThrown.StackTrace.Split(Environment.NewLine);
                Console.WriteLine(orderedErrors.First().ErrorThrown.Message + Environment.NewLine + string.Join(Environment.NewLine, splittedError.Take(Math.Min(15, splittedError.Length))));
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Timeout:");
            Console.WriteLine(string.Join(Environment.NewLine, statistics.Where(x => x.Status == SolverStatus.TIMEOUT).Select(x => x.LevelName)));

            Console.WriteLine();
            Console.WriteLine($"Total time: {watch.ElapsedMilliseconds}");
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine($"Success: {statistics.Sum(x => x.Status == SolverStatus.SUCCESS ? 1 : 0)}");
            Console.WriteLine($"Timeout: {statistics.Sum(x => x.Status == SolverStatus.TIMEOUT ? 1 : 0)}");
            Console.WriteLine($"Error  : {statistics.Sum(x => x.Status == SolverStatus.ERROR ? 1 : 0)}");

            foreach (var scoreData in ScoresData)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                var score = scoreData.GetScore(levelStatisticsBag.ToList());
                Console.WriteLine($"Competition: {scoreData.CompetitionName}");
                Console.WriteLine($"SA move score: {score.SAMoveScore.ToString("N2")}");
                Console.WriteLine($"SA time score: {score.SATimeScore.ToString("N2")}");
                Console.WriteLine($"MA move score: {score.MAMoveScore.ToString("N2")}");
                Console.WriteLine($"MA time score: {score.MATimeScore.ToString("N2")}");
                Console.WriteLine($"Times faster:  {score.TimesFaster.ToString("N2")}");
                Console.WriteLine();
                Console.WriteLine($"Moves score:   {(score.SAMoveScore + score.MAMoveScore).ToString("N2")}");
                Console.WriteLine($"Time score:    {(score.SATimeScore + score.MATimeScore).ToString("N2")}");
                Console.WriteLine($"Total score:   {(score.SAMoveScore + score.MAMoveScore + score.SATimeScore + score.MATimeScore).ToString("N2")}");
            }


            Console.Read();
        }