Exemplo n.º 1
0
        public Dictionary <Recipe, ExtraData> sortBasedOnPreferences(int pricepreference, int savingspreference, int numberOfRecipes, int radius, double latitude, double longitude)
        {
            DBController dbc = new DBController();

            // Get all recipes
            List <Recipe> recipes = dbc.GetAllRecipes();

            dbc.Close();

            Dictionary <Recipe, ExtraData> recipesAndPrices      = new Dictionary <Recipe, ExtraData>();
            Dictionary <Recipe, ExtraData> finalRecipesAndPrices = new Dictionary <Recipe, ExtraData>();

            // Get recipes that can be made from nearby stores
            foreach (Recipe recipe in recipes)
            {
                //evaluate each recipe and find the best store for the user with a given set of preferences
                Dictionary <Retailer, ExtraData> recipeData = getExtraData(recipe.GetOrSetId, radius, latitude, longitude);
                recipeData = RangeEvaluator(recipeData, recipeData.Count, pricepreference);
                recipeData = recipeData.OrderBy(x => x.Value.SavingGeneralPrice).ToDictionary(x => x.Key, x => x.Value);
                recipeData = RangeEvaluator(recipeData, recipeData.Count, savingspreference);

                //add the apporiate data to the recipe list, making sure we get the best of each recipe
                recipesAndPrices.Add(recipe, recipeData.OrderBy(x => x.Value.Rating).First().Value);
                recipesAndPrices.Last().Value.Rating = 0;
            }

            //evaluate and sort the data after which recipe scored the highest amount of points
            recipesAndPrices = recipesAndPrices.OrderBy(x => x.Value.Price).ToDictionary(x => x.Key, x => x.Value);
            recipesAndPrices = RangeEvaluator(recipesAndPrices, 100, pricepreference);

            recipesAndPrices = recipesAndPrices.OrderBy(x => x.Value.SavingGeneralPercent).ToDictionary(x => x.Key, x => x.Value);
            recipesAndPrices = RangeEvaluator(recipesAndPrices, 100, savingspreference);

            finalRecipesAndPrices = recipesAndPrices.OrderBy(x => x.Value.Rating).Take(numberOfRecipes).ToDictionary(x => x.Key, x => x.Value);

            return(finalRecipesAndPrices);
        }
Exemplo n.º 2
0
        public RecipeWithExtradata GetRecipesWithExtraData(int pricePreference, int savingsPreference, int numberOfRecipes, int radius, double latitude, double longitude)
        {
            DBController  dbc = new DBController();
            SearchMethods sm  = new SearchMethods();

            WebOperationContext ctx = WebOperationContext.Current;

            try {
                RecipeWithExtradata tempData = new RecipeWithExtradata(sm.sortBasedOnPreferences(pricePreference, savingsPreference, numberOfRecipes, radius, latitude, longitude));
                if (tempData != null)
                {
                    return(tempData);
                }
            } catch (NpgsqlException e) {
                Console.WriteLine((Program.sqlDebugMessages) ? "GetRecipesWithExtraData: " + e.BaseMessage.ToString() : "");
                ctx.OutgoingResponse.StatusCode        = System.Net.HttpStatusCode.Conflict;
                ctx.OutgoingResponse.StatusDescription = e.BaseMessage;
                return(null);
            } finally {
                dbc.Close();
            }
            ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NoContent;
            return(null);
        }
Exemplo n.º 3
0
        public static void ExcelExtractionScript()
        {
            List <string>  Groceries       = new List <string>();
            List <string>  MeasurementType = new List <string>();
            List <decimal> Measure         = new List <decimal>();
            List <decimal> Price           = new List <decimal>();

            int i;

            string  tempString;
            decimal tempValueOne;
            decimal tempValuetwo;

            using (StreamReader reader = new StreamReader(@"C:/Users/Casper/Dropbox/P8/gnmsnit.csv", Encoding.Default)) {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    string[] fields = line.Split(';');


                    Groceries.Add(fields[0]);

                    string[] tempPrice = fields[13].Split('.');

                    tempValueOne = Convert.ToDecimal(tempPrice[0]);
                    tempValuetwo = Convert.ToDecimal(tempPrice[1]) * Convert.ToDecimal(0.01);

                    Price.Add(tempValueOne + tempValuetwo);


                    tempString = fields[1];
                    var measurefields = tempString.Split(' ');

                    if (measurefields.Count() > 1)
                    {
                        if (measurefields[1] == "kg")
                        {
                            MeasurementType.Add("gram");
                            decimal numVal = Convert.ToDecimal(measurefields[0]);
                            Measure.Add(numVal * 1000);
                        }
                        else if (measurefields[1] == "stk")
                        {
                            MeasurementType.Add("stk");
                            decimal numVal = Convert.ToDecimal(measurefields[0]);
                            Measure.Add(numVal);
                        }
                        else if (measurefields[1] == "ltr" || measurefields[1] == "ltr.")
                        {
                            MeasurementType.Add("Deciliter");
                            decimal numVal = Convert.ToDecimal(measurefields[0]);
                            Measure.Add(numVal * 10);
                        }
                        else if (measurefields[1] == "g")
                        {
                            MeasurementType.Add("gram");
                            decimal numVal = Convert.ToDecimal(measurefields[0]);
                            Measure.Add(numVal);
                        }
                        else
                        {
                        }
                    }
                }
            }

            for (i = 1; i < Groceries.Count; i++)
            {
                Console.WriteLine(Groceries[i].ToString());
                DBController dbc = new DBController();
                dbc.AddIngredient(new Ingredient(Groceries[i], MeasurementType[i], (int)Measure[i], Price[i], false, 0.00m, false, null));
                dbc.Close();
            }
        }
