Exemple #1
0
        public ActionResult <IEnumerable <PurchaseViewModel> > Cost([FromBody] string[] skus)
        {
            var purchases         = CostCalculationService.CalculateCost(skus);
            var purchaseViewModel = _mapper.Map <IEnumerable <PurchaseViewModel> >(purchases);

            return(new ActionResult <IEnumerable <PurchaseViewModel> >(purchaseViewModel));
        }
Exemple #2
0
        private void SimulationStepSwitch()
        {
            Dictionary <MyRoom, double> RoomCosts = new Dictionary <MyRoom, double>();

            double actualCost           = CostCalculationService.CalculateCost(model).First();
            double mincost              = actualCost;
            int    rooms                = model.modelRooms.Count;
            MyRoom switchThisMyRoomFrom = null;
            MyRoom switchThisMyRoomTo   = null;

            Parallel.For(0, rooms,
                         index => {
                Parallel.For(index + 1, rooms, secondindex => {
                    MyRoom r1       = model.modelRooms.ElementAt(index);
                    MyRoom r2       = model.modelRooms.ElementAt(secondindex);
                    MyRoom r1target = null;
                    MyRoom r2target = null;
                    Model tempModel = model.DeepCopy(r1, r2, out r1target, out r2target);
                    tempModel.SwitchRooms(ref r1target, ref r2target);

                    double cost = CostCalculationService.CalculateCost(tempModel).First();
                    lock (locker) {
                        RoomCosts.Add(r1, cost);
                        if (mincost >= cost)
                        {
                            mincost = cost;
                            //this might need to be switched later
                            switchThisMyRoomFrom = r1;
                            switchThisMyRoomTo   = r2;
                        }
                    }
                });
            });

            if (mincost >= actualCost)
            {
                actualSimulationThreshold++;
            }


            if (switchThisMyRoomFrom != null && switchThisMyRoomTo != null)
            {
                model.SwitchRooms(ref switchThisMyRoomFrom, ref switchThisMyRoomTo);
            }
            else
            {
                MessageBox.Show("no room to switch");
            }

            double[] costArray = CostCalculationService.CalculateCost(model);

            SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3]));
            actualSimulationIndex++;
        }
Exemple #3
0
 public MainWindow()
 {
     DataContext = this;
     InitializeComponent();
     model = ModelConfigurations.InitNormalModel();
     CostCalculationService.InitializeASD();
     LoadDataFromModel();
     simulation.Model         = model;
     simulation.ModelChanged += ModelChangeHandler;
     Paint();
 }
Exemple #4
0
        public SearchController(
            IDatabaseItemDao databaseItemDao,
            IPlayerItemDao playerItemDao,
            IDatabaseItemStatDao databaseItemStatDao,
            IItemSkillDao itemSkillDao,
            IBuddyItemDao buddyItemDao,
            StashManager stashManager,
            AugmentationItemRepo augmentationItemRepo
            )
        {
            this._dbItemDao              = databaseItemDao;
            this._playerItemDao          = playerItemDao;
            this._itemStatService        = new ItemStatService(databaseItemStatDao, itemSkillDao);
            this._itemPaginatorService   = new ItemPaginatorService(TakeSize);
            this._recipeService          = new RecipeService(databaseItemDao);
            this._costCalculationService = new CostCalculationService(playerItemDao, stashManager);
            this._buddyItemDao           = buddyItemDao;
            this._stashManager           = stashManager;
            this._augmentationItemRepo   = augmentationItemRepo;


            // Just make sure it writes .css/.html files before displaying anything to the browser
            //
            ItemHtmlWriter.ToJsonSerializeable(new List <PlayerHeldItem>()); // TODO: is this not a NOOP?
            JsBind.OnRequestItems += JsBind_OnRequestItems;

            // Return the ingredients for a given recipe
            JsBind.OnRequestRecipeIngredients += (sender, args) => {
                var recipeArgument = args as RequestRecipeArgument;
                var ingredients    = _recipeService.GetRecipeIngredients(recipeArgument?.RecipeRecord);
                _costCalculationService.Populate(ingredients);
                _costCalculationService.SetMod(_previousMod);

                _previousCallback = recipeArgument?.Callback;
                _previousRecipe   = recipeArgument?.RecipeRecord;
                Browser.SetRecipeIngredients(JsBind.Serialize(ingredients));
            };


            // Update the recipe when the stash has changed
            stashManager.StashUpdated += StashManagerOnStashUpdated;


            // Return the list of recipes
            JsBind.OnRequestRecipeList += (sender, args) => {
                var recipes = _recipeService.GetRecipeList();
                Browser.SetRecipes(JsBind.Serialize(recipes));
            };
        }
Exemple #5
0
        private void SimulationStepMove()
        {
            Dictionary <string, double> Costs = new Dictionary <string, double>();
            MyLine minline             = null;
            int    currentMoveDistance = moveDistance;
            double actualCost          = CostCalculationService.CalculateCost(model).First();
            double mincost             = actualCost;

            Parallel.For(0, model.modelLines.Count,
                         index => {
                MyLine myLine    = model.modelLines.ElementAt(index);
                MyLine newMyLine = null;
                Model tempModel  = model.DeepCopy(myLine, out newMyLine);
                tempModel.MoveLine(moveDistance, newMyLine);

                double cost = CostCalculationService.CalculateCost(tempModel).First();
                lock (locker) {
                    Costs.Add("+" + myLine.ToString(), cost);
                    if (mincost > cost)
                    {
                        mincost             = cost;
                        minline             = myLine;
                        currentMoveDistance = moveDistance;
                    }
                }
            });

            Parallel.For(0, model.modelLines.Count,
                         index => {
                MyLine myLine    = model.modelLines.ElementAt(index);
                MyLine newMyLine = null;
                Model tempModel  = model.DeepCopy(myLine, out newMyLine);
                tempModel.MoveLine(-moveDistance, newMyLine);

                double cost = CostCalculationService.CalculateCost(tempModel).First();
                lock (locker) {
                    Costs.Add("-" + myLine.ToString(), cost);
                    if (mincost > cost)
                    {
                        mincost             = cost;
                        minline             = myLine;
                        currentMoveDistance = -moveDistance;
                    }
                }
            });

            if (mincost >= actualCost)
            {
                actualSimulationThreshold++;
            }
            if (minline != null)
            {
                model.MoveLine(currentMoveDistance, minline);
            }
            else
            {
                MessageBox.Show("no line to move");
            }
            LineAndCostActualStep.Clear();
            foreach (var item in Costs)
            {
                LineAndCostActualStep.Add(new LineAndCost(item.Key, item.Value, actualSimulationIndex));
            }
            //System.Windows.Forms.MessageBox.Show(mincost.ToString());
            //SimulationCosts.Add(new Costs(actualSimulationIndex, mincost));

            double[] costArray = CostCalculationService.CalculateCost(model);
            SimulationCosts.Add(new Costs(actualSimulationIndex, costArray[0], costArray[1], costArray[2], costArray[3]));

            actualSimulationIndex++;
        }