async private void UpdateStats()
        {
            List <FoodItem> Items = await GlobalVariables.foodItemsDatabase.QueryById(getCurrentID());

            FoodItem foodItem = Items.First();
            Dictionary <int, int> dictionary = GlobalVariables.DeserializeDictionary(foodItem.ANSWERS);

            frequencyRating.Text = textToRating(dictionary[1]);
            healthRating.Text    = textToRating(dictionary[2]);
        }
 private void populateFields()
 {
     Task.Run(async() => {
         List <FoodItem> f = await GlobalVariables.foodItemsDatabase.QueryById(mID);
         food             = f.First();
         dict             = GlobalVariables.DeserializeDictionary(food.ANSWERS);
         imageView.Source = ImageSource.FromStream(() => new MemoryStream(GlobalVariables.DeserializeStringToByteArray(food.IMGBYTES)));
         if (EntryType == GlobalVariables.EntryType.UPDATE_ENTRY)
         {
             mName.Text = food.NAME;
             foreach (var question in dict)
             {
                 CustomRadioGroup group = null;
                 if (radioGroups.TryGetValue(question.Key, out group))
                 {
                     group.SelectedIndex = question.Value;
                 }
             }
         }
         Update();
     });
 }
Exemple #3
0
        public PlanPage()
        {
            ContinueOption = false;
            ChosenItems    = new List <FoodItem>(GlobalVariables.PRACTICE_NUMBER);
            InitializeComponent();

            FoodItems = GlobalVariables.getFoodItems(); //populate list with all food items

            //if random
            NavigationPage.SetHasNavigationBar(this, false);
            Randomizer randomizer = new Randomizer();
            List <int> list;

            if (Settings.RandomCriteriaValue == (int)GlobalVariables.RandomCriteria.Random)
            {
                list = randomizer.GetIndecies(GlobalVariables.PRACTICE_NUMBER, FoodItems.Count);
                foreach (var i in list)
                {
                    ChosenItems.Add(FoodItems[i]);
                }
            }
            else if (Settings.RandomCriteriaValue == (int)GlobalVariables.RandomCriteria.Health)
            {
                //TODO: Change value of health from 0 to 4 to -2 to 2
                // Use Math.Abs(health - 5)
                // Use Math.Pow(base, exponent)
                int        seed      = 0;
                List <int> intervals = new List <int>(FoodItems.Count);
                for (int f = 0; f < FoodItems.Count; f++)
                {
                    FoodItem food   = FoodItems[f];
                    int      health = GlobalVariables.DeserializeDictionary(food.ANSWERS)[2];
                    seed += Math.Abs(health - 5);
                    for (int i = intervals.Count; i < seed; i++)
                    {
                        intervals.Add(f);
                    }
                }
                list = randomizer.GetIndecies(GlobalVariables.PRACTICE_NUMBER, seed);
                foreach (var i in list)
                {
                    ChosenItems.Add(FoodItems[intervals[i]]);
                }
            }

            else if (Settings.RandomCriteriaValue == (int)GlobalVariables.RandomCriteria.DeltaFrequency)
            {
                int        seed      = 0;
                List <int> intervals = new List <int>(FoodItems.Count);
                for (int f = 0; f < FoodItems.Count; f++)
                {
                    FoodItem food = FoodItems[f];
                    Dictionary <int, int> dict = GlobalVariables.DeserializeDictionary(food.ANSWERS);
                    int health    = dict[2];
                    int deltaFreq = Math.Abs(dict[0] - dict[1]);
                    seed += (health * deltaFreq);
                    for (int i = intervals.Count; i < seed; i++)
                    {
                        intervals.Add(f);
                    }
                }
                list = randomizer.GetIndecies(GlobalVariables.PRACTICE_NUMBER, seed);
                foreach (var i in list)
                {
                    ChosenItems.Add(FoodItems[intervals[i]]);
                }
            }

            else if (Settings.RandomCriteriaValue == (int)GlobalVariables.RandomCriteria.HealthAndFrequency)
            {
                int        seed      = 0;
                List <int> intervals = new List <int>(FoodItems.Count);
                for (int f = 0; f < FoodItems.Count; f++)
                {
                    FoodItem food = FoodItems[f];
                    Dictionary <int, int> dict = GlobalVariables.DeserializeDictionary(food.ANSWERS);
                    int health = dict[2];
                    int Freq   = dict[0];
                    seed += (health * Freq);
                    for (int i = intervals.Count; i < seed; i++)
                    {
                        intervals.Add(f);
                    }
                }
                list = randomizer.GetIndecies(GlobalVariables.PRACTICE_NUMBER, seed);
                foreach (var i in list)
                {
                    ChosenItems.Add(FoodItems[intervals[i]]);
                }
            }
        }