Ejemplo n.º 1
0
 private static void AddPerfumeToAllPerfumes(Perfume perfume)
 {
     if (perfume.Accords.Keys.Count() != 0)
     {
         AllPerfumes.Add(perfume);
     }
 }
Ejemplo n.º 2
0
        //Our Lovely Suggest Function
        public static Perfume SuggestPerfumeByRequestedAccords(Dictionary <String, int> requested_accords)
        {
            List <String> requested_accord_names = requested_accords.Keys.ToList();

            Perfume ClosestPerfume               = null;
            double  previous_point_distance      = double.MaxValue;
            double  total_point_distance_squared = 0;
            int     perfume_accord_value         = 0;
            int     requested_accord_value       = 0;
            double  current_point_distance;

            foreach (Perfume perfume in AllPerfumes)
            {
                total_point_distance_squared = 0;
                foreach (String accord_name in requested_accord_names)
                {
                    perfume_accord_value   = perfume.Accords.Keys.Contains(accord_name) ? perfume.Accords[accord_name] : 0;
                    requested_accord_value = requested_accords[accord_name];

                    total_point_distance_squared += Math.Pow((perfume_accord_value - requested_accord_value), 2);
                }
                current_point_distance = Math.Sqrt((double)total_point_distance_squared);

                //
                if (current_point_distance < previous_point_distance)
                {
                    ClosestPerfume          = perfume;
                    previous_point_distance = current_point_distance;
                }
            }
            return(ClosestPerfume);
        }
Ejemplo n.º 3
0
 //Private section--------------------------------------------------------
 private static void SetAllPerfumesFromParsedData(List <String> parsed_data)
 {
     foreach (String data in parsed_data)
     {
         Perfume perfume = new Perfume(data);
         AddPerfumeToAllPerfumes(perfume);
         AddPerfumeAccordsToKnownAccords(perfume);
     }
 }
Ejemplo n.º 4
0
 private static void AddPerfumeAccordsToKnownAccords(Perfume perfume)
 {
     foreach (String accord_name in perfume.Accords.Keys)
     {
         if (!KnownAccords.Contains(accord_name))
         {
             KnownAccords.Add(accord_name);
         }
     }
 }
Ejemplo n.º 5
0
        private static void SuggestPerfumeMenu()
        {
            Console.Clear();

            Dictionary <String, int> RequestedAccords = new Dictionary <String, int>();

            RequestedAccords.Add("", 0);
            AcceptedInputs.Clear();
            AcceptedInputs = AcceptedInputs.Concat(PerfumeFinder.GetKnownAccords()).ToList();

            while (RequestedAccords.Keys.ToList().Except(AcceptedInputs).Count() != 0)
            {
                RequestedAccords.Clear();
                Console.WriteLine("---- Suggest Me A Perfume ----\n");
                Console.WriteLine("From this menu, program can suggest to you the closest perfume for your given accords.");
                Console.WriteLine("\nExample input : whiskey:82,citrus:70");
                Console.Write("\nEnter your accord selections : ");

                Input = Console.ReadLine();
                Console.Clear();

                try
                {
                    foreach (String accord_data in Input.Split(','))
                    {
                        RequestedAccords.Add(accord_data.Split(':')[0], Int32.Parse(accord_data.Split(':')[1]));
                    }
                }
                catch (Exception ex)
                {
                    if (ex is ArgumentNullException || ex is FormatException || ex is IndexOutOfRangeException)
                    {
                        RequestedAccords.Add("", 0);
                        continue;
                    }
                    throw;
                }
            }

            Perfume SuggestedPerfume = PerfumeFinder.SuggestPerfumeByRequestedAccords(RequestedAccords);

            Console.WriteLine("---- Suggest Me A Perfume ----\n");
            Console.WriteLine("The program suggest you this perfume !");
            Console.WriteLine($"\n{SuggestedPerfume.Info()}");

            Console.Write("\n -------------------------------------------");
            Console.Write("\n|...Press any key to go back to main menu...|");
            Console.Write("\n -------------------------------------------\n");

            Console.ReadKey();

            Scene = MainMenu;
        }