Пример #1
0
 public static int Comparison(PlaceSortObj POS1, PlaceSortObj POS2)
 {
     if (POS1.placeRating > POS2.placeRating)
     {
         return(-1);
     }
     else if (POS1.placeRating < POS2.placeRating)
     {
         return(1);
     }
     return(0);
 }
Пример #2
0
        public ActionResult ShowRecommendations()
        {
            String userId = User.Identity.GetUserId();

            var users = from user in db.Users select user;

            int userPos = 0;

            foreach (ApplicationUser user in users)
            {
                if (user.Id == userId)
                {
                    break;
                }
                userPos++;
            }

            var places1   = from place in db.Places select place;
            var placeSize = places1.Count();
            var places    = places1.ToList();

            int[] placePoz = new int[placeSize];
            for (int j = 0; j < placeSize; j++)
            {
                placePoz[j] = j;
            }


            var psi = new ProcessStartInfo();

            psi.FileName = @"C:\Users\vladi\Anaconda3\python.exe";

            // 2) Provide script and arguments
            var script = @"C:\Users\vladi\Desktop\work\An3\TakeMePlaces\TakeMePlaces\ProiectIP\AI\ScriptPython2.py";

            psi.Arguments = $"\"{script}\"";

            // 3) Process configuration
            psi.UseShellExecute        = false;
            psi.CreateNoWindow         = true;
            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError  = true;

            // 4) Execute process and get output
            var errors  = "";
            var results = "";

            using (var process = Process.Start(psi))
            {
                errors  = process.StandardError.ReadToEnd();
                results = process.StandardOutput.ReadToEnd();
            }

            // 5) Display output

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"C:\Users\vladi\Desktop\work\An3\TakeMePlaces\TakeMePlaces\ProiectIP\AI\conka.txt", true))
            {
                file.WriteLine("Errors:");
                file.WriteLine(errors);
                file.WriteLine();
                file.WriteLine("Results:");
                file.WriteLine(results);

                //String pattern = @"\s-\s?[+*]?\s?-\s";

                string[] userRec = results.Split(new char[2] {
                    ']', '['
                });

                string[] userRecPerPlace = userRec[userPos].Split(new char[2] {
                    '\n', ' '
                });

                double[] recPerPlace = new double[placeSize + 10];
                int      i           = 0;
                foreach (string rec in userRecPerPlace)
                {
                    file.WriteLine(rec);
                    double number;
                    if (Double.TryParse(rec.Trim(), out number))
                    {
                        recPerPlace[i] = number;
                    }
                    else
                    {
                        recPerPlace[i] = 0;
                    }

                    i++;
                }

                PlaceSortObj[] PSO = new PlaceSortObj[placeSize];
                for (int k = 0; k < placeSize; k++)
                {
                    PSO[k] = new PlaceSortObj(placePoz[k], recPerPlace[k], places[k]);
                }

                Array.Sort(PSO.ToArray(), Comparison);

                List <Place> placesView = new List <Place>();
                for (int t = 0; t < 5; t++)
                {
                    placesView.Add(PSO[t].place);
                }

                ViewBag.PlacesView = placesView;
            }

            return(View());
        }