예제 #1
0
        /// <summary>
        /// Populate the "mat" matrix with values according to the properties
        /// </summary>
        /// <param name="mat">the matrix to manipulate</param>
        private void PopulateMatrix(ref float[][] mat)
        {
            ConnectionMongoDB      db       = ConnectionMongoDB.GetInstance();
            IList <BasketItemsDTO> products = this.m_basket.basketItems;

            for (int i = 0; i < mat.Length; i++)
            {
                // TODO: DB access
                ProductDTO productItem = db.GetProductDTONotFromDBByProductId(products[i].id);
                //ProductDTO productItem = Program.Prodcuts[products[i].id];

                FillProduct(ref mat, i, productItem, db);
            }
        }
예제 #2
0
        private BasketListGenome MutateBasket(BasketListGenome BasketToMutate)
        {
            BasketListGenome  MutatedBasket = BasketToMutate;
            ConnectionMongoDB db            = ConnectionMongoDB.GetInstance();

            if (this.GetRandomNumber(0, 1) <= this.m_mutationFreq)
            {
                for (int i = 0; i < MutatedBasket.BasketObject.basketItems.Count; i++)
                {
                    if (this.GetRandomNumber(0, 1) <= this.m_mutationFreq)
                    {
                        // TODO: DB access
                        MutatedBasket.BasketObject.basketItems[i] = db.GetRandomProduct();
                        //MutatedBasket.BasketObject.basketItems[i] = Program.GetRandomProduct();
                    }
                }
            }

            return(MutatedBasket);
        }
예제 #3
0
        public async Task SaveAsync(Item item)
        {
            var conexaoBiblioteca = new ConnectionMongoDB(configuration);

            await conexaoBiblioteca.Item.InsertOneAsync(item);
        }
예제 #4
0
 public MainController()
 {
     this.db = ConnectionMongoDB.GetInstance();
     this.db.InitMongoClient(ConnectionMongoDB.URL);
 }
예제 #5
0
        private void FillProduct(ref float[][] mat, int i, ProductDTO productItem, ConnectionMongoDB DbConnection)
        {
            mat[i][(int)eFitnessFunctionParams.price]         = productItem.price;
            mat[i][(int)eFitnessFunctionParams.Organic]       = productItem.Organic == true ? TRUE : FALSE;
            mat[i][(int)eFitnessFunctionParams.VeganFriendly] = productItem.VeganFriendly == true ? TRUE : FALSE;
            mat[i][(int)eFitnessFunctionParams.GlutenFree]    = productItem.GlutenFree == true ? TRUE : FALSE;

            mat[i][(int)eFitnessFunctionParams.IsMeat]        = productItem.category == (int)eCategory.MeatAndFish ? TRUE : FALSE;
            mat[i][(int)eFitnessFunctionParams.IsDairy]       = productItem.category == (int)eCategory.MilkAndEggs ? TRUE : FALSE;
            mat[i][(int)eFitnessFunctionParams.IsBabyProduct] = productItem.category == (int)eCategory.Babies ? TRUE : FALSE;

            // whenever the product is kosher
            if (productItem.Kashrut != null && productItem.Kashrut != string.Empty)
            {
                mat[i][(int)eFitnessFunctionParams.Kashrut] = TRUE;
            }
            else
            {
                mat[i][(int)eFitnessFunctionParams.Kashrut] = FALSE;
            }

            // whenever the product is parve
            if (productItem.category != (int)eCategory.MeatAndFish && productItem.category != (int)eCategory.MilkAndEggs)
            {
                mat[i][(int)eFitnessFunctionParams.IsParve] = TRUE;
            }
            else
            {
                mat[i][(int)eFitnessFunctionParams.IsParve] = FALSE;
            }

            // whenever the product is Vegetarian
            if (productItem.category != (int)eCategory.MeatAndFish)
            {
                mat[i][(int)eFitnessFunctionParams.Vegetarian] = TRUE;
            }
            else
            {
                mat[i][(int)eFitnessFunctionParams.Vegetarian] = FALSE;
            }

            // whenever the product is Vegetarian
            if (productItem.name.Contains("סויה") ||
                productItem.name.ToLower().Contains("soy") ||
                productItem.ManufacturerItemDescription.Contains("סויה") ||
                productItem.ManufacturerItemDescription.ToLower().Contains("soy"))
            {
                mat[i][(int)eFitnessFunctionParams.IsSoy] = TRUE;
            }
            else
            {
                mat[i][(int)eFitnessFunctionParams.IsSoy] = FALSE;
            }

            // TODO: DB Access
            List <BasketDTO> allBaskets = DbConnection.GetListBasketByUserName(this.UserName);
            //List<BasketDTO> allBaskets = Program.OldBasketsPerUser[this.UserName];

            int productCounter = 0;

            foreach (BasketDTO CurrBasket in allBaskets)
            {
                foreach (BasketItemsDTO CurrProduct in CurrBasket.basketItems)
                {
                    if (CurrProduct.id == productItem.id)
                    {
                        productCounter++;

                        break;
                    }
                }
            }

            if (allBaskets.Count != 0)
            {
                mat[i][(int)eFitnessFunctionParams.WasInLastBasket] = (float)((float)productCounter) / ((float)allBaskets.Count);
            }
            else
            {
                mat[i][(int)eFitnessFunctionParams.WasInLastBasket] = 0;
            }

            mat[i][(int)eFitnessFunctionParams.GramAmount] = this.GetGramsFromProductAmount(productItem);
        }
        private async Task SaveMongoDB(ReceiveDataLogEntitie log)
        {
            var conexaoBiblioteca = new ConnectionMongoDB(configuration);

            await conexaoBiblioteca.ReciveDataLog.InsertOneAsync(log);
        }