示例#1
0
        public async Task <string> CreateAsync(string hallId, Stand stand)
        {
            var hall = await _halls.Find(hall => hall.Id.Equals(hallId)).FirstOrDefaultAsync();

            if (hall != null)
            {
                if (stand.Photo?.Photo != null)
                {
                    ObjectId id = await _gridFS.UploadFromBytesAsync(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff"), stand.Photo.Photo);

                    stand.Photo.Id    = id.ToString();
                    stand.Photo.Photo = null;
                }

                stand.Id = ObjectId.GenerateNewId().ToString();
                var filter = Builders <Hall> .Filter.Eq("Id", hallId);

                var update = Builders <Hall> .Update.Push("Stands", stand);

                await _halls.UpdateOneAsync(filter, update);

                return(stand.Id);
            }
            return(null);
        }
    public void SetStandComputed()
    {
        int w100 = CharacterEngine.ComputeStandWurf();

        inStandWurf.text = w100.ToString();

        Stand stand = CharacterEngine.GetStandfromWurf(w100);

        switch (stand)
        {
        case Stand.Unfrei:
            inStandText.text = "unfrei";
            break;

        case Stand.Volk:
            inStandText.text = "Volk";
            break;

        case Stand.Mittelschicht:
            inStandText.text = "Mittelschicht";
            break;

        case Stand.Adel:
            inStandText.text = "Adel";
            break;

        default:
            break;
        }
    }
        //---------------------------------------------------------------------

        /// <summary>
        /// Assigns an active site to a particular stand.
        /// </summary>
        /// <param name="activeSite">
        /// The active site that is being assigned to a stand.
        /// </param>
        /// <param name="mapCode">
        /// The map code of the stand that the site is being assigned to.
        /// </param>
        public static void AssignSiteToStand(ActiveSite activeSite,
                                             ushort     mapCode)
        {
            double blockArea = (activeSite.SharesData ? Model.BlockArea : Model.Core.CellArea)
            
            //  Skip the site if its management area is not active.
            if (SiteVars.ManagementArea[activeSite] == null)
                return;

            Stand stand;
            //check if this stand is already in the dictionary
            if (stands.TryGetValue(mapCode, out stand)) {
                //if the stand is already in the dictionary, check if it is in the same management area.
                //if it's not in the same MA, throw exception.
                if (SiteVars.ManagementArea[activeSite] != stand.ManagementArea) {
                    throw new PixelException(activeSite.Location,
                                             "Stand {0} is in management areas {1} and {2}",
                                             stand.MapCode,
                                             stand.ManagementArea.MapCode,
                                             SiteVars.ManagementArea[activeSite].MapCode);
                }

            }
            //valid site location which has not been keyed by the dictionary.
            else {
                //assign stand (trygetvalue set it to null when it wasn't found in the dictionary)
                stand = new Stand(mapCode, blockArea);
                //add this stand to the correct management area (pointed to by the site)
                SiteVars.ManagementArea[activeSite].Add(stand);
                stands[mapCode] = stand;
            }                        

            //add this site to this stand
            stand.Add(activeSite);
        }
示例#4
0
        public static Dictionary <Stand, List <Product> > Level1GroupProductsByStand(Product[] products)
        {
            Dictionary <Stand, List <Product> > ExtraStand = new Dictionary <Stand, List <Product> >();

            //level 1: group the product by the shelves
            //key: The common stand, value: list of the product [in the shop]
            //הייתי רוצה שבמקום הלולאה יהיה בשאילתת לינק פשוטה, איך עושים שלכל סטנד יהיה רשימת מוצרים
            //  var v= products.GroupBy(x => x.ProductShelves.First().Shelf.Stand).ToDictionary(y=>y.Key);

            foreach (var item in products)
            {
                //TODO: לטפל במוצרים שאין להם מיקום
                if (item.ProductShelves.Count == 0)
                {
                    continue;
                }
                Stand s          = item.ProductShelves.First().Shelf.Stand;
                Stand anotherKey = ExtraStand.Keys.FirstOrDefault(x => x.Equals(s));
                if (anotherKey == null)
                {
                    ExtraStand.Add(s, new List <Product>()
                    {
                        item
                    });
                }
                else //או
                {
                    ExtraStand[anotherKey].Add(item);
                }
            }
            return(ExtraStand);
        }
示例#5
0
        public async Task UpdateAsync(string hallId, string id, Stand stand)
        {
            if (!string.IsNullOrEmpty(stand.Photo?.Id))
            {
                await _gridFS.DeleteAsync(ObjectId.Parse(stand.Photo.Id));
            }
            if (stand?.Photo?.Photo != null)
            {
                ObjectId photoId = await _gridFS.UploadFromBytesAsync(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff"), stand.Photo.Photo);

                stand.Photo.Id    = photoId.ToString();
                stand.Photo.Photo = null;
            }
            else
            {
                stand.Photo = null;
            }

            var arrayFilter = Builders <Hall> .Filter.And(
                Builders <Hall> .Filter.Where(hall => hall.Id.Equals(hallId)),
                Builders <Hall> .Filter.Eq("Stands.Id", id));

            var update = Builders <Hall> .Update.Set("Stands.$", stand);

            await _halls.UpdateOneAsync(arrayFilter, update);
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Computes the rank for a stand.
        /// </summary>
        protected override double ComputeRank(Stand stand, int i)
        {
            SiteVars.ReInitialize();
            //if (SiteVars.CFSFuelType == null)
            //    throw new System.ApplicationException("Error: CFS Fuel Type NOT Initialized.  Fuel extension MUST be active.");

            double standFireRisk = 0.0;
            //Model.Core.UI.WriteLine("Base Harvest: EconomicRank.cs: ComputeRank:  there are {0} sites in this stand.", stand.SiteCount);
            foreach (ActiveSite site in stand) {

                //double siteFireRisk = 0.0;
                int fuelType = SiteVars.CFSFuelType[site];
                //Model.Core.UI.WriteLine("Base Harvest: ComputeRank:  FuelType = {0}.", fuelType);
                FireRiskParameters rankingParameters = rankTable[fuelType];
                standFireRisk = (double)rankingParameters.Rank;

                //foreach (ISpeciesCohorts speciesCohorts in SiteVars.Cohorts[site])
                //{
                //    FireRiskParameters rankingParameters = rankTable[speciesCohorts.Species];
                //    foreach (ICohort cohort in speciesCohorts) {
                //        if (rankingParameters.MinimumAge > 0 &&
                //            rankingParameters.MinimumAge <= cohort.Age)
                //            siteEconImportance += (double) rankingParameters.Rank / rankingParameters.MinimumAge * cohort.Age;
                //    }
                //}
                //standEconImportance += siteEconImportance;
            }
            standFireRisk /= stand.SiteCount;

            return standFireRisk;
        }
示例#7
0
        public static int CountTool(Tool tool, Party party, Stand currentStand)
        {
            int counter = 0;

            using (var db = new PartyContext())
            {
                var parties = db.parties.Where(x => (party.Date.CompareTo(x.ToDate) <= 0 && x.Date.CompareTo(party.Date) < 0) || (party.ToDate.CompareTo(x.Date) >= 0 && x.ToDate.CompareTo(party.ToDate) >= 0) || (party.Date.CompareTo(x.Date) <= 0 && party.ToDate.CompareTo(x.ToDate) > 0)).ToList <Party>();
                foreach (Party tmp in parties)
                {
                    foreach (Stand stand in GetStandsByID(tmp.StandsIDs))
                    {
                        if (stand.StandId != currentStand.StandId)
                        {
                            List <string> toolsIds = stand.ToolsAsStrings.Split(',').ToList();
                            counter += toolsIds.Where(x => x.Equals(tool.ToolId.ToString())).Count();
                        }
                    }
                }
                if (currentStand.ToolsAsStrings != null)
                {
                    Debug.WriteLine(currentStand.ToolsAsStrings);
                    List <string> tmp2 = currentStand.ToolsAsStrings.Split(',').ToList();
                    counter += tmp2.Where(x => x.Equals(tool.ToolId.ToString())).Count();
                }
            }
            return(counter);
        }
示例#8
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            CalculatedStyle dims          = base.GetDimensions();
            Vector2         MousePosition = new Vector2((float)Main.mouseX, (float)Main.mouseY);

            if (this.ContainsPoint(MousePosition))
            {
                Main.LocalPlayer.mouseInterface = true;
            }

            Stand stand = TBARPlayer.Get().PlayerStand;

            bool existsAndMatches = stand != null && stand.StandName == StandDisplayName;

            Texture2D texture = existsAndMatches ? Textures.StandCardCurrent : Textures.StandCard;

            spriteBatch.Draw(texture, dims.Position(), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);

            /*if (!Unlocked)
             * {
             *  spriteBatch.Draw(Textures.Instance.SCUnknown, dims.Position() + new Vector2(70), null, Color.White, 0f, new Vector2(Textures.SCUnknown.Width / 2, Textures.SCUnknown.Height / 2), 1f, SpriteEffects.None, 1f);
             *  Utils.DrawBorderString(spriteBatch, "???", dims.Position() + new Vector2(56, 160), Color.White);
             * }
             *
             * if (Unlocked)
             * {*/
            Vector2 anchor = dims.Position() + new Vector2(16, 160);

            spriteBatch.Draw(Idle.SpriteSheet, dims.Position() + new Vector2(70), Idle.FrameRect, Color.White, 0f, Idle.FrameCenter, 1f, SpriteEffects.FlipHorizontally, 1f);
            Utils.DrawBorderString(spriteBatch, StandDisplayName, anchor, Color.White, 1);
            //}
        }
示例#9
0
        public void GetRecipeUpdate(Stand stand)
        {
            bool stayOnRecipeUpdate = false;

            Messages.PrintRecipeHeader();
            Messages.PrintEmptyLine();
            Messages.PrintCurrentRecipe(stand.recipe);

            string yesOrNo = Validation.GetData("Do you want to adjust the recipe and/or your price per cup? (yes/no)", new Regex(regexYesOrNo));

            if (yesOrNo == "yes")
            {
                stayOnRecipeUpdate = true;
            }

            while (stayOnRecipeUpdate)
            {
                Messages.PromptForRecipe();
                stand.recipe.lemonsPerCup     = Convert.ToDouble(Validation.GetData("How many LEMONS do you want in each cup of lemonade?", new Regex(regexDecimalNumbersString)));
                stand.recipe.sugarCubesPerCup = Convert.ToDouble(Validation.GetData("How many SUGAR CUBES do you want in each cup of lemonade?", new Regex(regexDecimalNumbersString)));
                stand.recipe.iceCubesPerCup   = Convert.ToDouble(Validation.GetData("How many ICE CUBES do you want in each cup of lemonade?", new Regex(regexDecimalNumbersString)));
                stand.recipe.price            = Convert.ToDouble(Validation.GetData("How much do you want to charge for each cup of lemonade?", new Regex(regexDecimalNumbersString)));
                Messages.PrintEmptyLine();
                Messages.PrintRecipeUpdated();
                Messages.PrintCurrentRecipe(stand.recipe);

                stayOnRecipeUpdate = false;
            }
            ;
        }
        //---------------------------------------------------------------------

        bool IRequirement.MetBy(Stand stand)
        {
			//PlugIn.ModelCore.UI.WriteLine("checking stand {0}", stand.MapCode);
			//get list of neighboring stands (must cast from enum)
			List<Stand> neighbor_stands = new List<Stand>();
			neighbor_stands = (List<Stand>) stand.Neighbors;
			//add ma_neighbors to this list as well, to check with all the neighboring stands that are in a different management area
			foreach (Stand n_stand in stand.MaNeighbors) {
				neighbor_stands.Add(n_stand);
			}
			//loop through neighbor stands (including ma_neighbors), if one is too young then return false
			foreach (Stand n_stand in neighbor_stands) {
				//if n_stand is too young, return false (breaking out of loop as soon as one neighbor fails)
				if (type == "StandAge") {
					if (n_stand.Age < time) {
						return false;
					}
				}
				//if type was mintimesincelastharvest
				else {
					if (n_stand.TimeSinceLastHarvested < time) {
						//PlugIn.ModelCore.UI.WriteLine("stand {0} NOT ranked.", stand.MapCode);
						return false;
					}
				}
			}
			return true;
        }
示例#11
0
        public void SetStand(Stand stand)
        {
            Stand            = stand;
            StandDisplayName = Stand.StandName;

            Idle = Stand.AlbumEntryAnimation();
        }
示例#12
0
        public IActionResult Register([FromBody] Stand stand)
        {
            try
            {
                if (string.IsNullOrEmpty(stand.Url) || string.IsNullOrEmpty(stand.Name))
                {
                    return(BadRequest());
                }

                if (_db.Stands == null || _db.Stands != null &&
                    _db.Stands.Any(d => d.Name == stand.Name && d.Url == stand.Url))
                {
                    return(BadRequest("The stand had already added!"));
                }
                _db.Stands.Add(new Stand {
                    Name = stand.Name, Url = stand.Url
                });

                _db.SaveChanges();
                return(Ok());
            }
            catch
            {
                return(BadRequest());
            }
        }
示例#13
0
 void Awake()
 {
     vStand  = GameObject.FindWithTag("stand");
     vStandS = vStand.GetComponent <Stand>();
     vTarget = vStandS.vNode;
     //vStandS.GiveTarget(this);
 }
        //---------------------------------------------------------------------

        //require that the stand wait a certain minimum time before being
        //eligible for harvesting again.
        bool IRequirement.MetBy(Stand stand)
        {
            //Model.Core.UI.WriteLine("stand {0} TimeLastHarvested = {1}", stand.MapCode, stand.TimeLastHarvested);
            int time_since = Model.Core.CurrentTime - stand.TimeLastHarvested;
            //Model.Core.UI.WriteLine("time_since stand {0} was harvested = {1}\n", stand.MapCode, time_since);
            return time_since >= minTime;
        }
示例#15
0
        public async Task <Stand> Create(Stand stand)
        {
            stand.Id = null;
            await this.DatabaseContext.Stand.AddAsync(stand);

            return(stand);
        }
        /// <summary>
        /// Reads the input map of stands.
        /// </summary>
        /// <param name="path">
        /// Path to the map.
        /// </param>
        public static void ReadMap(string path)
        {
            Dictionary<ushort, Stand> stands = new Dictionary<ushort, Stand>();

            IInputRaster<MapCodePixel> map = Model.Core.OpenRaster<MapCodePixel>(path);
            using (map) {
                // TODO: make sure its dimensions match landscape's dimensions
                foreach (Site site in Model.Core.Landscape.AllSites) {
                    MapCodePixel pixel = map.ReadPixel();
                    //  Process the pixel only if the site is active and it's
                    //  in an active management area.
                    if (site.IsActive && SiteVars.ManagementArea[site] != null) {
                        ushort mapCode = pixel.Band0;
                        Stand stand;
                        if (stands.TryGetValue(mapCode, out stand)) {
                            if (SiteVars.ManagementArea[site] != stand.ManagementArea)
                                throw new PixelException(site.Location,
                                                         "Stand {0} is in management areas {1} and {2}",
                                                         stand.MapCode,
                                                         stand.ManagementArea.MapCode,
                                                         SiteVars.ManagementArea[site].MapCode);
                        }
                        else {
                            stand = new Stand(mapCode);
                            SiteVars.ManagementArea[site].Add(stand);
                            stands[mapCode] = stand;
                        }
                        stand.Add((ActiveSite) site);
                    }
                }
            }
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Adds a stand's unharvested neighbors and their rankings to a
        /// sorted list of stand rankings.
        /// </summary>
        /// <remarks>
        /// The stand rankings are in highest to lowest order.  A neighbor is
        /// only added to the list if its rank is > 0 and it isn't already in
        /// the list.
        /// </remarks>
        public void AddUnharvestedNeighbors(Stand              stand,
                                            List<StandRanking> neighborRankings)
        {
            foreach (Stand neighbor in stand.Neighbors) {
                if (! neighbor.Harvested) {
                    bool inList = false;
                    foreach (StandRanking ranking in neighborRankings) {
                        if (ranking.Stand == neighbor) {
                            inList = true;
                            break;
                        }
                    }
                    if (inList)
                        continue;

                    StandRanking neighborRanking = GetRanking(neighbor);
                    if (neighborRanking.Rank <= 0)
                        continue;

                    int i;
                    for (i = 0; i < neighborRankings.Count; i++) {
                        if (neighborRankings[i].Rank < neighborRanking.Rank)
                            break;
                    }
                    neighborRankings.Insert(i, neighborRanking);
                }
            }
        }
示例#18
0
        // todo: write tests for DetermineTodaySales on if there is/isn't enough inventory
        // todo: write test for inventory decreases based on recipe
        // todo: make test private and fix test
        public double DetermineTodaySales(Stand stand)
        {
            int cupsToBuyTotal = 0;

            foreach (var customer in customers)
            {
                int thisCustomerWillBuy = DetermineCupsCustomerWillBuyWithLimitedInventory(stand, customer);

                if (stand.inventory.IsEnoughInventory(stand.recipe))
                {
                    if (CheckWeatherConditionsContained(customer.preferredWeatherConditions))
                    {
                        stand.inventory.ReduceInventoryByCurrentRecipe(thisCustomerWillBuy, stand.recipe);
                        cupsToBuyTotal += thisCustomerWillBuy;
                    }
                }
                else
                {
                    uIProvider.SoldOutOfInventory(stand);
                    break;
                }
            }

            uIProvider.ReportTotalCupsSold(cupsToBuyTotal);

            return(cupsToBuyTotal * stand.recipe.price);
        }
        /// <summary>
        /// Reads the input map of stands.
        /// </summary>
        /// <param name="path">
        /// Path to the map.
        /// </param>
        public static void ReadMap(string path)
        {
            Stand stand;
            Dictionary<uint, Stand> stands = new Dictionary<uint, Stand>();

            IInputRaster<UIntPixel> map;

            try
            {
                map = Model.Core.OpenRaster<UIntPixel>(path);
            }
            catch (FileNotFoundException)
            {
                string mesg = string.Format("Error: The file {0} does not exist", path);
                throw new System.ApplicationException(mesg);
            }

            if (map.Dimensions != Model.Core.Landscape.Dimensions)
            {
                string mesg = string.Format("Error: The input map {0} does not have the same dimension (row, column) as the ecoregions map", path);
                throw new System.ApplicationException(mesg);
            }

            using (map) {

                UIntPixel pixel = map.BufferPixel;
                foreach (Site site in Model.Core.Landscape.AllSites)
                {
                    map.ReadBufferPixel();
                    uint mapCode = pixel.MapCode.Value;
                    if (site.IsActive && SiteVars.ManagementArea[site] != null)
                    {
                        if (stands.TryGetValue(mapCode, out stand)) {
                            //if the stand is already in the dictionary, check if it is in the same management area.
                            //if it's not in the same MA, throw exception.
                            if (SiteVars.ManagementArea[site] != stand.ManagementArea) {
                                string mesg = string.Format("Stand {0} is in management areas {1} and {2}",
                                    stand.MapCode,
                                    stand.ManagementArea.MapCode,
                                    SiteVars.ManagementArea[site].MapCode);
                                throw new System.ApplicationException(mesg);
                            }

                        }
                        //valid site location which has not been keyed by the dictionary.
                        else {
                            //assign stand (trygetvalue set it to null when it wasn't found in the dictionary)
                            stand = new Stand(mapCode);
                            //add this stand to the correct management area (pointed to by the site)
                            SiteVars.ManagementArea[site].Add(stand);
                            stands[mapCode] = stand;
                        }
                        //add this site to this stand
                        stand.Add((ActiveSite) site);
                    }
                }

            }
        }
示例#20
0
        public Seller(Stand stand)
        {
            _stand = stand ?? throw new ArgumentNullException("Stand can't be null");
            _stand.OnStandOpening += _stand_OnStandOpening;
            _stand.OnStandClosing += _stand_OnStandClosing;

            _isWorkTimeLocker = new object();
        }
示例#21
0
        public ActionResult DeleteConfirmed(int id)
        {
            Stand stand = db.Tb_Stand.Find(id);

            db.Tb_Stand.Remove(stand);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#22
0
        //---------------------------------------------------------------------

        //require that the stand wait a certain minimum time before being
        //eligible for harvesting again.
        bool IRequirement.MetBy(Stand stand)
        {
            //Model.Core.UI.WriteLine("stand {0} TimeLastHarvested = {1}", stand.MapCode, stand.TimeLastHarvested);
            int time_since = Model.Core.CurrentTime - stand.TimeLastHarvested;

            //Model.Core.UI.WriteLine("time_since stand {0} was harvested = {1}\n", stand.MapCode, time_since);
            return(time_since >= minTime);
        }
示例#23
0
 private void Stand_Click(object sender, EventArgs e)
 {
     I.Write("Fold$");
     Thread.Sleep(500);
     I.Write("Stand$");
     Stand.Hide();
     Sit.Show();
 }
        public void GetStand_ContainsStand_ExpectStand()
        {
            Stand randomStand             = standControl.GetRandom();
            ActionResult <StandDto> stand = standBoundary.GetStand(randomStand.Guid);

            Assert.Equal(randomStand.Name, stand.Value.Name);
            Assert.Equal(randomStand.Guid, stand.Value.Guid);
        }
示例#25
0
 public static void PrintCurrentInventory(Stand stand)
 {
     Print("Your current inventory is:");
     Print($"You have {stand.inventory.lemons.quantity} lemons.");
     Print($"You have {stand.inventory.sugarCubes.quantity} sugar cubes.");
     Print($"You have {stand.inventory.iceCubes.quantity} ice cubes.");
     Print($"You have {stand.inventory.cups.quantity} cups.");
 }
        public void GetRandomStand_ContainsStands_ExpectStand()
        {
            Stand randomStand = standControl.GetRandom();

            Assert.NotNull(randomStand);

            Assert.Contains(randomStand, standControl.All());
        }
示例#27
0
        private void BuyProductsFromStand(Stand stand)
        {
            Random rnd = new Random();

            _productsCount = rnd.Next(ProgramConfig.BuyerConfig.MinNumbersOfProducts, ProgramConfig.BuyerConfig.MaxNumbersOfProducts);
            SetCurrentStand(stand, _productsCount);
            stand.AddBuyerToQueue(this);
        }
示例#28
0
    private void Start()
    {
        m_lever      = GameObject.Find("Lever").GetComponent <Lever>();
        m_stand      = GameObject.Find("Stand").GetComponent <Stand>();
        m_cargoPanel = GameObject.Find("CargoPanel").GetComponent <CargoPanel>();

        m_level = 1;
    }
示例#29
0
 public Product(string brand, string model, int id, double price, Stand stand)
 {
     _brand     = brand;
     _model     = model;
     _productID = id;
     _price     = price;
     _stand     = stand.ToString();
 }
示例#30
0
 private void SetCurrentStand(Stand stand, int productCount)
 {
     _currentStand = stand;
     if (ProgramConfig.BuyerConfig.ShowBuyerLogInConsole)
     {
         ConsoleHelper.WriteInfo(String.Format("\nBuyer {0} say:\nI am coming to stand with {1}s.", _guid.ToString(), stand.Product.Name) +
                                 String.Format(" I want to buy {0} {1}(s).", productCount, stand.Product.Name));
     }
 }
        //---------------------------------------------------------------------
        //mark the whole area selected as harvested
        IEnumerable<ActiveSite> ISiteSelector.SelectSites(Stand stand)
        {
            areaSelected = stand.ActiveArea;
            stand.MarkAsHarvested();
            //mark this stand's event id
            stand.EventId = EventId.MakeNewId();

            return stand;
        }
示例#32
0
        public void Construct_CreateStandWithoutProducts_ExpectStand()
        {
            Coordinate coordinates = new Coordinate(1.2, 2.2);
            Stand      stand       = new Stand("Stand 1", coordinates, new List <Product>());

            Assert.Equal("Stand 1", stand.Name);
            Assert.Equal(coordinates, stand.Coordinates);
            Assert.Empty(stand.Meals);
            Assert.Empty(stand.Drinks);
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Gets the ranking for an unharvested stand from among the whole set
        /// of stand rankings.
        /// </summary>
        public StandRanking GetRanking(Stand stand)
        {
            //  Search backward through the stand rankings because unharvested
            //  stands are at the end of the list.
            for (int i = rankings.Length - 1; i >= 0; i--) {
                if (rankings[i].Stand == stand)
                    return rankings[i];
            }
            throw new System.ApplicationException("ERROR: Stand not found in rankings");
        }
示例#34
0
 public void SoldOutOfInventory(Stand stand)
 {
     Messages.PrintEmptyLine();
     Messages.PrintDashedLine();
     Messages.PrintOutOfInventory();
     Messages.PrintEmptyLine();
     Messages.PrintCurrentInventory(stand);
     Messages.PrintDashedLine();
     Messages.PrintEmptyLine();
 }
示例#35
0
 public ActionResult Edit([Bind(Include = "Stand_id,StandTypeId,EnterpriseLogo,EnterpriseBanner,StandColorA,StandColorB,StandColorC,Available")] Stand stand)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stand).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StandTypeId = new SelectList(db.Tb_Stand_Type, "StandType", "StandName", stand.StandTypeId);
     return(View(stand));
 }
示例#36
0
 private void LeaveCurrentStand()
 {
     if (_currentStand != null)
     {
         if (ProgramConfig.BuyerConfig.ShowBuyerLogInConsole)
         {
             ConsoleHelper.WriteInfo(String.Format("\nBayer {0} say:\nI am leaving the stand with {1}s.", _guid.ToString(), _currentStand.Product.Name));
         }
         _currentStand = null;
     }
 }
示例#37
0
        private int DetermineCupsCustomerWillBuyWithLimitedInventory(Stand stand, ICustomer customer)
        {
            int thisCustomerWillBuy = customer.HowManyCupsWillCustomerPurchase(stand.recipe.price);

            while (!stand.inventory.IsEnoughInventory(stand.recipe, thisCustomerWillBuy) && thisCustomerWillBuy > 0)
            {
                thisCustomerWillBuy -= 1;
            }

            return(thisCustomerWillBuy);
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Harvests a stand (and possibly its neighbors) according to the
        /// repeat-harvest's site-selection method.
        /// </summary>
        /// <returns>
        /// The area that was harvested (units: hectares).
        /// </returns>
        public override double Harvest(Stand stand)
        {
            double areaHarvested = base.Harvest(stand);

            harvestedStands.Clear();
            harvestedStands.Add(stand);
            if (spreadingSiteSelector != null)
                harvestedStands.AddRange(spreadingSiteSelector.HarvestedNeighbors);

            return areaHarvested;
        }
示例#39
0
        public override void Initialize()
        {
            _activeStandProjectile = default;

            //AuraAnimationKey = (int)AuraAnimationType.None;

            MaxStamina = 100;
            Stamina    = MaxStamina;

            UnlockedStands = new List <string>();
        }
        //---------------------------------------------------------------------
        //mark the whole area selected as harvested
        IEnumerable<ActiveSite> ISiteSelector.SelectSites(Stand stand)
        {
            areaSelected = stand.ActiveArea;
            stand.MarkAsHarvested();
			//mark this stand's event id
			stand.EventId = PlugIn.EventId;
			
			//increment global event id number
			PlugIn.EventId++;
			
            return stand;
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Harvests a stand (and possibly its neighbors) according to the
        /// repeat-harvest's site-selection method.
        /// </summary>
        /// <returns>
        /// The area that was harvested (units: hectares).
        /// </returns>
        public override double Harvest(Stand stand)
        {
            if (stand.IsSetAside) {
                CohortSelector = additionalCohortSelector;
                SpeciesToPlant = additionalSpeciesToPlant;
            }
            else {
                CohortSelector = initialCohortSelector;
                SpeciesToPlant = initialSpeciesToPlant;
            }
            return base.Harvest(stand);
        }
        //---------------------------------------------------------------------

        public IEnumerable<ActiveSite> SelectSites(Stand stand)
        {
            foreach (ActiveSite activeSite in originalSelector.SelectSites(stand)) {
                yield return activeSite;

                //  At this point, a prescription is done harvesting the
                //  site with age-only cohort selectors.  See if any
                //  specific-age cohort selectors have flagged some cohorts
                //  for partial thinning.
                PartialHarvestDisturbance.ReduceCohortBiomass(activeSite);
            }
        }
示例#43
0
        public void Init(decimal intialAssets = 2.0M)
        {
            TitlePage();
            int numPlayers = GetPlayerCount();

            Stands = new Stand[numPlayers];
            for (int i = 0; i < numPlayers; i++)
            {
                Stands[i] = new Stand(i + 1, intialAssets);
            }
            PrintIntro(intialAssets);
        }
        //---------------------------------------------------------------------

        IEnumerable<ActiveSite> ISiteSelector.SelectSites(Stand stand)
        {
            IEnumerable<ActiveSite> selectedSites = (IEnumerable<ActiveSite>) baseClassSelectSites.Invoke(this, new object[] {stand});
            foreach (ActiveSite activeSite in selectedSites) {
                yield return activeSite;

                //  At this point, a prescription is done harvesting the
                //  site with age-only cohort selectors.  See if any
                //  specific-age cohort selectors have flagged some cohorts
                //  for partial thinning.
                PartialHarvestDisturbance.ReduceCohortBiomass(activeSite, stand);
            }
        }
        //---------------------------------------------------------------------

        public IEnumerable<ActiveSite> SelectSites(Stand stand)
        {
            //PlugIn.ModelCore.Log.WriteLine("Site Selector Wrapper");

            foreach (ActiveSite activeSite in originalSelector.SelectSites(stand)) {
                
                //  At this point, a prescription is done harvesting the
                //  site with age-only cohort selectors.  See if any
                //  specific-age cohort selectors have flagged some cohorts
                //  for partial thinning.
                PartialHarvestDisturbance.ReduceCohortBiomass(activeSite, stand);
                
                yield return activeSite;

            }
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Computes the rank for a stand.
 /// </summary>
 /// <remarks>
 /// Stands are ranked by age class so that over time harvesting will
 /// result in an even distribution of sites by age classes.
 /// </remarks>
 protected override double ComputeRank(Stand stand, int i)
 {
     double freq = 0.0;
     //find where the stands of this age are in the array
     //and return that frequency from the freq_array
     int k = 0;
     for (k = 0; k < age_count; k++) {
         if (stand.Age == age_array[k]) {
             freq = freq_array[k];
             //Model.Core.UI.WriteLine("stand {0}.\nreturning age = {1} and freq = {2}", stand.MapCode, age_array[k], freq);
             //break loop when freq for this stand has been found
             break;
         }
     }
     //rank = freq * e^(age / 10) <-- using age / 10 to get a smaller number
     return freq * (System.Math.Exp(stand.Age / 10));
 }
        //---------------------------------------------------------------------

        public void WriteLogEntry(Stand stand)
        {
            int totalSites = 0;
            int damagedSites = 0;
            int cohortsKilled = 0;
            foreach (ActiveSite site in stand) {
                totalSites++;
                int cohortsKilledAtSite = SiteVars.CohortsKilled[site];
                cohortsKilled += cohortsKilledAtSite;
                if (cohortsKilledAtSite > 0)
                    damagedSites++;
            }

            log.WriteLine("{0},{1},{2},{3},{4}",
                          Model.Core.CurrentTime, stand.MapCode,
                          totalSites, damagedSites, cohortsKilled);
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Computes the rank for a stand.
        /// </summary>
        protected override double ComputeRank(Stand stand)
        {
            double standEconImportance = 0.0;

            foreach (ActiveSite site in stand) {
                double siteEconImportance = 0.0;
                foreach (ICohort cohort in Model.LandscapeCohorts[site]) {
                    EconomicRankParameters rankingParameters = rankTable[cohort.Species];
                    if (rankingParameters.MinimumAge > 0 &&
                        rankingParameters.MinimumAge <= cohort.Age)
                        siteEconImportance += (double) rankingParameters.Rank / rankingParameters.MinimumAge * cohort.Age;
                }
                standEconImportance += siteEconImportance;
            }
            standEconImportance /= stand.SiteCount;

            return standEconImportance;
        }
        //---------------------------------------------------------------------

        public IEnumerable<ActiveSite> SelectSites(Stand stand)
        {
            foreach (ActiveSite activeSite in originalSelector.SelectSites(stand)) {
                
                //  At this point, a prescription is done harvesting the
                //  site with age-only cohort selectors.  See if any
                //  specific-age cohort selectors have flagged some cohorts
                //  for partial thinning.
                PartialHarvestDisturbance.ReduceCohortBiomass(activeSite, stand);
                
                //if(BaseHarvest.SiteVars.CohortsDamaged[currentSite] <= 0)  // don't double count
                //Landis.Harvest.SiteVars.Stand[activeSite].LastAreaHarvested += Model.Core.CellArea;
                
                
                yield return activeSite;

            }
        }
        //---------------------------------------------------------------------

        //require that the stand's neighbors are of a certain minimum age 
        //before this stand can be harvested.
        bool IRequirement.MetBy(Stand stand)
        {
            //initially declare stand available for ranking
            bool allow_rank = true;
            //loop through stand's neighbors.
            //if any of the stand's neighbors are too young,
            //don't rank this stand (set rank = 0)
            foreach (Stand neighbor in stand.Neighbors) {
                //Model.Core.UI.WriteLine("neighbor {0} age = {1}", neighbor.MapCode, neighbor.Age);
                if (neighbor.Age < minAge) {
                    //don't allow stand to be ranked
                    allow_rank = false;
                    break;
                }
            }
            //return allow_rank.  if false, stand will be ranked 0
            //Model.Core.UI.WriteLine("stand {0} allow_rank = {1}", stand.MapCode, allow_rank);
            return allow_rank;
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Harvests a stand (and possibly its neighbors) according to the
        /// repeat-harvest's site-selection method.
        /// </summary>
        /// <returns>
        /// The area that was harvested (units: hectares).
        /// </returns>
        public override void Harvest(Stand stand)
        {
            if (stand.IsSetAside) {
                CohortCutter = additionalCohortCutter;
                SpeciesToPlant = additionalSpeciesToPlant;
                SiteSelector = additionalSiteSelector; // new CompleteStand();
                //
                //if(this.SiteSelectionMethod.GetType() == Landis.Extension.BiomassHarvest.PartialStandSpreading)
                //  SiteSelector = BiomassHarvest.WrapSiteSelector(SiteSelector);

            }
            else {
                CohortCutter = initialCohortSelector;
                SpeciesToPlant = initialSpeciesToPlant;
            }
            base.Harvest(stand);

            return;
        }
        /// <summary>
        /// Reads the input map of stands.
        /// </summary>
        /// <param name="path">
        /// Path to the map.
        /// </param>

        public static void ReadMap(string path) {
            Stand stand;
            Dictionary<ushort, Stand> stands = new Dictionary<ushort, Stand>();

            IInputRaster<MapCodePixel> map = Model.Core.OpenRaster<MapCodePixel>(path);
            using (map) {
            
                //loop through every single site in management area, assigning them to a stand.
                foreach (Site site in Model.Core.Landscape.AllSites) {
                    MapCodePixel pixel = map.ReadPixel();
                     //  Process the pixel only if the site is active and it's
                    //  in an active management area.
                    if (site.IsActive && SiteVars.ManagementArea[site] != null) {
                        ushort mapCode = pixel.Band0;
                        //check if this stand is already in the dictionary
                        if (stands.TryGetValue(mapCode, out stand)) {
                            //if the stand is already in the dictionary, check if it is in the same management area.
                            //if it's not in the same MA, throw exception.
                            if (SiteVars.ManagementArea[site] != stand.ManagementArea) {
                                throw new PixelException(site.Location,
                                "Stand {0} is in management areas {1} and {2}",
                                stand.MapCode,
                                stand.ManagementArea.MapCode,
                                SiteVars.ManagementArea[site].MapCode);
                            }
                        
                        }
                        //valid site location which has not been keyed by the dictionary.
                        else {
                            //assign stand (trygetvalue set it to null when it wasn't found in the dictionary)
                            stand = new Stand(mapCode);
                            //add this stand to the correct management area (pointed to by the site)
                            SiteVars.ManagementArea[site].Add(stand);
                            stands[mapCode] = stand;
                        }                        
                        //add this site to this stand
                        stand.Add((ActiveSite) site);
                    }
                }
                
            }
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Harvests a stand (and possibly its neighbors) according to the
        /// repeat-harvest's site-selection method.
        /// </summary>
        /// <returns>
        /// The area that was harvested (units: hectares).
        /// </returns>
        public override void Harvest(Stand stand)
        {
            if (stand.IsSetAside)
            {
                SiteSelector = additionalSiteSelector;
            }
            
            base.Harvest(stand);
            
            harvestedStands.Clear();

            //  Add stand to list only if actually harvested
            if(stand.LastAreaHarvested > 0)
                harvestedStands.Add(stand); 
            
            if (spreadingSiteSelector != null)
                harvestedStands.AddRange(spreadingSiteSelector.HarvestedNeighbors);
            
            return; // areaHarvested;
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Computes the rank for a stand.
        /// </summary>
        protected override double ComputeRank(Stand stand, int i)
        {
            double standEconImportance = 0.0;
            //UI.WriteLine("there are {0} sites in this stand.", stand.SiteCount);
            foreach (ActiveSite site in stand) {

                double siteEconImportance = 0.0;
                foreach (ISpeciesCohorts speciesCohorts in Model.LandscapeCohorts[site]) {
                    EconomicRankParameters rankingParameters = rankTable[speciesCohorts.Species];
                    foreach (ICohort cohort in speciesCohorts) {
                        if (rankingParameters.MinimumAge > 0 &&
                            rankingParameters.MinimumAge <= cohort.Age)
                            siteEconImportance += (double) rankingParameters.Rank / rankingParameters.MinimumAge * cohort.Age;
                    }
                }
                standEconImportance += siteEconImportance;
            }
            standEconImportance /= stand.SiteCount;

            return standEconImportance;
        }
        //---------------------------------------------------------------------

        bool IRequirement.MetBy(Stand stand)
        {
            int sumTimeOfNext = 0;
            int siteCount = 0;
            if (SiteVars.NextBDA == null)
            {
                return false;
            }
            else
            {
                foreach (ActiveSite site in stand)
                {
                    int timeOfNext = SiteVars.NextBDA[site];
                    siteCount += 1;
                    sumTimeOfNext += timeOfNext;
                }

                double avgTimeOfNext = (double)sumTimeOfNext / (double)siteCount;

                return avgTimeOfNext <= (PlugIn.ModelCore.CurrentTime + presalvYears);

            }
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Computes the rank for a stand.
        /// </summary>
        /// <remarks>
        /// The stand's rank is its age.
        /// </remarks>
        protected override double ComputeRank(Stand stand, int i)
        {
            return stand.Age;
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Adds a stand to the management area.
        /// </summary>
        public void Add(Stand stand)
        {
            stands.Add(stand);
            area += stand.ActiveArea;
            //PlugIn.ModelCore.Log.WriteLine("ma {0} now has area {1}", mapCode, area);
            stand.ManagementArea = this;
        }
        //---------------------------------------------------------------------
        public void WriteLogEntry(ManagementArea mgmtArea, Stand stand)
        {
            int damagedSites = 0;
            int cohortsDamaged = 0;
            int standPrescriptionNumber = 0;

            foreach (ActiveSite site in stand) {
                //set the prescription name for this site
                if (SiteVars.Prescription[site] != null)
                {
                    standPrescriptionNumber = SiteVars.Prescription[site].Number;
                    SiteVars.PrescriptionName[site] = SiteVars.Prescription[site].Name;
                    SiteVars.TimeOfLastEvent[site] = PlugIn.ModelCore.CurrentTime;
                }
                int cohortsDamagedAtSite = SiteVars.CohortsDamaged[site];
                cohortsDamaged += cohortsDamagedAtSite;
                if (cohortsDamagedAtSite > 0) {
                    damagedSites++;
                }
            }


            totalSites[standPrescriptionNumber] += stand.SiteCount;
            totalDamagedSites[standPrescriptionNumber] += damagedSites;

            //csv string for log file, contains species kill count
            string species_count = "";

            //if this is the right species match, add it's count to the csv string
            foreach (ISpecies species in PlugIn.ModelCore.Species)
            {
                bool assigned = false;

                //loop through dictionary of species kill count
                foreach (KeyValuePair<string, int> kvp in stand.DamageTable) {
                    if (species.Name == kvp.Key) {
                        assigned = true;
                        species_count += kvp.Value + ",";
                        totalSpeciesCohorts[standPrescriptionNumber, species.Index] += kvp.Value;
                    }
                }
                if (!assigned) {
                    //put a 0 there if it's not assigned (because none were found in the dictionary)
                    species_count += "0,";
                }
            }

            //now that the damage table for this stand has been recorded, clear it!!
            stand.ClearDamageTable();

            //write to log file:
                //current time
                //management area's map code
                //the prescription that caused this harvest
                //stand's map code
                //stand's age
                //stand's current rank
                //total sites in the stand
                //damaged sites from this stand
                //cohorts killed in this stand, by this harvest
            //and only record stands where a site has been damaged
            log.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}",
                          PlugIn.ModelCore.CurrentTime, mgmtArea.MapCode, stand.PrescriptionName, stand.MapCode, stand.EventId,
                          stand.Age, stand.HarvestedRank, stand.SiteCount, damagedSites, cohortsDamaged, species_count);


        }
        //---------------------------------------------------------------------

        public void WriteLogEntry(ManagementArea mgmtArea, Stand stand)
        {
            int damagedSites = 0;
            int cohortsDamaged = 0;
            int cohortsKilled = 0;
            int standPrescriptionNumber = 0;
            double biomassRemoved = 0.0;
            double biomassRemovedPerHa = 0.0;
            //ModelCore.UI.WriteLine("BiomassHarvest:  PlugIn.cs: WriteLogEntry: mgmtArea {0}, Stand {1} ", mgmtArea.Prescriptions.Count, stand.MapCode);

            foreach (ActiveSite site in stand) {
                //set the prescription name for this site
                if (BaseHarvest.SiteVars.Prescription[site] != null)
                {
                    standPrescriptionNumber = BaseHarvest.SiteVars.Prescription[site].Number;
                    BaseHarvest.SiteVars.PrescriptionName[site] = BaseHarvest.SiteVars.Prescription[site].Name;
                    BaseHarvest.SiteVars.TimeOfLastEvent[site] = modelCore.CurrentTime;
                }

                cohortsDamaged += SiteVars.CohortsPartiallyDamaged[site];
                cohortsKilled += BaseHarvest.SiteVars.CohortsDamaged[site];


                if (SiteVars.CohortsPartiallyDamaged[site] > 0 ||  BaseHarvest.SiteVars.CohortsDamaged[site] > 0)
                {
                    damagedSites++;

                    //Conversion from [g m-2] to [Mg ha-1] to [Mg]
                    biomassRemoved += SiteVars.BiomassRemoved[site] / 100.0 * modelCore.CellArea;
                }
            }

            totalSites[standPrescriptionNumber] += stand.SiteCount;
            totalDamagedSites[standPrescriptionNumber] += damagedSites;
            totalCohortsDamaged[standPrescriptionNumber] += cohortsDamaged;
            totalCohortsKilled[standPrescriptionNumber] += cohortsKilled;


            //csv string for log file, contains species kill count
            string species_count = "";
            //if this is the right species match, add it's count to the csv string
            foreach (ISpecies species in modelCore.Species) {
                bool assigned = false;

                //loop through dictionary of species kill count
                foreach (KeyValuePair<string, int> kvp in stand.DamageTable) {
                    if (species.Name == kvp.Key) {
                        assigned = true;
                        species_count += "," + kvp.Value;
                        totalSpeciesCohorts[standPrescriptionNumber, species.Index] += kvp.Value;
                    }
                }
                if (!assigned) {
                    //put a 0 there if it's not assigned (because none were found in the dictionary)
                    species_count += ",0";
                    totalSpeciesCohorts[standPrescriptionNumber, species.Index] += 0;
                }
            }

            //now that the damage table for this stand has been recorded, clear it!!
            stand.ClearDamageTable();

            //write to log file:
            biomassRemovedPerHa = biomassRemoved / (double) damagedSites / modelCore.CellArea;

            if(biomassRemoved <= 0.0)
                return;

            log.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9:0.000},{10:0.000},{11},{12}{13}",
                          modelCore.CurrentTime,
                          mgmtArea.MapCode,
                          stand.PrescriptionName,
                          stand.MapCode,
                          stand.EventId,
                          stand.Age,
                          stand.HarvestedRank,
                          stand.SiteCount,
                          damagedSites,
                          biomassRemoved,  // Mg
                          biomassRemovedPerHa, // Mg/ha
                          cohortsDamaged,
                          cohortsKilled,
                          species_count);
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Adds a stand to the management area.
        /// </summary>
        public void Add(Stand stand)
        {
            stands.Add(stand);
            stand.ManagementArea = this;
        }