Example #1
0
        private void LoadTrainingData(IDBLoader loader)
        {
            this.trainingData = new Dictionary <Guid, IRecipeClassification>();

            this.breakfastIndex = new RecipeIndex();
            this.lunchIndex     = new RecipeIndex();
            this.dinnerIndex    = new RecipeIndex();
            this.dessertIndex   = new RecipeIndex();

            var data = loader.LoadTrainingData();

            foreach (var recipeClassification in data)
            {
                this.trainingData.Add(recipeClassification.Recipe.Id, recipeClassification);

                if (recipeClassification.IsBreakfast)
                {
                    this.breakfastIndex.Add(recipeClassification.Recipe);
                }
                if (recipeClassification.IsLunch)
                {
                    this.lunchIndex.Add(recipeClassification.Recipe);
                }
                if (recipeClassification.IsDinner)
                {
                    this.dinnerIndex.Add(recipeClassification.Recipe);
                }
                if (recipeClassification.IsDessert)
                {
                    this.dessertIndex.Add(recipeClassification.Recipe);
                }
            }
        }
Example #2
0
        private void Compete(Recipe entry, RecipeIndex first, RecipeIndex second, Ranking rankBreakfast, Ranking rankLunch, Ranking rankDinner, Ranking rankDessert)
        {
            var chance = this.GetPrediction(entry, first, second);

            if (chance > 0.5f - Tolerance && chance < 0.5f + Tolerance)
            {
                return; // No winner
            }

            var diff   = (float)Math.Abs(chance - 0.5);
            var winner = chance < 0.5 ? second : first;

            if (winner == this.breakfastIndex)
            {
                rankBreakfast.Score += diff;
            }

            if (winner == this.lunchIndex)
            {
                rankLunch.Score += diff;
            }

            if (winner == this.dinnerIndex)
            {
                rankDinner.Score += diff;
            }

            if (winner == this.dessertIndex)
            {
                rankDessert.Score += diff;
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Type")] RecipeIndex recipeIndex)
        {
            if (id != recipeIndex.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recipeIndex);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecipeIndexExists(recipeIndex.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipeIndex));
        }
        public async Task <IActionResult> Create([Bind("ID,Title,Type")] RecipeIndex recipeIndex)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipeIndex);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipeIndex));
        }
Example #5
0
        private async Task RemoveReference(Recipe item)
        {
            // Site
            {
                var repository = new SiteRepository(this.ConnectionString);
                var site       = await repository.GetAsync();

                RecipeIndex line = site.Recipes.Where(x => x.Guid == item.Guid).FirstOrDefault();

                if (line != null)
                {
                    site.Recipes.Remove(line);
                    await repository.SaveAsync(site);
                }
            }
        }
Example #6
0
        private float GetPrediction(Recipe recipe, RecipeIndex first, RecipeIndex second)
        {
            // Reset probability and invertedProbability
            this.invertedProbability = 0;
            this.probability         = 0;

            var tokens = Tokenizer.Tokenize(recipe);

            foreach (var token in tokens)
            {
                var firstRITokensCount  = first.GetTokenCount(token);
                var secondRITokensCount = second.GetTokenCount(token);

                this.CalcProbability(firstRITokensCount, first.EntryCount, secondRITokensCount, second.EntryCount);
            }

            var prediction = this.probability / (this.probability + this.invertedProbability);

            return(prediction);
        }
Example #7
0
        private async Task AddReference(Recipe item)
        {
            // Update Site
            {
                var repository = new SiteRepository(this.ConnectionString);
                var site       = await repository.GetAsync();

                var line = site.Recipes.Where(x => x.Guid == item.Guid).FirstOrDefault();
                if (line == null)
                {
                    line = new RecipeIndex()
                    {
                        Guid = item.Guid
                    };
                    site.Recipes.Add(line);
                    site.Recipes = site.Recipes.OrderBy(o => o.Name).ToList();
                }
                line.Name           = item.Name;
                line.HashtagsString = item.HashtagsString;
                line.ImageUrl       = item.ImageUrl;

                await repository.SaveAsync(site);
            }
        }
 public RecipeLineViewModel(RecipeIndex item)
 {
     this.Guid     = item.Guid;
     this.Name     = item.Name;
     this.ImageUrl = item.ImageUrl;
 }