public ActionResult GenerateNameSortList(string access_token, string error)
        {
            if (error != null || error == "access_denied")
            {
                return(View("Error"));
            }

            if (string.IsNullOrEmpty(access_token))
            {
                return(View());
            }

            try
            {
                _spotifyApi.Token = access_token;
                SpotifyService spotifyService = new SpotifyService(_spotifyApi);
                //Get user_id and user displayName
                SpotifyUser spotifyUser = spotifyService.GetUserProfile();
                ViewBag.UserName = spotifyUser.DisplayName;

                Tracks       tocadasRecentemente = spotifyService.GetRecentlyPlayed();
                List <Audio> metaAudios          = spotifyService.GetAudioTracks(tocadasRecentemente, spotifyUser);



                /*//Usando o framework ML
                 * string _dataPath = Path.Combine(Environment.CurrentDirectory, "Dados", spotifyUser+"musicas.csv");
                 * string _modelPath = Path.Combine(@"C:\Users\fran\Documents\Docs\" + spotifyUser.UserId + "musicasSaida.csv");
                 *
                 * var env = new LocalEnvironment();
                 * var reader = new TextLoader(env,
                 * new TextLoader.Arguments()
                 * {
                 * Separator = ";",
                 * HasHeader = true,
                 * Column = new[]
                 * {
                 *          new TextLoader.Column("Speechiness", DataKind.R4, 0),
                 *          new TextLoader.Column("Liveness", DataKind.R4, 1),
                 *          new TextLoader.Column("Energy", DataKind.R4, 2),
                 *          new TextLoader.Column("Danceability", DataKind.R4, 3)
                 *
                 * }
                 * });
                 * IDataView trainingDataView = reader.Read(new MultiFileSource(_dataPath));
                 * var pipeline = new TermEstimator(env, "Label", "Label")
                 * .Append(new ConcatEstimator(env, "Speechiness", "Liveness", "Energy", "Danceability", "PetalWidth"))
                 * .Append(new SdcaMultiClassTrainer(env, new SdcaMultiClassTrainer.Arguments()))
                 * .Append(new KeyToValueEstimator(env, "PredictedLabel"));
                 *
                 * // STEP 4: Train your model based on the data set
                 * var model = pipeline.Fit(trainingDataView);
                 *
                 * // var x = spotifyService.MeuK(metaAudios);
                 * //  metaAudios = spotifyService.calcDistancias(metaAudios);
                 *
                 * //playlistProntas = spotifyService.Knn(metaAudios);
                 *
                 * /* string uriCallback = "http:%2F%2Flocalhost:12029%2FHome%2FPost";
                 * string clientId = "215f619c52da4befaa569f12a2108b41";
                 * string completo = "https://accounts.spotify.com/en/authorize?client_id=" + clientId +
                 *    "&response_type=token&redirect_uri=" + uriCallback +
                 *    "&state=&scope=" + Scope.PLAYLIST_MODIFY_PRIVATE.GetStringAttribute(" ") +
                 *    "&show_dialog=true";
                 * ViewBag.AuthUri = completo;*/

                return(RedirectToAction("Create", "Usuarios"));
                // Post(access_token, error, playlistProntas);
                //return View("Teste", playlistProntas);
            }
            catch (Exception e)
            {
                return(View("Error"));
            }
        }
        /*  public ActionResult PlayLists() {
         *    ViewBag.usuario = spotifyUser.DisplayName;
         *    return View(db.Musicas.Where(m => m.idUsuario.Equals(spotifyUser.UserId)).ToList());
         * }*/

        public ActionResult GenerateNameSortList(string access_token, string error)
        {
            if (error != null || error == "access_denied")
            {
                return(View("Error"));
            }

            if (string.IsNullOrEmpty(access_token))
            {
                return(View());
            }

            try
            {
                _spotifyApi.Token = access_token;
                SpotifyService spotifyService = new SpotifyService(_spotifyApi);
                //Get user_id and user displayName
                spotifyUser      = spotifyService.GetUserProfile();
                ViewBag.UserName = spotifyUser.DisplayName;

                Tracks tocadasRecentemente = spotifyService.GetRecentlyPlayed();

                List <Audio> metaAudios = spotifyService.GetAudioTracks(tocadasRecentemente, spotifyUser);
                // GeraPlayLists();

                /*HttpContext.Current.Server.MapPath("~/Content/Dados/");
                 * using (var sw = new StreamWriter(path + nomeArquivo + "musicas.csv"))*/
                string _dataPath   = System.Web.HttpContext.Current.Server.MapPath("~/Content/Dados/" + spotifyUser.UserId + "_" + spotifyUser.DisplayName + "musicas.csv");
                string _dataPath2  = System.Web.HttpContext.Current.Server.MapPath("~/Content/Dados/dataSpotify.csv");
                string _modelPath  = System.Web.HttpContext.Current.Server.MapPath("~/Content/Dados/p1.zip");
                string _modelPath2 = System.Web.HttpContext.Current.Server.MapPath("~/Content/Dados/p2.zip");
                string nomeArq     = spotifyUser.UserId + "_" + spotifyUser.DisplayName + "musicas.csv";
                var    model1      = PredictionModel.ReadAsync <Musica, ClusterPrediction>(_modelPath).Result;
                var    model2      = PredictionModel.ReadAsync <Musica, ClusterPrediction>(_modelPath2).Result;
                var    rec         = spotifyService.geraplay(_dataPath, _dataPath2, model1, model2);
                rec.Nome      = spotifyUser.DisplayName;
                rec.IdUsuario = spotifyUser.UserId;

                foreach (var musicasp1 in rec.P1)
                {
                    musicasp1.IdUsuario = spotifyUser.UserId;
                    // db.Musicas.Add(musicasp1);
                }
                foreach (var musicasp2 in rec.P2)
                {
                    musicasp2.IdUsuario = spotifyUser.UserId;
                    //db.Musicas.Add(musicasp2);
                }
                foreach (var musicasp3 in rec.P3)
                {
                    musicasp3.IdUsuario = spotifyUser.UserId;
                    //db.Musicas.Add(musicasp3);
                }

                // db.SaveChanges();
                TempData["rec"]       = rec;
                TempData["nomeArqui"] = nomeArq;

                return(RedirectToAction("Index", "Musicas"));
                //   return RedirectToAction("Playlists", rec);
                // Post(access_token, error, playlistProntas);
                //return View("Teste", playlistProntas);
            }
            catch (Exception e)
            {
                return(View("Error"));
            }
        }