Esempio n. 1
0
 /// <summary>
 /// Adds the receipe.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 /// <param name="model">The model.</param>
 public void addReceipe(Receipe receipe, AppModel model)
 {
     if (checkType(receipe))
     {
         if (checkDifficulty(receipe))
         {
             if (checkOptions(receipe))
             {
                 model.AddReceipe(receipe);
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the data by ingredients.
        /// </summary>
        /// <param name="keyWords">The key words.</param>
        /// <param name="nbItemsPerPage">The nb items per page.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <bool> GetDataByIngredients(String[] keyWords, int nbItemsPerPage, int startIndex, AppModel model)
        {
            bool error = false;

            model.ClearReceipes();
            try
            {
                //we add all receipes created by the user
                foreach (var jsonItem in model.LocalReceipes)
                {
                    Receipe localToAdd = new Receipe(jsonItem.Stringify());
                    addReceipe(localToAdd, model);
                }
            }
            catch (Exception ex)
            {
            }
            try
            {
                List <Receipe>[] results = new List <Receipe> [keyWords.Length];
                for (int i = 0; i < keyWords.Length; i++)
                {
                    results[i]  = new List <Receipe>();
                    keyWords[i] = keyWords[i].ToUpper();
                }
                //we add all basic research associated to each keyword to the model
                foreach (var keyWord in keyWords)
                {
                    await this.GetData(keyWord, nbItemsPerPage, startIndex, model);
                }

                int bestResults = 1;// confidence level

                foreach (var receipe in model.Receipes)
                {
                    //we check the research parameters to go faster
                    if (checkType(receipe))
                    {
                        if (checkDifficulty(receipe))
                        {
                            if (checkOptions(receipe))
                            {
                                //used to compute the confidence level
                                int count = 0;

                                //case of receipes from marmiton
                                if (receipe.Id != -1)
                                {
                                    //retrieves ingredients
                                    ReceipeRetriever rr = new ReceipeRetriever();
                                    var task            = rr.extractReceipeFromMarmiton(receipe);


                                    if ((await task) == true)
                                    {
                                        var task2 = rr.cleanHtmlEntities(receipe.HtmlReceipe, receipe);
                                        rr.handleIngredients(rr.ingredientPart, receipe);
                                    }
                                }

                                //we compute the confidence level
                                foreach (var keyWord in keyWords)
                                {
                                    //each key word in the receipe informations add 1 confidence level
                                    if (checkIngredients(receipe, keyWord) || checkInstructions(receipe, keyWord) || checkTitle(receipe, keyWord))
                                    {
                                        count++;
                                    }
                                }
                                results[count].Add(receipe);
                                if (count > bestResults)
                                {
                                    bestResults = count;
                                }
                            }
                        }
                    }
                }

                model.ClearReceipes();


                //only best results are displayed
                foreach (var receipe in results[bestResults])
                {
                    model.AddReceipe(receipe);
                }
            }
            catch (Exception ex)
            {
                error = true;
            }

            return(error);
        }