Exemple #1
0
        private void addIngredientsToGroceryList(object sender, EventArgs e)
        {
            if (nutrientList.SelectedItem != null)
            {
                Recipe recipe = new Recipe();
                recipe.Name        = nutrientList.SelectedItem.ToString();
                recipe.Ingredients = ingredientList[nutrientList.SelectedItem.ToString()];
                IngredientForm ingredientForm = new IngredientForm(recipe);

                if (ingredientForm.ShowDialog() == DialogResult.OK)
                {
                    if (ingredientForm.isValid == true)
                    {
                        groceryList[selectedDay].Add(nutrientList.SelectedItem.ToString() + globalCount.ToString());
                        ingredientList[nutrientList.SelectedItem.ToString() + globalCount.ToString()] = ingredientForm.ConfirmedIngredients;
                        globalCount++;
                        ingredientForm.Close();
                    }
                }
            }
            else
            {
                MessageBox.Show("Please select a recipe from added list.");
            }
        }
Exemple #2
0
        public Pairings LoadFormPairings()
        {
            //TODO: This will come from a database of pairs that maps every possible unit to a default form of an ingredient
            var pairings = new Pairings();
            var pair     = new NameIngredientPair("head", TestIngredientLoader.ING_LETTUCE);
            var form     = new IngredientForm(TestIngredientLoader.FORM_LETTUCE_HEAD, TestIngredientLoader.ING_LETTUCE, Units.Unit, null, "head/heads", 0, null);

            pairings.Add(pair, form);

            return(pairings);
        }
Exemple #3
0
        public static IngredientBinding Create(Guid ingId, Guid recipeId, Single?qty, Units usageUnit, UnitType convType, Int32 unitWeight,
                                               Units formUnit, Single equivAmount, Units equivUnit)
        {
            var rawUnit = KitchenPC.Unit.GetDefaultUnitType(convType);

            if (qty.HasValue && rawUnit != usageUnit)
            {
                if (UnitConverter.CanConvert(usageUnit, rawUnit))
                {
                    qty = UnitConverter.Convert(qty.Value, usageUnit, rawUnit);
                }
                else
                {
                    var ing = new Ingredient
                    {
                        Id             = ingId,
                        ConversionType = convType,
                        UnitWeight     = unitWeight
                    };

                    var form = new IngredientForm
                    {
                        FormUnitType = formUnit,
                        FormAmount   = new Amount(equivAmount, equivUnit),
                        IngredientId = ingId
                    };

                    var usage = new Ingredients.IngredientUsage
                    {
                        Form       = form,
                        Ingredient = ing,
                        Amount     = new Amount(qty.Value, usageUnit)
                    };

                    try
                    {
                        var newAmt = FormConversion.GetNativeAmountForUsage(ing, usage);
                        qty = UnitConverter.Convert(newAmt.SizeHigh, newAmt.Unit, rawUnit); //Ingredient graph only stores high amounts
                    }
                    catch (Exception e)
                    {
                        throw new DataLoadException(e);
                    }
                }
            }

            return(new IngredientBinding
            {
                RecipeId = recipeId,
                IngredientId = ingId,
                Qty = qty.HasValue ? (float?)Math.Round(qty.Value, 3) : null,
                Unit = rawUnit
            });
        }
        public static bool TryGetFormForIngredient(string formname, Guid ing, out IngredientForm form)
        {
            form = null;
            FormNode node;

            if (false == synonymMap.TryGetValue(formname, out node))
            {
                return(false);
            }

            var pair = new NameIngredientPair(formname, ing);

            return(pairings.TryGetValue(pair, out form));
        }
Exemple #5
0
        private void AddIngredientButton_Click(object sender, EventArgs e)
        {
            var form = new IngredientForm();
            IngredientInterface ingredientInterface = null;
            DialogResult        dr = form.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                ingredientInterface = form.GetIngredient();
            }
            if (ingredientInterface.Name.Length > 0 && ingredientInterface.Price > 0)
            {
                ingredientsService.addIngredient(ingredientInterface);
            }
            form.Close();
        }
