Пример #1
0
        public static List <FlatProgressInfo> Flatten(this ProgressComponent This)
        {
            if (This == null)
            {
                throw new ArgumentNullException(nameof(This));
            }
            var list = new List <FlatProgressInfo> {
                This.MapTo <FlatProgressInfo>()
            };
            var active = This.GetFirstActive();

            if (active == null)
            {
                return(list);
            }
            var c = active as ProgressComponent;

            if (c != null)
            {
                list.AddRange(c.Flatten());
            }
            else
            {
                list.Add(active.MapTo <FlatProgressInfo>());
            }
            return(list);
        }
Пример #2
0
        public override ReturnCodes Execute(ConsoleCommandController controller)
        {
            // MODE: Progress + Library
            ProgressComponent comp = new ProgressComponent();
            comp.Load(ArgSolverLibrary);

            int total = comp.Items.Count;
            var countSolutions = comp.Items.Count(x => x.HasSolution);
            controller.DisplayLable("# Solutions", string.Format("{0}/{1} = {2} %", countSolutions, total, countSolutions * 100 / total));

            controller.DisplayHeader("TOP 10", 1);
            var best = comp.Items.Where(x => x.HasSolution).OrderByDescending(x => x.Rating).Take(10);
            foreach (SolverPuzzle puzzle in best)
            {
                controller.DisplayLable("Best", puzzle.Rating.ToString());
                controller.Display(StringHelper.Join(puzzle.NormalisedMap, null, Environment.NewLine));
            }

            controller.DisplayHeader("WORST 10", 1);
            var worst = comp.Items.Where(x => !x.HasSolution).OrderBy(x => x.Rating).Take(10);
            foreach (SolverPuzzle puzzle in worst)
            {
                controller.DisplayLable("Worst", string.Format("{0}, longest attempt={1}", puzzle.Rating, puzzle.Attempts.Items.Max(x => x.ElapsedTime)));
                controller.Display(StringHelper.Join(puzzle.NormalisedMap, null, Environment.NewLine));
            }

            return ReturnCodes.OK;
        }
        public override ReturnCodes Execute(ConsoleCommandController controller)
        {
            // MODE: Progress + Library
            ProgressComponent comp = new ProgressComponent();
            comp.Load(ArgSolverLibrary);

            // MODE: Only Library
            XmlProvider xml = new XmlProvider();
            Library lib = xml.Load(ArgLibrary);

            controller.DisplayLable("Reading File", ArgLibrary);
            controller.DisplayLable("Reading Library", lib.GetDetails().Name);

            if (ArgPuzzle == null || ArgPuzzle == "*")
            {
                int cc = 0;
                comp.Add(lib);
            }
            else
            {
                Puzzle pux = lib.GetPuzzleByID(ArgPuzzle);
                comp.Add(pux.MasterMap);
            }

            comp.Sort();
            comp.Save(ArgSolverLibrary);
            controller.Display(comp.Summary);

            return ReturnCodes.OK;
        }
        public override void OnInit()
        {
            base.OnInit();

            this.progress = this.GetLayoutComponent <ProgressComponent>();

            User.instance.id = Random.Range(0, 500);
            this.userInfo    = this.FlowUserInfo();
        }
Пример #5
0
 public Progress(ProgressComponent component)
 {
     _component  = component;
     _components = new IProgressComponent[] {
         Checking    = new ProgressLeaf("Checking"),
         Compressing = new ProgressLeaf("Compressing", 3),
         Copying     = new ProgressContainer("Copying", 2),
         Downloading = new ProgressLeaf("Downloading", 9),
         Extracting  = new ProgressContainer("Extracting", 3)
     };
     _component.AddComponents(_components);
 }
        public void SetUpModel(ProgressComponent model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            UnsubscribeFromModel();

            this.Model = model;

            Model.ProgressUpdated += Model_ProgressUpdated;
            UpDateValues();
        }
        public void TestProgressCreate()
        {
            ProgressComponent comp = new ProgressComponent();

            XmlProvider xml = new XmlProvider();
            Library lib = xml.Load(MakePathUIContent(@"Libraries\SolverDevelopment.ssx"));

            comp.Add(lib);

            comp.Save("temp_test_progress.xml");

            ProgressComponent load = new ProgressComponent();
            load.Load("temp_test_progress.xml");

            Assert.AreEqual(comp.Count, load.Count);
        }
Пример #8
0
        private static FileInfoWithData <State>[] PrepareFiles(
            Dictionary <IAbsoluteDirectoryPath, FileObjectMapping[]> dict, IAbsoluteDirectoryPath downloadPath,
            Uri[] hosts,
            StatusRepo status, ProgressContainer component)
        {
            var map = new Dictionary <string, List <IAbsoluteFilePath> >();

            foreach (var a in dict)
            {
                foreach (var v in a.Value)
                {
                    var fullPath = a.Key.GetChildFileWithName(v.FilePath);
                    if (map.ContainsKey(v.Checksum))
                    {
                        map[v.Checksum].Add(fullPath);
                    }
                    else
                    {
                        map[v.Checksum] = new List <IAbsoluteFilePath> {
                            fullPath
                        }
                    };
                }
            }

            return(map.Select(x => {
                var progressComponent = new ProgressComponent(x.Key);
                component.AddComponents(progressComponent);
                return new FileInfoWithData <State>(
                    new DownloadInfo(GetRemotePath(x.Key),
                                     downloadPath.GetChildFileWithName(SplitObjectName(x.Key)), hosts),
                    x.Value.ToArray(),
                    new State {
                    Checksum = x.Key,
                    Progress = new Progress(progressComponent)
                })
                {
                    CancelToken = status.CancelToken
                };
            }).OrderByDescending(x => Tools.FileUtil.SizePrediction(x.Destinations.First().FileName)).ToArray());
        }

        Dictionary <IAbsoluteDirectoryPath, FileObjectMapping[]> TransformPackages(IEnumerable <Package> p)
        => p.ToDictionary(x => x.WorkingPath,
                          x => x.MetaData.Files.Select(f => new FileObjectMapping(f.Key, f.Value)).ToArray());
        public void TestProgressUpdate()
        {
            ProgressComponent comp = new ProgressComponent();

            XmlProvider xml = new XmlProvider();
            Library lib = xml.Load(MakePathUIContent(@"Libraries\Sasquatch.ssx"));

            comp.Add(lib);

            var res = Solve(lib.GetPuzzleByID("P1").MasterMap.Map);
            var rec = comp.Update(res);
            Assert.IsTrue(rec.HasSolution);

            var res2 = Solve(lib.GetPuzzleByID("P3").MasterMap.Map);
            var rec2 = comp.Update(res2);
            Assert.IsTrue(rec2.HasSolution);

            comp.Save("temp_test_progress.xml");
        }
