private async void lvSavedMeals_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            SavedMeals[e.ItemIndex].index = e.ItemIndex;
            SavedMeals[e.ItemIndex]       = await CalculatorV2.MacroTotalsAsync(SavedMeals[e.ItemIndex]);

            bool addMeal = await DisplayAlert(
                SavedMeals[e.ItemIndex].mealName,
                "Add this meal?\n\n" +
                "Contains food items:\n\n" +
                MealItemSummary(e.ItemIndex) +
                string.Format("Total Energy: {0:0.00} kcal", SavedMeals[e.ItemIndex].totalEnergy) + "\n" +
                string.Format("Total Protein: {0:0.00} g", SavedMeals[e.ItemIndex].totalProtein) + "\n" +
                string.Format("Total Carbs: {0:0.00} g", SavedMeals[e.ItemIndex].totalCarbs) + "\n" +
                string.Format("Total Fat: {0:0.00} g", SavedMeals[e.ItemIndex].totalFat) + "\n", "Yes", "No");

            if (addMeal == true)
            {
                await MasterModel.DAL.SaveNewTempLoadoutMealAsync(SavedMeals[e.ItemIndex]);
            }
        }
示例#2
0
        private async void Meal_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            MasterModel.tempMeal.index = e.ItemIndex;

            MasterModel.tempMeal = await CalculatorV2.MacroTotalsAsync(MasterModel.tempMeal);

            bool addMeal = await DisplayAlert(
                MasterModel.tempMeal.mealName,
                "Add this meal?\n\n" +
                MealItemSummary() +
                string.Format("{0:0.00} kcal", MasterModel.tempMeal.totalEnergy) + "\n" +
                string.Format("{0:0.00} g", MasterModel.tempMeal.totalProtein) + "\n" +
                string.Format("{0:0.00} g", MasterModel.tempMeal.totalCarbs) + "\n" +
                string.Format("{0:0.00} g", MasterModel.tempMeal.totalFat) + "\n", "Yes", "No");

            if (addMeal == true)
            {
                await MasterModel.DAL.SaveNewTempLoadoutMealAsync(MasterModel.tempMeal);
            }
        }
示例#3
0
        private async Task <string> MealSummary(int index)
        {
            string summary = "Select this loadout?\n\n";

            //calculate macro totals for each meal while adding to summary string
            for (int i = 0; i < userLoadouts[index].Meals.Count; i++)
            {
                await CalculatorV2.MacroTotalsAsync(userLoadouts[index].Meals[i]);

                summary += (userLoadouts[index].Meals[i].mealName + "\n");
            }
            summary += "\n";

            //calculate macro totals of whole loadout
            userLoadouts[index] = await CalculatorV2.MacroTotalsLoadoutAsync(userLoadouts[index]);

            summary += "This loadout has:\n";
            summary += string.Format("Energy: {0:0.00} kcal\n", userLoadouts[index].totalEnergy);
            summary += string.Format("Protein: {0:0.00} kcal\n", userLoadouts[index].totalProtein);
            summary += string.Format("Carbs: {0:0.00} kcal\n", userLoadouts[index].totalCarbs);
            summary += string.Format("Fat: {0:0.00} kcal\n", userLoadouts[index].totalFat);

            return(summary);
        }
示例#4
0
        private async Task SetGoalRatios()
        {
            dailyGoal = await CalculatorV2.CalcRatiosAsync(dailyGoal);

            goalProgress = await CalculatorV2.CalcRatiosAsync(goalProgress);
        }
示例#5
0
 public void Setup()
 {
     calculator = new CalculatorV2();
 }