Exemple #6
0
        public IEnumerable <AnomalousNode> LoadSynonyms()
        {
            using (var session = adapter.GetStatelessSession())
            {
                var anomalies = session.QueryOver <NlpAnomalousIngredients>()
                                .Fetch(prop => prop.Ingredient).Eager()
                                .Fetch(prop => prop.WeightForm).Eager()
                                .Fetch(prop => prop.VolumeForm).Eager()
                                .Fetch(prop => prop.UnitForm).Eager()
                                .List();

                var ret = new List <AnomalousNode>();

                foreach (var anon in anomalies)
                {
                    var name    = anon.Name;
                    var ing     = anon.Ingredient.IngredientId;
                    var ingName = anon.Ingredient.DisplayName;

                    IngredientForm weightForm = null, volumeForm = null, unitForm = null;
                    if (anon.WeightForm != null)
                    {
                        weightForm = new IngredientForm(
                            anon.WeightForm.IngredientFormId,
                            ing,
                            anon.WeightForm.UnitType,
                            anon.WeightForm.FormDisplayName,
                            anon.WeightForm.UnitName,
                            anon.WeightForm.ConvMultiplier,
                            new Amount(anon.WeightForm.FormAmount, anon.WeightForm.FormUnit));
                    }

                    if (anon.VolumeForm != null)
                    {
                        volumeForm = new IngredientForm(
                            anon.VolumeForm.IngredientFormId,
                            ing,
                            anon.VolumeForm.UnitType,
                            anon.VolumeForm.FormDisplayName,
                            anon.VolumeForm.UnitName,
                            anon.VolumeForm.ConvMultiplier,
                            new Amount(anon.VolumeForm.FormAmount, anon.VolumeForm.FormUnit));
                    }

                    if (anon.UnitForm != null)
                    {
                        unitForm = new IngredientForm(
                            anon.UnitForm.IngredientFormId,
                            ing,
                            anon.UnitForm.UnitType,
                            anon.UnitForm.FormDisplayName,
                            anon.UnitForm.UnitName,
                            anon.UnitForm.ConvMultiplier,
                            new Amount(anon.UnitForm.FormAmount, anon.UnitForm.FormUnit));
                    }

                    var pairings = new DefaultPairings()
                    {
                        Weight = weightForm, Volume = volumeForm, Unit = unitForm
                    };
                    var ingNode = new AnomalousIngredientNode(ing, ingName, UnitType.Unit, 0, pairings); //TODO: Must load conv type and unit weight
                    ret.Add(new AnomalousNode(name, ingNode));
                }

                return(ret);
            }
        }
 public bool TryGetValue(NameIngredientPair key, out IngredientForm value)
 {
     return this.pairs.TryGetValue(key, out value);
 }
 public void Add(NameIngredientPair key, IngredientForm value)
 {
     this.pairs.Add(key, value);
 }
        public static bool TryGetFormForPrep(Preps preps, IngredientNode ing, bool remove, out IngredientForm form)
        {
            //TODO: Do we need to check all preps, or just the one that was on the input
            foreach (var prep in preps)
            {
                var fMatch = TryGetFormForIngredient(prep.Prep, ing.Id, out form);
                if (!fMatch)
                {
                    continue;
                }

                if (remove)
                {
                    preps.Remove(prep);
                }

                return(true);
            }

            form = null;
            return(false);
        }
Exemple #10
0
 public InvalidFormException(Ingredient ing, IngredientForm form)
 {
     Ingredient = ing;
     Form       = form;
 }
Exemple #11
0
 public IngredientUsageCreator WithForm(IngredientForm form)
 {
     Usage.Form = form;
     return(this);
 }
Exemple #12
0
 public bool TryGetValue(NameIngredientPair key, out IngredientForm value)
 {
     return(pairs.TryGetValue(key, out value));
 }
Exemple #13
0
 public void Add(NameIngredientPair key, IngredientForm value)
 {
     pairs.Add(key, value);
 }