Пример #10
0
        public override void OnInit()
        {
            base.OnInit();

            this.progress = this.GetLayoutComponent <ProgressComponent>();
        }
Пример #11
0
 public LoadElementUpdateSystem(List <LoadingData> loadings, ProgressComponent progress)
 {
     this.loadings = loadings;
     this.progress = progress;
 }
Пример #12
0
        public override ReturnCodes Execute(ConsoleCommandController controller)
        {
            if (ArgReport != null)
            {
                reportFile = File.CreateText(ArgReport);
            }

            if (!string.IsNullOrEmpty(ArgSolverLibrary))
            {
                DateTime start = DateTime.Now;

                // MODE: Progress + Library
                ProgressComponent comp = new ProgressComponent();
                Library lib = null;

                // It is exists load...
                if (File.Exists(ArgSolverLibrary))
                {
                    comp.Load(ArgSolverLibrary);
                }

                // If a library is specified, merge/add it...
                if (!string.IsNullOrEmpty(ArgLibrary))
                {
                    XmlProvider xml = new XmlProvider();
                    lib = xml.Load(ArgLibrary);
                    comp.Add(lib);
                }

                int cc = 0;
                foreach (SolverPuzzle item in comp.Items)
                {
                    if (ArgNonSolutionOnly && item.HasSolution)
                    {
                        controller.DisplayLable("Skipping solution", item.Name);
                        cc++;
                        continue;
                    }

                    TimeSpan left = TimeSpan.FromSeconds((double) (comp.Items.Count - cc)*ArgMaxTime);
                    controller.DisplayLable("Est. Time Left", left.ToString());
                    controller.DisplayLable("Time Elapsed", (DateTime.Now-start).ToString());
                    controller.Display("==========================================================================");
                    controller.Display("");
                    controller.DisplayLable("Attempt", string.Format("{0}/{1} {2}%, maxtime={3}", cc, comp.Items.Count, cc*100/comp.Items.Count, TimeSpan.FromSeconds(ArgMaxTime)));
                    controller.DisplayLable("Name", item.Name);
                    controller.DisplayLable("Rating", string.Format("{0}, size=({1}, {2})", item.Rating, item.Width, item.Height));

                    controller.Display(StringHelper.Join(item.NormalisedMap, null, Environment.NewLine));

                    SokobanMap map = new SokobanMap();
                    map.SetFromStrings(item.NormalisedMap);
                    using (SolverController ctrl = new SolverController(map))
                    {
                        ctrl.ExitConditions.MaxDepth = 1000;
                        ctrl.ExitConditions.MaxItterations = 10000000;
                        ctrl.ExitConditions.MaxTimeSecs = (float) ArgMaxTime;

                        SolverResult res = ctrl.Solve();
                        if (res.Exception != null)
                        {
                            controller.Display(res.Exception);
                        }
                        controller.DisplayLable("Result", res.Summary);

                        comp.Update(res);
                    }

                    CheckForceGC();
                    controller.Display("---------------------------------------------------------------------------");

                    if (System.Console.KeyAvailable && System.Console.ReadKey().KeyChar == 'Q')
                    {
                        controller.Display("BREAK REQUESTED... Exiting");
                        break;
                    }

                    cc++;
                }

                comp.Save(ArgSolverLibrary);

            }
            else if (!string.IsNullOrEmpty(ArgLibrary))
            {
                // MODE: Only Library
                XmlProvider xml = new XmlProvider();
                Library lib = xml.Load(ArgLibrary);

                if (ArgPuzzle == "*")
                {
                    int cc = 0;
                    foreach (Puzzle puzzle in lib.Puzzles)
                    {
                        cc++;
                        controller.Display("");
                        controller.DisplayLable("Attempting", string.Format("{0:000} of {1:000}", cc, lib.Puzzles.Count));

                        SolvePuzzle(puzzle.MasterMap, puzzle.GetDetails().Name);

                        CheckForceGC();

                        if (System.Console.KeyAvailable && System.Console.ReadKey().KeyChar == 'Q')
                        {
                            controller.Display("BREAK REQUESTED... Exiting");
                            break;
                        }

                    }
                }
                else
                {
                    Puzzle pux = lib.GetPuzzleByID(ArgPuzzle);
                    SolvePuzzle(pux.MasterMap, pux.GetDetails().Name);
                }
            }

            if (reportFile != null)
            {
                reportFile.Close();
                reportFile.Dispose();
            }

            return ReturnCodes.OK;
        }
 public ProgressComponentViewModel(ProgressComponent model)
 {
     SetUpModel(model);
 }