Inheritance: FourSquareEntity
 public SearchLocationsViewModel()
 {
     Latitude = 54.8693482;
     Longitude = 83.0785167;
     Query = "школа";
     Radius = 3000;
     Venues = new List<Venue>();
     ChosenVenues = new List<Venue>();
 }
        public Result<Place[]> SearchPlace(string lat, string lng, string query)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            if (!string.IsNullOrEmpty(query))
                parameters.Add("query", query);
            parameters.Add("ll", string.Format("{0},{1}", lat, lng));

            List<Place> result = new List<Place>();
            List<Venue> apiResult = _FSClient.SearchVenues(parameters);

            foreach (var venue in apiResult)
            {
                result.Add(this.ConvertPlace(venue));
            }

            return this.GetResult(result.ToArray());
        }
        /// <summary>
        /// Transforms provided list of Venues to list of FPlaces. If list of recent Checkins is provided, places will contain names of friends that checked at specific place.
        /// </summary>
        /// <param name="venues">list of Venue objects to transform</param>
        /// <param name="checkins">list of Checkin objects to include in places</param>
        /// <returns>list of transformed FPlaces</returns>
        public static List<FPlace> TransformToFPlaces(List<Venue> venues, List<Checkin> checkins)
        {
            if (venues == null)
                throw new ArgumentNullException("venues");

            List<FPlace> places = new List<FPlace>();

            venues.ForEach(venue =>
                {
                    FPlace place = new FPlace
                    {
                        Id = venue.id,
                        Name = venue.name,
                        Location = new Location
                            {
                                Latitude = venue.location != null ? venue.location.lat : 0,
                                Longitude = venue.location != null ? venue.location.lng : 0
                            },
                        Address = venue.location != null ? venue.location.address : string.Empty,
                        City = venue.location != null ? venue.location.city : string.Empty,
                        Country = venue.location != null ? venue.location.country : string.Empty,
                        FormattedAddress = venue.location != null ? venue.location.formattedAddress : null,
                        Phone = venue.contact != null ? venue.contact.phone : string.Empty,
                        Category = venue.categories != null ? venueCatManager.GetOurCategory(venue.categories) : string.Empty,
                        CheckinsCount = venue.stats != null ? venue.stats.checkinsCount : 0,
                        HereNow = venue.hereNow != null ? venue.hereNow.count : 0,
                        Url = venue.url
                    };

                    if (checkins != null)
                    {
                        checkins.ForEach(checkin =>
                        {
                            if (checkin.venue != null && checkin.venue.id == venue.id && checkin.user != null)
                                place.FriendsHere.Add(checkin.user.firstName + " " + checkin.user.lastName);
                        });
                    }

                    places.Add(place);
                });

            return places;
        }
 public CommentByTagViewModel()
 {
     Tags = new List<TagsCount>();
 }
        public ActionResult AdicionarTips()
        {
            SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret);
            List<Banco.Models.Tip> tiplist = new List<Banco.Models.Tip>();
            List<Banco.Models.User> userlist = new List<Banco.Models.User>();
            List<Banco.Models.Venue> venuelist = new List<Banco.Models.Venue>();
            Dictionary<string, string> parametros = new Dictionary<string, string>();
            List<FourSquare.SharpSquare.Entities.Venue> venues = new List<FourSquare.SharpSquare.Entities.Venue>();
            List<FourSquare.SharpSquare.Entities.Tip> tips = new List<FourSquare.SharpSquare.Entities.Tip>();
            parametros.Add("limit", "500"); // tentando pegar ateh 500 venues e tips

            for (double lon = -43.2652; lon < -43.2475; lon += 0.0005)
            {

                parametros.Remove("limit");
                parametros.Add("limit", "50");
                parametros.Add("ll", "-22.8707," + lon.ToString().Replace(',', '.'));
                venues = sharpSquare.SearchVenues(parametros);

                foreach (FourSquare.SharpSquare.Entities.Venue v in venues)
                {
                    Banco.Models.Venue ven;
                    ven = db.Venues.FirstOrDefault(f => f.SquareId == v.id);
                    if (ven == null && venuelist.FirstOrDefault(f => f.SquareId == v.id) == null)
                    {
                        ven = new Banco.Models.Venue();
                        ven.SquareId = v.id;
                        ven.lat = -22.8707;
                        ven.lon = lon;
                        venuelist.Add(ven);
                        db.Venues.Add(ven);
                    }
                    ven.Name = v.name;
                    parametros.Remove("ll");
                    parametros.Remove("limit");
                    parametros.Add("limit", "500");
                    tips = sharpSquare.GetVenueTips(v.id, parametros);
                    foreach (FourSquare.SharpSquare.Entities.Tip t in tips)
                    {
                        Banco.Models.Tip tip;
                        //Verifica de tip já foi adicionada anteriormente no banco
                        tip = db.Tips.FirstOrDefault(f => f.SquareId == t.id);
                        if (tip == null && tiplist.FirstOrDefault(f => f.SquareId == t.id) == null)
                        {
                            //Se é uma tip nova cria uma e adiciona no context
                            tip = new Banco.Models.Tip();
                            tip.SquareId = t.id;
                            tip.Venue = ven;
                            tiplist.Add(tip);
                            db.Tips.Add(tip);

                        }
                        //sendo tip nova ou não atualiza os campos
                        tip.Description = t.text;
                        Banco.Models.User user;
                        user = db.Users.FirstOrDefault(f => f.SquareId == t.user.id);
                        if (user == null && userlist.FirstOrDefault(f => f.SquareId == t.user.id) == null)
                        {
                            user = new Banco.Models.User();
                            user.SquareId = t.user.id;
                            user.Name = t.user.firstName;
                            userlist.Add(user);
                            db.Users.Add(user);
                        }
                        if (user == null && userlist.FirstOrDefault(f => f.SquareId == t.user.id) != null)
                        {
                            user = userlist.FirstOrDefault(f => f.SquareId == t.user.id);
                        }
                        tip.User = user;
                    }
                }
                db.SaveChanges();
            }
            ViewBag.Message = "Venues, tips e users adicionados ao banco com sucesso.";
            return View();
        }
        private void SaveLocations_Click(object sender, RoutedEventArgs e)
        {
            var deleted = new List<Venue>();
            deleted.AddRange(UserFactory.Insta.LocationsToProcess.Where(x => !ViewModel.ChosenVenues.Any(y => y == x)));

            UserFactory.Insta.LocationsToProcess = UserFactory.Insta.LocationsToProcess.Except(deleted);
            UserFactory.Insta.LocationsToProcess = UserFactory.Insta.LocationsToProcess.Concat(ViewModel.ChosenVenues.Where(x => !UserFactory.Insta.LocationsToProcess.Any(y => y == x)));

            var result = MessageBox.Show("Локации сохранены, доступны во вкладках \"Комменты\" и \"Лайки\"");
        }
        public ActionResult readPredictFromFile()
        {
            List<char> listaPredict = new List<char>();
            List<string> listId = new List<string>();
            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader("C:\\Users\\Avell B155 MAX\\Documents\\facul\\projetofinal\\Python notebook\\unclasspredicaofinal.txt"))
                {
                    // Read the stream to a string, and write the string to the console.
                    sr.ReadLine();
                    sr.ReadLine();
                    sr.ReadLine();
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();
                        listaPredict.Add(line[25]);

                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader("C:\\Users\\Avell B155 MAX\\Documents\\facul\\projetofinal\\Python notebook\\attributes2.txt"))
                {
                    // Read the stream to a string, and write the string to the console.
                    while (!sr.EndOfStream)
                    {
                        string line = sr.ReadLine();
                        listId.Add(line);

                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
            var tips = db.Tips.Where(w => w.status == 0).OrderBy(o => o.Id);
            int countId = 0;
            int countProgress = 0;
            foreach (Banco.Models.Tip t in tips)
            {
                countId++;

                if (int.Parse(listId.ElementAt(countProgress)) == countId)
                {
                    t.WekaPredictFinal = int.Parse(listaPredict.ElementAt(countProgress).ToString());
                    countProgress++;
                }
            }
            db.SaveChanges();
            ViewBag.Teste = listId;
            return View();
        }
        public void SatisfacaoInterna()
        {
            List<Banco.Models.User> users = db.Users.ToList();

            foreach (Banco.Models.User u in users)
            {
                List<Banco.Models.Tip> tipsUser = db.Tips.Where(w => w.UserId == u.Id && w.WekaPredictFinal != 0).ToList();
                List<int> listaDesvio = new List<int>();
                foreach (Banco.Models.Tip t in tipsUser)
                {
                    if (t.WekaPredictFinal == 1)
                    {
                        listaDesvio.Add(10);
                    }
                    else if (t.WekaPredictFinal == 2)
                    {
                        listaDesvio.Add(5);
                    }
                    else
                        listaDesvio.Add(0);
                }
                if (tipsUser.Count < 6)
                    u.pesoInterno = 1;
                else
                    u.pesoInterno = (float)CalculateStdDev(listaDesvio);
                //if (u.pesoInterno < 3)
                //    u.pesoInterno = 1;
                //else if (u.pesoInterno >= 3 && u.pesoInterno <= 4)
                //    u.pesoInterno = 2;
                //else if (u.pesoInterno > 4)
                //    u.pesoInterno = 3;
            }
            db.SaveChanges();
            List<Banco.Models.Venue> venues = db.Venues.ToList();
            foreach (Banco.Models.Venue v in venues)
            {
                List<Banco.Models.Tip> tipsVenue = db.Tips.Where(w => w.VenueId == v.Id).ToList();
                float somaPesos = 0;
                float somaTotal = 0;
                foreach (Banco.Models.Tip t in tipsVenue)
                {
                    if (t.WekaPredictFinal == 1)
                    {
                        somaTotal += 10 * t.User.pesoInterno;
                    }
                    else if (t.WekaPredictFinal == 2)
                    {
                        somaTotal += 5 * t.User.pesoInterno;
                    }
                    somaPesos += t.User.pesoInterno;
                }
                if (somaPesos == 0)
                    v.ratePesoInterno = 0;
                else
                    v.ratePesoInterno = somaTotal / (double)somaPesos;
            }
            db.SaveChanges();
        }
        public void WriteARFF()
        {

            // Write the string to a file.
            System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\Users\\Avell B155 MAX\\Documents\\facul\\projetofinal\\lasttestDuasClassesMedianaComp.arff");
            file.WriteLine("% 1. Title: Sentiment Analysis\n");
            file.WriteLine("@RELATION tips\n");
            file.WriteLine("@ATTRIBUTE sent1        NUMERIC");
            file.WriteLine("@ATTRIBUTE sent2        NUMERIC");
            file.WriteLine("@ATTRIBUTE sent3        NUMERIC");
            file.WriteLine("@ATTRIBUTE sent4        NUMERIC");
            file.WriteLine("@ATTRIBUTE sent5        NUMERIC");
            file.WriteLine("@ATTRIBUTE mean1        NUMERIC");
            file.WriteLine("@ATTRIBUTE mean2        NUMERIC");
            file.WriteLine("@ATTRIBUTE mean3        NUMERIC");
            file.WriteLine("@ATTRIBUTE mean4        NUMERIC");
            file.WriteLine("@ATTRIBUTE mean5        NUMERIC");
            file.WriteLine("@ATTRIBUTE stdv1        NUMERIC");
            file.WriteLine("@ATTRIBUTE stdv2        NUMERIC");
            file.WriteLine("@ATTRIBUTE stdv3        NUMERIC");
            file.WriteLine("@ATTRIBUTE stdv4        NUMERIC");
            file.WriteLine("@ATTRIBUTE stdv5        NUMERIC");
            file.WriteLine("@ATTRIBUTE class        {0,1}\n");
            file.WriteLine("@DATA");
            var tips = db.Tips.Where(w => w.Venue.rate != 0 && w.WekaPredictFinal != 0).GroupBy(g => g.VenueId);
           
            foreach (var g in tips)
            {
                string line = "";
                List<int> sents = new List<int>();
                List<double> means = new List<double>();
                List<float> stdvs = new List<float>();
                string classe = "0";
                if (g.Count() > 4)
                {
                    Banco.Models.Venue v = db.Venues.Find(g.Key);
                    //if (v.rate < 5)
                    //    classe = "0";
                    //else if (v.rate >= 5 && v.rate <= 6)
                    //    classe = "1";
                    //else if (v.rate > 6 && v.rate <= 8)
                    //    classe = "2";
                    //else
                    //    classe = "3";
                    classe = v.rate > 6.9 ? "1" : "0";
                    foreach (var t in g.Take(5))
                    {
                        sents.Add(t.WekaPredictFinal);
                        if (t.User.pesoInterno != 1)
                        {
                            means.Add(t.User.mediaComentarios);
                            stdvs.Add(t.User.pesoInterno);
                        }
                    }
                    if (means.Count != 0)
                    {
                        if (means.Count != 5)
                        {
                            int cont = means.Count;
                            for (int i = 0; i < 5 - cont; i++)
                            {
                                means.Add(means.Sum() / means.Count);
                                stdvs.Add(stdvs.Sum() / stdvs.Count);
                            }
                        }
                        foreach (int sent in sents)
                        {
                            line += sent.ToString() + ",";
                        }
                        foreach (double mean in means)
                        {
                            line += mean.ToString().Replace(',', '.') + ",";
                        }
                        foreach (float stdv in stdvs)
                        {
                            line += stdv.ToString().Replace(',', '.') + ",";
                        }
                        line += classe;
                        file.WriteLine(line);
                    }
                }
            }

            file.Close();
        }
Beispiel #10
0
        protected Venue BuscarAgregarEstablecimiento(Establecimiento establecimiento)
        {
            var listaNiveles = new List<string>
                                           {
                                               "Inicial",
                                               "Primario",
                                               "Secundario"
                                           };

            Venue fourSquareVenue = null;
            var sharpSquare = (SharpSquare)Session["SharpSquare"];

            if (establecimiento.FourSquareVenueId == null)
            {
                var latitudLongitud = establecimiento.Latitud.ToString(CultureInfo.InvariantCulture.NumberFormat)
                                      + "," +
                                      establecimiento.Longitud.ToString(CultureInfo.InvariantCulture.NumberFormat);

                var parametros = new Dictionary<string, string>();
                parametros.Add("ll", latitudLongitud);
                parametros.Add("intent", "match");
                var nombreReducido = establecimiento.Nombre.ToLower()
                    .Replace("inst.", "")
                    .Replace("instituto", "")
                    .Replace("colegio", "")
                    .Replace("coleg.", "")
                    .Replace("priv.", "")
                    .Replace("integral", "")
                    .Replace("escuela", "")
                    .Replace("educ.", "")
                    .Replace("fund.", "")
                    .Replace("fundacion", "")
                    .Replace("secundaria", "")
                    .Replace("primaria", "")
                    .Replace("infantil", "")
                    .Replace("jardin", "")
                    .Replace("jardin de infantes", "")
                    .Replace("maternal", "")
                    .Replace("parroquial", "")
                    .Trim();
                parametros.Add("query", nombreReducido);

                var categorias = new List<string>();

                //categorias.Add("4bf58dd8d48988d131941735"); //Centro Espiritual
                if (establecimiento.NivelTipo.Any(x => listaNiveles.Contains(x.NivelEducativo.Valor)))
                {
                    categorias.Add("4bf58dd8d48988d13b941735"); //Colegio
                }
                else
                {
                    if (establecimiento.NivelTipo.Any(x => x.NivelEducativo.Valor == "Otros"))
                    {
                        categorias.Add("4bf58dd8d48988d1f2931735"); //Lugar de Artes interpretativas
                    }
                    else
                    {
                        categorias.Add("4d4b7105d754a06372d81259"); //Facultades y Universidades
                    }
                }
                parametros.Add("categoryId", String.Join(",", categorias));
                Logger.Error("Hago un Search Venues");
                var listaDeLugares = sharpSquare.SearchVenues(parametros);

                Venue lugar = null;
                //Busco el Id de FourSquare

                lugar = listaDeLugares.OrderBy(x => Math.Abs(x.location.lat - establecimiento.Latitud)
                    + Math.Abs(x.location.lng - establecimiento.Longitud)
                    ).FirstOrDefault();
                if (lugar == null)
                {
                    var venue = new Dictionary<string, string>();
                    venue.Add("name", establecimiento.Nombre);
                    venue.Add("address", establecimiento.Direccion);
                    venue.Add("city", "Buenos Aires");
                    venue.Add("state", "Buenos Aires");
                    //venue.Add("phone", establecimiento.Telefonos); //Tira error por ser una string y no un numero
                    venue.Add("ll", establecimiento.Latitud.ToString(CultureInfo.InvariantCulture.NumberFormat)
                                        + "," +
                                        establecimiento.Longitud.ToString(CultureInfo.InvariantCulture.NumberFormat));

                    if (establecimiento.NivelTipo.Any(x => listaNiveles.Contains(x.NivelEducativo.Valor)))
                    {
                        venue.Add("primaryCategoryId", "4bf58dd8d48988d13b941735"); //Colegios
                    }
                    else
                    {
                        if (establecimiento.NivelTipo.Any(x => x.NivelEducativo.Valor == "Otros"))
                        {
                            venue.Add("primaryCategoryId", "4bf58dd8d48988d1f2931735"); //Artes Interpretativas
                        }
                        else
                        {
                            venue.Add("primaryCategoryId", "4bf58dd8d48988d198941735"); //Edificio Universitario
                        }
                    }
                    Logger.Error("Agrego un Venue");
                    fourSquareVenue = sharpSquare.AddVenue(venue);
                    fourSquareVenue = sharpSquare.GetVenue(fourSquareVenue.id);
                    return fourSquareVenue;
                }
                Logger.Error("Hago un getvenue por Id");
                fourSquareVenue = sharpSquare.GetVenue(lugar.id);
                return fourSquareVenue;
            }
            Logger.Error("Hago un getvenue por Id que ya tengo guardada");
            fourSquareVenue = sharpSquare.GetVenue(establecimiento.FourSquareVenueId);
            return fourSquareVenue;
        }
 public LikeByTagViewModel()
 {
     Tags = new List<TagsCount>();
 }