Exemple #14
0
        public IEnumerable <AnomalousNode> LoadSynonyms()
        {
            var forms       = store.GetIndexedIngredientForms();
            var ingredients = store.GetIndexedIngredients();
            var anomalies   = store.NlpAnomalousIngredients;

            var ret = new List <AnomalousNode>();

            foreach (var anon in anomalies)
            {
                var ingredient = ingredients[anon.IngredientId];

                var name    = anon.Name;
                var ing     = anon.IngredientId;
                var ingName = ingredient.DisplayName;

                IngredientForm weightForm = null, volumeForm = null, unitForm = null;
                if (anon.WeightFormId.HasValue)
                {
                    var wf = forms[anon.WeightFormId.Value];

                    weightForm = new IngredientForm(
                        wf.IngredientFormId,
                        ing,
                        wf.UnitType,
                        wf.FormDisplayName,
                        wf.UnitName,
                        wf.ConvMultiplier,
                        new Amount(wf.FormAmount, wf.FormUnit));
                }

                if (anon.VolumeFormId.HasValue)
                {
                    var vf = forms[anon.VolumeFormId.Value];

                    volumeForm = new IngredientForm(
                        vf.IngredientFormId,
                        ing,
                        vf.UnitType,
                        vf.FormDisplayName,
                        vf.UnitName,
                        vf.ConvMultiplier,
                        new Amount(vf.FormAmount, vf.FormUnit));
                }

                if (anon.UnitFormId.HasValue)
                {
                    var uf = forms[anon.UnitFormId.Value];

                    unitForm = new IngredientForm(
                        uf.IngredientFormId,
                        ing,
                        uf.UnitType,
                        uf.FormDisplayName,
                        uf.UnitName,
                        uf.ConvMultiplier,
                        new Amount(uf.FormAmount, uf.FormUnit));
                }

                var pairings = new DefaultPairings()
                {
                    Weight = weightForm, Volume = volumeForm, Unit = unitForm
                };
                var ingNode = new AnomalousIngredientNode(ing, ingName, UnitType.Unit, 0, pairings); //TODO: Must load conv type and unit weight
                ret.Add(new AnomalousNode(name, ingNode));
            }

            return(ret);
        }
        /// <summary>
        /// Show Ingredients Main Menu
        /// </summary>
        public static void ShowIngredientsMenu()
        {
            string menuOption = new string("");
            string menu       = "Ingredients\n\n" +
                                "1 - New\n" +
                                "2 - Invetory\n" +
                                "3 - Find\n" +
                                "4 - Update\n" +
                                //"5 - Delete\n" +
                                "\nb - Back\n\n" +
                                "Option: ";

            do
            {
                Console.Write(menu);
                menuOption = Console.ReadLine();

                switch (menuOption)
                {
                case "1":
                    ClearHelper.Clear();
                    IngredientForm.ShowForm();
                    break;

                case "2":
                    ClearHelper.Clear();
                    ShowAll.Show();
                    Console.WriteLine();
                    Console.ReadKey();
                    ClearHelper.Clear();
                    break;

                case "3":
                    ClearHelper.Clear();
                    SearchForm.Search();
                    break;

                case "4":
                    ClearHelper.Clear();
                    ShowAll.Show();
                    Console.WriteLine();
                    Update.Show();
                    break;

                /*case "5":
                 *  ClearHelper.Clear();
                 *  ShowAll.Show();
                 *  Console.WriteLine();
                 *  Delete.Show();
                 *  break;*/
                case "b":
                    ClearHelper.Clear();
                    break;

                default:
                    Console.WriteLine("Wrong option!");
                    Console.ReadKey();
                    ClearHelper.Clear();
                    break;
                }
            } while (menuOption != "b");
        }