示例#6
0
        public void Execute(int numberOfRuns = 1)
        {
            NumberOfRuns = numberOfRuns > 0 ? numberOfRuns: 1;
            WriteLine($"   ({numberOfRuns} runs per each formula and input data)");
            WriteLine();

            var shortData = new[]
            {
                new DecodedScan(1, new[] { 1f, 10f, 100f }),
                new DecodedScan(1, new[] { 2f, 20f, 200f }),
                new DecodedScan(1, new[] { 3f, 30f, 300f }),
                new DecodedScan(1, new[] { 4f, 40f, 400f }),
                new DecodedScan(1, new[] { 5f, 50f, 500f }),
                new DecodedScan(1, new[] { 6f, 60f, 600f }),
                new DecodedScan(1, new[] { 7f, 70f, 700f })
            };

            var data1kSPS = Enumerable.Range(0, 1000)
                            .Select(i => new DecodedScan((ulong)i, new[] { i + 1f, (i + 1) * 10f, (i + 1) * 100f })).ToArray();

            var data200kSPS = Enumerable.Range(0, 200_000)
                              .Select(i => new DecodedScan((ulong)i, new[] { i + 1f, (i + 1) * 10f, (i + 1) * 100f })).ToArray();

            var data1000kSPS = Enumerable.Range(0, 1_000_000)
                               .Select(i => new DecodedScan((ulong)i, new[] { i + 1f, (i + 1) * 10f, (i + 1) * 100f })).ToArray();

            var calculator = new CalculatorV2();

            WriteLine($" {"SAMPLES",7} | {"DURATION",16} | {"FORMULA",FormulaWidth} == {"RESULT VALUES",-10}");
            WriteLine();
            var formulaDefinition = "1 + 1";

            Evaluate(calculator, formulaDefinition, 10, shortData);
            Evaluate(calculator, formulaDefinition, 1000, data1kSPS);
            Evaluate(calculator, formulaDefinition, 200_000, data200kSPS);
            Evaluate(calculator, formulaDefinition, 1_000_000, data1000kSPS);
            WriteLine();
            formulaDefinition = "sig(B) + sig(A)";
            Evaluate(calculator, formulaDefinition, 10, shortData);
            Evaluate(calculator, formulaDefinition, 1000, data1kSPS);
            Evaluate(calculator, formulaDefinition, 200_000, data200kSPS);
            Evaluate(calculator, formulaDefinition, 1_000_000, data1000kSPS);
            WriteLine();
            formulaDefinition = "sig(B) + sig(A) + sig(C)";
            Evaluate(calculator, formulaDefinition, 10, shortData);
            Evaluate(calculator, formulaDefinition, 1000, data1kSPS);
            Evaluate(calculator, formulaDefinition, 200_000, data200kSPS);
            Evaluate(calculator, formulaDefinition, 1_000_000, data1000kSPS);
            WriteLine();
            formulaDefinition = "sqrt(sig(A)*sig(A) + sig(B)*sig(B))";
            Evaluate(calculator, formulaDefinition, 10, shortData);
            Evaluate(calculator, formulaDefinition, 1000, data1kSPS);
            Evaluate(calculator, formulaDefinition, 200_000, data200kSPS);
            Evaluate(calculator, formulaDefinition, 1_000_000, data1000kSPS);
            WriteLine();
            formulaDefinition = "sigDifferentiate(C)";
            Evaluate(calculator, formulaDefinition, 10, shortData);
            Evaluate(calculator, formulaDefinition, 1000, data1kSPS);
            Evaluate(calculator, formulaDefinition, 200_000, data200kSPS);
            Evaluate(calculator, formulaDefinition, 1_000_000, data1000kSPS);
            WriteLine();
            formulaDefinition = "sigIntegrate(C)";
            Evaluate(calculator, formulaDefinition, 10, shortData);
            Evaluate(calculator, formulaDefinition, 1000, data1kSPS);
            Evaluate(calculator, formulaDefinition, 200_000, data200kSPS);
            Evaluate(calculator, formulaDefinition, 1_000_000, data1000kSPS);
            WriteLine("-------------------------------");
            WriteLine($"{"SUM:",10} {TotalDuration} ({TotalDuration.TotalMilliseconds} ms)");
        }
示例#7
0
        public void FormulasWithSignals()
        {
            var calculator = new CalculatorV2();

            //-------------------------------------------
            var samplingRate = 10;

            WriteLine();
            WriteLine($"Formulas with signals: 3 signals (A, B, C), sampling rate = {samplingRate}");
            WriteLine();


            var signalsInputData = new[]
            {
                new DecodedScan(1, new[] { 1f, 10f, 100f }),
                new DecodedScan(1, new[] { 2f, 20f, 200f }),
                new DecodedScan(1, new[] { 3f, 30f, 300f }),
                new DecodedScan(1, new[] { 4f, 40f, 400f }),
                new DecodedScan(1, new[] { 5f, 50f, 500f }),
                new DecodedScan(1, new[] { 6f, 60f, 600f }),
                new DecodedScan(1, new[] { 7f, 70f, 700f })
            };


            WriteLineTitle(
                "----------------------------- input signals",
                "----------------------------------------------------------");
            WriteLineResult("FORMULA", "RESULT VALUES");
            WriteLine();

            Evaluate(calculator, "sig(A)", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(B)", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(C)", samplingRate, signalsInputData);
            WriteLine();

            WriteLineTitle(
                "------------------------- simple operations",
                "----------------------------------------------------------");
            WriteLineResult("FORMULA", "RESULT VALUES");
            WriteLine();

            Evaluate(calculator, "integrate(25)", samplingRate, signalsInputData);
            Evaluate(calculator, "sqrt(25)", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(C) + 7", samplingRate, signalsInputData);
            Evaluate(calculator, "sqrt(sig(C))", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(B) + sig(A)", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(B) - sig(A)", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(B) * sig(A)", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(B) / sig(A)", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(B) / sig(A) +1", samplingRate, signalsInputData);
            Evaluate(calculator, "sig(B) / (sig(A) +1)", samplingRate, signalsInputData);
            WriteLine();
            WriteLineTitle(
                "--------------------- integration operation",
                "-------------------------------------------------------");
            WriteLineResult("FORMULA", "RESULT VALUES");
            WriteLine();

            Evaluate(calculator, "sig(C)", samplingRate, signalsInputData);
            Evaluate(calculator, "integrate(sig(C))", samplingRate, signalsInputData);
            Evaluate(calculator, "sigIntegrate(C)", samplingRate, signalsInputData);
            Evaluate(calculator, "integrate(sig(C)*10)", samplingRate, signalsInputData);
            Evaluate(calculator, "sigIntegrate(C)*10", samplingRate, signalsInputData);
            Evaluate(calculator, "111 - integrate(sig(C))", samplingRate, signalsInputData);
            Evaluate(calculator, "111 - sigIntegrate(C)", samplingRate, signalsInputData);
            WriteLine();

            WriteLineTitle(
                "-------------------differentiate operations",
                "-------------------------------------------------------");
            WriteLineResult("FORMULA", "RESULT VALUES");
            WriteLine();

            Evaluate(calculator, "sig(C)", samplingRate, signalsInputData);
            Evaluate(calculator, "sigDifferentiate(C)", samplingRate, signalsInputData);
            Evaluate(calculator, "111 - sigDifferentiate(C)", samplingRate, signalsInputData);
            WriteLine();


            WriteLineTitle(
                "---------------------------typical formulas",
                "-------------------------------------------------------");
            WriteLineResult("FORMULA", "RESULT VALUES");
            WriteLine();

            Evaluate(calculator, "sqrt(sig(A)*sig(A) + sig(B)*sig(B))", samplingRate, signalsInputData);
        }