Exemplo n.º 1
0
        private static ObservableCollection <FoodComposition> ConvertToList(JToken foodComposition)
        {
            IList <JToken> compositionList = foodComposition.Children().ToList();
            var            list            = new ObservableCollection <FoodComposition>();

            for (int i = 0; i < compositionList.Count; i++)
            {
                JToken children           = compositionList[i];
                var    foodGroup          = children["Food Group"].Value <int>();
                var    itemNo             = children["Item No."].Value <int>();
                var    indexNo            = children["Index No."].Value <int>();
                var    foodAndDescription = children["Food and Description"].Value <string>();
                var    refuse             = Nutrient.Parse(children["Refuse"].Value <string>(), UnitKind.percent);
                var    energy_kcal        = Nutrient.Parse(children["Energy (kcal)"].Value <string>(), UnitKind.kcal);
                var    energy_kj          = Nutrient.Parse(children["Energy (kJ)"].Value <string>(), UnitKind.kj);
                var    water   = Nutrient.Parse(children["Water"].Value <string>(), UnitKind.g);
                var    protein = Nutrient.Parse(children["Protein, calculated from  reference nitrogen"].Value <string>(), UnitKind.g);
                var    protein_AminoAcidResidues = Nutrient.Parse(children["Protein, calculated as  the sum of amino acid residues"].Value <string>(), UnitKind.g);
                var    lipid = Nutrient.Parse(children["Lipid"].Value <string>(), UnitKind.g);
                var    fattyAcid_TriacylGlycerol = Nutrient.Parse(children["Fatty acid, triacyl-glycerol equivalents"].Value <string>(), UnitKind.g);
                var    fattyAcid_Saturated       = Nutrient.Parse(children["Fatty acid, saturated"].Value <string>(), UnitKind.g);
                var    fattyAcid_MonoUnsaturated = Nutrient.Parse(children["Fatty acid, mono-unsaturated"].Value <string>(), UnitKind.g);
                var    fattyAcid_PolyUnsaturated = Nutrient.Parse(children["Fatty acid, poly-unsaturated"].Value <string>(), UnitKind.g);
                var    cholesterol  = Nutrient.Parse(children["Cholesterol"].Value <string>(), UnitKind.g);
                var    carbohydrate = Nutrient.Parse(children["Carbohydrate, total, calculated by difference"].Value <string>(), UnitKind.g);
                //var carbohydrate_Available = Nutrient.Parse(children["Carbohydrate, available; expressed in mono-saccharide equivalents"].Value<string>(), UnitKind.g);
                var carbohydrate_Available = Nutrient.Parse(children["Carbohydrate, available, expressed in mono-saccharide equivalents"].Value <string>(), UnitKind.g);
                var dietaryFiber_Soluble   = Nutrient.Parse(children["Dietary fiber, soluble"].Value <string>(), UnitKind.g);
                var dietaryFiber_Insoluble = Nutrient.Parse(children["Dietary fiber, insoluble"].Value <string>(), UnitKind.g);
                var dietaryFiber_Total     = Nutrient.Parse(children["Dietary fiber, total"].Value <string>(), UnitKind.g);
                var ash                         = Nutrient.Parse(children["Ash"].Value <string>(), UnitKind.g);
                var sodium                      = Nutrient.Parse(children["Sodium"].Value <string>(), UnitKind.mg);
                var potassium                   = Nutrient.Parse(children["Potassium"].Value <string>(), UnitKind.mg);
                var calcium                     = Nutrient.Parse(children["Calcium"].Value <string>(), UnitKind.mg);
                var magnesium                   = Nutrient.Parse(children["Magnesium"].Value <string>(), UnitKind.mg);
                var phosphorus                  = Nutrient.Parse(children["Phosphorus"].Value <string>(), UnitKind.mg);
                var iron                        = Nutrient.Parse(children["Iron"].Value <string>(), UnitKind.mg);
                var zinc                        = Nutrient.Parse(children["Zinc"].Value <string>(), UnitKind.mg);
                var copper                      = Nutrient.Parse(children["Copper"].Value <string>(), UnitKind.mg);
                var manganese                   = Nutrient.Parse(children["Manganese"].Value <string>(), UnitKind.mg);
                var iodine                      = Nutrient.Parse(children["Iodine"].Value <string>(), UnitKind.micro_g);
                var selenium                    = Nutrient.Parse(children["Selenium"].Value <string>(), UnitKind.micro_g);
                var chromium                    = Nutrient.Parse(children["Chromium"].Value <string>(), UnitKind.micro_g);
                var molybdenum                  = Nutrient.Parse(children["Molybdenum"].Value <string>(), UnitKind.micro_g);
                var retinol                     = Nutrient.Parse(children["Retinol"].Value <string>(), UnitKind.micro_g);
                var alpha_Carotene              = Nutrient.Parse(children["alpha-Carotene"].Value <string>(), UnitKind.micro_g);
                var beta_Carotene               = Nutrient.Parse(children["beta-Carotene"].Value <string>(), UnitKind.micro_g);
                var beta_Cryptoxathin           = Nutrient.Parse(children["beta-Cryptoxanthin"].Value <string>(), UnitKind.micro_g);
                var beta_Caroteneequivalents    = Nutrient.Parse(children["beta-Caroteneequivalents"].Value <string>(), UnitKind.micro_g);
                var retinon_ActivityEquivalents = Nutrient.Parse(children["Retinol activityequivalents"].Value <string>(), UnitKind.micro_g);
                var vitamin_D                   = Nutrient.Parse(children["Vitamin D"].Value <string>(), UnitKind.micro_g);
                var alpha_Tocopherol            = Nutrient.Parse(children["alpha-Tocopherol"].Value <string>(), UnitKind.mg);
                var beta_Tocopherol             = Nutrient.Parse(children["beta-Tocopherol"].Value <string>(), UnitKind.mg);
                var gamma_Tocopherol            = Nutrient.Parse(children["gamma-Tocopherol"].Value <string>(), UnitKind.mg);
                var delta_Tocopherol            = Nutrient.Parse(children["delta-Tocopherol"].Value <string>(), UnitKind.mg);
                var vitamin_K                   = Nutrient.Parse(children["Vitamin K"].Value <string>(), UnitKind.micro_g);
                var thiamin                     = Nutrient.Parse(children["Thiamin"].Value <string>(), UnitKind.mg);
                var riboflavin                  = Nutrient.Parse(children["Riboflavin"].Value <string>(), UnitKind.mg);
                var niacin                      = Nutrient.Parse(children["Niacin"].Value <string>(), UnitKind.mg);
                var vitamin_B6                  = Nutrient.Parse(children["Vitamin B-6"].Value <string>(), UnitKind.mg);
                var vitamin_B12                 = Nutrient.Parse(children["Vitamin B-12"].Value <string>(), UnitKind.micro_g);
                var folate                      = Nutrient.Parse(children["Folate"].Value <string>(), UnitKind.micro_g);
                var pantothenic_Acid            = Nutrient.Parse(children["Pantothenic acid"].Value <string>(), UnitKind.mg);
                var biotin                      = Nutrient.Parse(children["Biotin"].Value <string>(), UnitKind.micro_g);
                var ascorbic_Acid               = Nutrient.Parse(children["Ascorbic acid"].Value <string>(), UnitKind.mg);
                var salt_Equivalents            = Nutrient.Parse(children["Salt equivalents"].Value <string>(), UnitKind.g);
                var alcohol                     = Nutrient.Parse(children["Alcohol"].Value <string>(), UnitKind.g);
                var nitrate_Ion                 = Nutrient.Parse(children["Nitrate ion "].Value <string>(), UnitKind.g);
                var theobromine                 = Nutrient.Parse(children["Theobromine"].Value <string>(), UnitKind.g);
                var caffeine                    = Nutrient.Parse(children["Caffeine"].Value <string>(), UnitKind.g);
                var tannin                      = Nutrient.Parse(children["Tannin"].Value <string>(), UnitKind.g);
                var polyphenol                  = Nutrient.Parse(children["Polyphenol"].Value <string>(), UnitKind.g);
                var acetic_Acid                 = Nutrient.Parse(children["Acetic acid"].Value <string>(), UnitKind.g);
                var cooking_Oil                 = Nutrient.Parse(children["Cooking oil"].Value <string>(), UnitKind.g);
                var organic_Acids               = Nutrient.Parse(children["Organic acids, total"].Value <string>(), UnitKind.g);
                var yield                       = Nutrient.Parse(children["Yield"].Value <string>(), UnitKind.percent);

                list.Add(
                    new FoodComposition(foodGroup, itemNo, indexNo, foodAndDescription, refuse,
                                        energy_kcal, energy_kj, water, protein, protein_AminoAcidResidues,
                                        lipid, fattyAcid_TriacylGlycerol, fattyAcid_Saturated,
                                        fattyAcid_MonoUnsaturated, fattyAcid_PolyUnsaturated, cholesterol, carbohydrate,
                                        carbohydrate_Available, dietaryFiber_Soluble, dietaryFiber_Insoluble, dietaryFiber_Total,
                                        ash, sodium, potassium, calcium, magnesium, phosphorus,
                                        iron, zinc, copper, manganese, iodine, selenium,
                                        chromium, molybdenum, retinol, alpha_Carotene, beta_Carotene,
                                        beta_Cryptoxathin, beta_Caroteneequivalents, retinon_ActivityEquivalents, vitamin_D,
                                        alpha_Tocopherol, beta_Tocopherol, gamma_Tocopherol, delta_Tocopherol, vitamin_K,
                                        thiamin, riboflavin, niacin, vitamin_B6, vitamin_B12, folate, pantothenic_Acid,
                                        biotin, ascorbic_Acid, salt_Equivalents, alcohol, nitrate_Ion, theobromine, caffeine,
                                        tannin, polyphenol, acetic_Acid, cooking_Oil, organic_Acids, yield)
                    );
            }

            return(list);
        }