Exemple #16
0
        public void TestFormConverter()
        {
            //Form conversions (Unit ingredients)
            var unitIng = new Ingredient()
            {
                ConversionType = UnitType.Unit, UnitWeight = 200
            };                                                                              //Ingredient sold by units (unit weighs 200g)
            var unitIng_UnitForm = new IngredientForm()
            {
                FormAmount = new Amount(50, Units.Gram), ConversionMultiplier = 1, FormUnitType = Units.Unit
            };                                                                                                                                       //Form expressed in units (unit in this form weighs 50g)
            var unitIng_WeightForm = new IngredientForm()
            {
                ConversionMultiplier = 1, FormUnitType = Units.Ounce
            };                                                                                                 //Form expressed by weight
            var unitIng_VolForm = new IngredientForm()
            {
                FormUnitType = Units.Cup, ConversionMultiplier = 1, FormAmount = new Amount(20, Units.Gram)
            };                                                                                                                                     //Each cup weighs 20g)

            var unitIng_UnitUsage = new IngredientUsage()
            {
                Amount = new Amount(4, Units.Unit), Form = unitIng_UnitForm, Ingredient = unitIng
            };
            var unitIng_WeightUsage = new IngredientUsage()
            {
                Amount = new Amount(300, Units.Gram), Form = unitIng_WeightForm, Ingredient = unitIng
            };
            var unitIng_VolUsage = new IngredientUsage()
            {
                Amount = new Amount(160, Units.Tablespoon), Form = unitIng_VolForm, Ingredient = unitIng
            };                                                                                                                                    //10 cups

            var unitIng_UnitAmt   = FormConversion.GetNativeAmountForUsage(unitIng, unitIng_UnitUsage);
            var unitIng_WeightAmt = FormConversion.GetNativeAmountForUsage(unitIng, unitIng_WeightUsage);
            var unitIng_VolAmt    = FormConversion.GetNativeAmountForUsage(unitIng, unitIng_VolUsage);

            Assert.AreEqual(1.0f, unitIng_UnitAmt.SizeHigh); //4 units in this form should convert to 1 unit of ingredient
            Assert.AreEqual(Units.Unit, unitIng_UnitAmt.Unit);

            Assert.AreEqual(2.0f, unitIng_WeightAmt.SizeHigh); //300g of this form should convert to 1.5 units of ingredient, however we round up to whole units
            Assert.AreEqual(Units.Unit, unitIng_WeightAmt.Unit);

            //TODO: Fix
            //Assert.AreEqual(1.0f, unitIng_VolAmt.SizeHigh); //10 cups of this form should convert to 1 unit of ingredient
            //Assert.AreEqual(Units.Unit, unitIng_VolAmt.Unit);

            //Form conversions (Volume ingredients)
            var volIng = new Ingredient()
            {
                ConversionType = UnitType.Volume
            };                                                             //Ingredient sold by volume
            var volIng_UnitForm = new IngredientForm()
            {
                FormUnitType = Units.Unit, ConversionMultiplier = 1, FormAmount = new Amount(5, Units.Teaspoon)
            };
            var volIng_WeightForm = new IngredientForm()
            {
                FormUnitType = Units.Ounce, ConversionMultiplier = 1, FormAmount = new Amount(2, Units.Teaspoon)
            };

            var volIng_UnitUsage = new IngredientUsage()
            {
                Amount = new Amount(2, Units.Unit), Form = volIng_UnitForm, Ingredient = volIng
            };
            var volIng_WeightUsage = new IngredientUsage()
            {
                Amount = new Amount(0.25f, Units.Pound), Form = volIng_WeightForm, Ingredient = volIng
            };                                                                                                                                    //4oz

            var volIng_UnitAmt   = FormConversion.GetNativeAmountForUsage(volIng, volIng_UnitUsage);
            var volIng_WeightAmt = FormConversion.GetNativeAmountForUsage(volIng, volIng_WeightUsage);

            Assert.AreEqual(10.0f, volIng_UnitAmt.SizeHigh);
            Assert.AreEqual(Units.Teaspoon, volIng_UnitAmt.Unit);

            Assert.AreEqual(8.0f, volIng_WeightAmt.SizeHigh);
            Assert.AreEqual(Units.Teaspoon, volIng_WeightAmt.Unit);

            //Form conversions (Weight ingredients)
            var weightIng = new Ingredient()
            {
                ConversionType = UnitType.Weight
            };                                                                //Ingredient sold by weight
            var weightIng_UnitForm = new IngredientForm()
            {
                ConversionMultiplier = 1, FormUnitType = Units.Unit, FormAmount = new Amount(100, Units.Gram)
            };
            var weightIng_VolForm = new IngredientForm()
            {
                ConversionMultiplier = 1, FormUnitType = Units.Cup, FormAmount = new Amount(50, Units.Gram)
            };

            var weightIng_UnitUsage = new IngredientUsage()
            {
                Amount = new Amount(5, Units.Unit), Form = weightIng_UnitForm, Ingredient = weightIng
            };
            var weightIng_VolUsage = new IngredientUsage()
            {
                Amount = new Amount(144, Units.Teaspoon), Form = weightIng_VolForm, Ingredient = weightIng
            };                                                                                                                                        //3 cups

            var weightIng_UnitAmt = FormConversion.GetNativeAmountForUsage(weightIng, weightIng_UnitUsage);
            var weightIng_VolAmt  = FormConversion.GetNativeAmountForUsage(weightIng, weightIng_VolUsage);

            Assert.AreEqual(500.0f, weightIng_UnitAmt.SizeHigh);
            Assert.AreEqual(Units.Gram, weightIng_UnitAmt.Unit);

            Assert.AreEqual(150.0f, weightIng_VolAmt.SizeHigh);
            Assert.AreEqual(Units.Gram, weightIng_VolAmt.Unit);
        }