Exemplo n.º 4
0
        public Dictionary <Retailer, ExtraData> getExtraData(int recipeId, int radius, double latitude, double longitude)
        {
            decimal NormalPrice      = 0;
            decimal storeNormalPrice = 0;
            decimal price            = 0;
            decimal savingStorePrice;
            decimal savingStorePercent;
            decimal savingGeneralPrice;
            decimal savingGeneralPercent;

            DBController dbc = new DBController();

            Dictionary <Retailer, ExtraData> retailerDictionary = new Dictionary <Retailer, ExtraData>();

            RecipeWithIngredients recipeWithIngredients = dbc.GetRecipeByIdWithIngredients(recipeId);

            List <Retailer> retailers = GetStoresWithinRadius(dbc.GetAllRetailers(), radius, latitude, longitude);

            //finds all retailers within the radius which has an offer on anything on the recipe.
            for (int i = retailers.Count() - 1; i > -1; i--)
            {
                bool found = false;

                foreach (Offers offer in recipeWithIngredients.GetOrSetOffers)
                {
                    if (retailers[i].GetOrSetId == offer.GetOrSetRetailerId)
                    {
                        found = true;
                    }
                }

                if (!found)
                {
                    retailers.RemoveAt(i);
                }
            }

            //foreach retailer, get the offered price, the normal price from the store, and the normal price from average.
            foreach (Retailer retailer in retailers)
            {
                foreach (Ingredient ingredient in recipeWithIngredients.GetOrSetIngredients)
                {
                    foreach (Offers offer in recipeWithIngredients.GetOrSetOffers)
                    {
                        if (offer.GetOrSetIngredientId == ingredient.GetOrSetId)
                        {
                            price += offer.GetOrSetOnSalePrice;

                            if (storeNormalPrice != -1)
                            {
                                if (offer.GetOrSetNormalPrice.HasValue)
                                {
                                    storeNormalPrice += (decimal)offer.GetOrSetNormalPrice;
                                }
                                else
                                {
                                    storeNormalPrice = -1;
                                }
                            }
                        }
                        else
                        {
                            price            += ingredient.GetOrSetPrice;
                            storeNormalPrice += ingredient.GetOrSetPrice;
                        }

                        NormalPrice += ingredient.GetOrSetPrice;
                    }
                }

                //The saving prices and percentages are calculated
                savingGeneralPrice = NormalPrice - price;
                savingStorePrice   = storeNormalPrice - price;

                savingGeneralPercent = savingGeneralPrice / price * 100;
                savingStorePercent   = savingStorePrice / price * 100;

                //Important, this is the order in which the dictionary is ordered

                retailerDictionary.Add(retailer, new ExtraData(price, savingStorePrice, savingGeneralPrice, savingStorePercent, savingGeneralPercent, retailer.GetOrSetId));
                price = 0;
            }

            retailerDictionary = retailerDictionary.OrderBy(x => x.Value.Price).ToDictionary(x => x.Key, x => x.Value);

            dbc.Close();
            return(retailerDictionary);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            string substring = "";
            int    length    = LongComSubstring.LongestCommonSubstring("penislægen", "penis", out substring);

            Console.WriteLine(length);
            Console.WriteLine(substring);
            IngredientIdentifier.Identify();

            Offer        off1   = null;
            List <Offer> offers = getOffers();

            for (int i = 530; i < 531; i++)
            {
                off1 = offers[i];
                Console.WriteLine(off1.heading);
                Console.WriteLine(off1.description);
                Console.WriteLine(off1.pricing.pre_price);
                Console.WriteLine(off1.pricing.price);
            }



            //IngredientIdentifier.nameGuessing(off1.heading, off1.description);

            Console.WriteLine("string: " + off1.heading);
            DBController      dbc            = new DBController();
            List <Ingredient> allIngredients = dbc.GetAllIngredients();

            dbc.Close();



            List <string> badWords = new List <string> {
                "i", "med", "fra", "af"
            };

            if (badWords.Contains("med"))
            {
                Console.WriteLine("indeholder, gem ikke");
            }
            else
            {
                Console.WriteLine("indeholder ikke, gem");
            }


            foreach (Offer off in offers)
            {
                Console.WriteLine(off.heading);
                List <string> words = IngredientIdentifier.importantWordsFromString(off.heading, ref allIngredients);
                foreach (string str in words)
                {
                    Console.WriteLine(str);
                }
                Console.ReadLine();
            }



            /*
             * DBDebug.dbMassInsert();
             * Script.ExcelExtractionScript();
             * UpdateDatabaseWithOffers();
             */



            Console.WriteLine("Starting Service...");
            //startRestService();

            //Script.ExcelExtractionScript();
            Console.WriteLine("Program Ended");
            while (true)
            {
            }

            Console.ReadLine();
        }