Пример #1
0
        /* ReadTxtFile parses data fron the .txt file stored in the Assets directory
         * and creates Dining Location objects and created Food objects within each Dining Location Object
         */
        public async void ReadTxtFile()
        {
            Dining_Location Current_DL = null;
            string          L;

            using (Stream stream = await FileSystem.OpenAppPackageFileAsync("TTU_Meal_Objs.txt"))
            {
                using (StreamReader sr = new StreamReader(stream))
                {
                    while ((L = sr.ReadLine()) != null)
                    {
                        //Console.WriteLine(L);
                        //Check if there is a new DiningLocation
                        if (L.Contains("->"))
                        {
                            string          Title = L.Substring(2);
                            Dining_Location DL    = new Dining_Location(Title);
                            if (Current_DL != null)
                            {
                                Current_DL.getSortedFood();
                                TTU_Meal_Data.Add(Current_DL);
                            }
                            Current_DL = DL;
                        }
                        else if (!L.Equals(""))
                        {
                            Food F = new Food(L);
                            Current_DL.Add_Food(F);
                        }
                    }
                }
            }
        }
Пример #2
0
        private Food Get_Food(int TCal, int TPro, int TCar, int TFat, bool isB)
        {
            Random      random  = new System.Random();
            List <Food> AllFood = new List <Food>();

            if (isB)
            {
                Dining_Location PlaceToEat = Breakfast_Places[random.Next(0, Breakfast_Places.Count)];
                AllFood = PlaceToEat.AllFood;
                if (PlaceToEat.get_Name().Equals("Fresh Plate Nutritionals For Week Day Menu") ||
                    PlaceToEat.get_Name().Equals("Sams Sub Nutritionals"))
                {
                    //Throw out food from list that do not contain "Breakfast" in their label
                    for (int a = 0; a < AllFood.Count; a++)
                    {
                        string Label = AllFood[a].get_Type();
                        if (!Label.Contains("Breakfast"))
                        {
                            AllFood.RemoveAt(a);
                            a--;
                        }
                    }
                }
            }
            else
            {
                Dining_Location PlaceToEat = Lunch_Dinner_Places[random.Next(0, Lunch_Dinner_Places.Count)];
                AllFood = PlaceToEat.AllFood;
            }

            AllFood = Reset_SS(AllFood);

            //If didn't find food, increase serving size to see if that will help
            List <Food> Potential_Options = Options(AllFood, TCal, TPro, TCar, TFat);

            if (Potential_Options.Count == 0)
            {
                Potential_Options = Options(Increase_SS(AllFood), TCal, TPro, TCar, TFat);
            }
            //--Finding Food with increased Serving Size---------------------------------


            if (Potential_Options.Count == 0)
            {
                return(null);
            }
            else
            {
                return(Potential_Options[random.Next(0, Potential_Options.Count)]);
            }
        }
Пример #3
0
        private Dining_Location Create_Obj(string PDFN)
        {
            string RawD = ExtractTextFromPdf(PDFN);

            //Console.WriteLine(RawD);
            string[] Lines = Regex.Split(RawD, "\r\n|\r|\n");

            //Create Header
            string Header = FormatHeader(PDFN);
            //Console.WriteLine(Header);

            Dining_Location DL = new Dining_Location(Header);

            //Get Data and send it to the Food Object
            List <string> Formatted_Sheet = Format_Sheet(Lines);
            string        CurrentLabel    = "Offered Food";

            foreach (string L in Formatted_Sheet)
            {
                //Test to see if L is correctly formatted for food item
                string newS = L.Replace("<", "");
                newS = newS.Replace(">", "");
                newS = Regex.Replace(newS, "[\\d*]", "@");
                //Console.WriteLine(newS + "\n");
                string[] AllP = newS.Split(" @");
                if (L.Contains("| LABEL"))
                {
                    CurrentLabel = L.Replace("| LABEL", "").Replace("Serving Size", "").Replace("180 2 24 1 4  Wheat, Milk, Soy", "")
                                   .Replace("Serving Size Calories Fat (g) Carbs (g) Fiber Protein (g) Vegan Vegetarian Gluten Free Allergen/Contains", "")
                                   .Replace("<", "").Replace("Nuts Pecans/Walnuts", "").Replace("", "").Replace("Wheat, Milk, Soy", "").Replace("?", "");
                    CurrentLabel = Regex.Replace(CurrentLabel, "[\\d*]", "");
                }
                else if (AllP.Length == 7)
                {
                    //Add to the list of food in the Dining Location
                    Food NewF = new Food(Header, CurrentLabel, L);
                    DL.Add_Food(NewF);
                }

                //Console.WriteLine(L + "\n");
            }

            return(DL);
        }