예제 #1
0
        static void AnlayzeSpotScore()
        {
            var sr           = new StreamReader(JsonFolder_WepApi + "深圳市旅游景点信息.json");
            var records_spot = JsonConvert.DeserializeObject <List <旅游景点信息> >(sr.ReadToEnd());

            sr.Close();

            sr = new StreamReader(JsonFolder_AngularAssets + "旅游目的地包团信息.json");
            var records_tour = JsonConvert.DeserializeObject <List <旅游目的地包团信息> >(sr.ReadToEnd());
            var c            = records_spot.Select(x => (x.Name, records_tour.Count(y => y.IsContain(x.Name)))).ToList();

            c.Sort((x, y) => { return(y.Item2.CompareTo(x.Item2)); });
            Console.WriteLine("地接团TOP10");
            foreach (var item in c.Take(10))
            {
                Console.WriteLine(item.Name + ":" + item.Item2);
            }


            var SpotNameInfo = WordCloudItem.Create(records_spot.Select(x => x.Name).ToList(), 30);

            Console.WriteLine("名称单词TOP30");
            foreach (var item in SpotNameInfo)
            {
                Console.WriteLine(item.name + ":" + item.value);
            }

            records_spot.Sort((x, y) => { return(y.Scenery.CompareTo(x.Scenery)); });
            var top10 = records_spot.Where(x => x.Scenery != 0 && x.ScoreCnt > 50).Take(10);

            Console.WriteLine("景色TOP10");
            foreach (var item in top10)
            {
                Console.WriteLine(item.Name + ":" + item.Scenery + "(" + item.ScoreCnt + ")");
            }

            records_spot.Sort((x, y) => { return(y.Funny.CompareTo(x.Funny)); });
            top10 = records_spot.Where(x => x.Funny != 0 && x.ScoreCnt > 50).Take(10);
            Console.WriteLine("趣味TOP10");
            foreach (var item in top10)
            {
                Console.WriteLine(item.Name + ":" + item.Funny + "(" + item.ScoreCnt + ")");
            }


            records_spot.Sort((x, y) => { return(y.PriceValue.CompareTo(x.PriceValue)); });
            top10 = records_spot.Where(x => x.PriceValue != 0 && x.ScoreCnt > 50).Take(10);
            Console.WriteLine("性价比TOP10");
            foreach (var item in top10)
            {
                Console.WriteLine(item.Name + ":" + item.PriceValue + "(" + item.ScoreCnt + ")");
            }

            records_spot.Sort((x, y) => { return(y.ScoreAvg.CompareTo(x.ScoreAvg)); });
            top10 = records_spot.Where(x => x.ScoreAvg != 0 && x.ScoreCnt > 50).Take(10);
            Console.WriteLine("综合TOP10");
            foreach (var item in top10)
            {
                Console.WriteLine(item.Name + ":" + item.ScoreAvg + "(" + item.ScoreCnt + ")");
            }


            records_spot.Sort((x, y) => { return(x.Scenery.CompareTo(y.Scenery)); });
            top10 = records_spot.Where(x => x.Scenery != 0 && x.ScoreCnt > 50).Take(10);
            Console.WriteLine("景色LOW10");
            foreach (var item in top10)
            {
                Console.WriteLine(item.Name + ":" + item.Scenery + "(" + item.ScoreCnt + ")");
            }

            records_spot.Sort((x, y) => { return(x.Funny.CompareTo(y.Funny)); });
            top10 = records_spot.Where(x => x.Funny != 0 && x.ScoreCnt > 50).Take(10);
            Console.WriteLine("趣味LOW10");
            foreach (var item in top10)
            {
                Console.WriteLine(item.Name + ":" + item.Funny + "(" + item.ScoreCnt + ")");
            }


            records_spot.Sort((x, y) => { return(x.PriceValue.CompareTo(y.PriceValue)); });
            top10 = records_spot.Where(x => x.PriceValue != 0 && x.ScoreCnt > 50).Take(10);
            Console.WriteLine("性价比LOW10");
            foreach (var item in top10)
            {
                Console.WriteLine(item.Name + ":" + item.PriceValue + "(" + item.ScoreCnt + ")");
            }

            records_spot.Sort((x, y) => { return(x.ScoreAvg.CompareTo(y.ScoreAvg)); });
            top10 = records_spot.Where(x => x.ScoreAvg != 0 && x.ScoreCnt > 50).Take(10);
            Console.WriteLine("综合LOW10");
            foreach (var item in top10)
            {
                Console.WriteLine(item.Name + ":" + item.ScoreAvg + "(" + item.ScoreCnt + ")");
            }
        }
예제 #2
0
    public static List <特色美食信息> CreateFood(string xlsxFilename, string jsonFilename, List <特色美食评论> Comments)
    {
        var records      = new List <特色美食信息>();
        var templetefs   = new FileStream(xlsxFilename, FileMode.Open, FileAccess.Read);
        var hssfworkbook = new XSSFWorkbook(templetefs);
        var sheet        = hssfworkbook.GetSheetAt(0);
        var rfirst       = sheet.FirstRowNum;
        var rlast        = sheet.LastRowNum;

        //去掉第一条
        for (int i = 1; i < rlast; i++)
        {
            var row = sheet.GetRow(i);
            var r   = new 特色美食信息();
            r.City    = BaiduApi.DefaultCity;
            r.Name    = row.GetCell(0).StringCellValue;
            r.Address = row.GetCell(1).StringCellValue;
            r.Item    = row.GetCell(2).StringCellValue.Split(",\n".ToCharArray()).Where(x => !string.IsNullOrEmpty(x)).Select(x => x.Trim()).ToArray();

            if (r.Item.Length == 1)
            {
                var itemline = r.Item[0];
                if (itemline.Split(" ").Length != 1)
                {
                    r.Item = itemline.Split(" ");
                }
                else
                {
                    if (itemline.Split("、").Length != 1)
                    {
                        r.Item = itemline.Split("、");
                    }
                }
                r.Item = r.Item.Where(x => !string.IsNullOrEmpty(x)).Select(x => x.Trim()).ToArray();
            }

            r.Price = 0;
            if (row.GetCell(3).CellType == CellType.String)
            {
                var strPrice = row.GetCell(3).StringCellValue;
                if (string.IsNullOrEmpty(strPrice) || strPrice == "0")
                {
                    r.Price = 0;
                }
                else
                {
                    r.Price = int.Parse(strPrice.Substring(1));
                }
            }
            else
            {
                if (row.GetCell(3).CellType == CellType.Numeric)
                {
                    r.Price = (int)row.GetCell(3).NumericCellValue;
                }
            }
            records.Add(r);
        }
        templetefs.Close();

        records = records.Distinct(new 特色美食信息()).ToList();

        foreach (var item in records)
        {
            //GEO信息取得
            var loc = BaiduApi.GetGeoInfo(item.Address);
            item.lat = loc.lat;
            item.lng = loc.lng;
            //评论
            var c = Comments.Where(x => x.Name == item.Name).FirstOrDefault();
            if (c != null)
            {
                //词云的制作
                item.WordCloud    = WordCloudItem.Create(c.Comments, 20);
                item.Comments     = c.Comments.Take(50).ToList();
                item.CommentCount = c.Comments.Count;
            }
        }

        string json = JsonConvert.SerializeObject(records, Formatting.Indented);

        using (var sw = new StreamWriter(jsonFilename, false))
        {
            sw.Write(json);
            sw.Close();
        }

        var FoodRankDict = new Dictionary <string, int>();

        //美食排行榜
        foreach (var r in records)
        {
            foreach (var i in r.Item)
            {
                if (!FoodRankDict.ContainsKey(i))
                {
                    FoodRankDict.Add(i, 0);
                }
                FoodRankDict[i]++;
            }
        }

        var FoodRankTuple = new List <(string, int)>();

        FoodRankTuple = FoodRankDict.Select(x => (x.Key, x.Value)).ToList();
        FoodRankTuple.Sort((x, y) => y.Item2 - x.Item2);

        //Print一下看看
        foreach (var item in FoodRankTuple.Take(20))
        {
            System.Console.WriteLine(item.Item1 + ":" + item.Item2);
        }

        //平均消费
        var PriceAvg = records.Where(x => x.Price != 0).Average(x => x.Price);

        System.Console.WriteLine("平均消费:" + PriceAvg);

        return(records);
    }
예제 #3
0
    public static List <宾馆酒店信息> CreateHotel(string xlsxFilename, string jsonFilename, int LastColIdx, List <宾馆酒店评论> Comments)
    {
        var records      = new List <宾馆酒店信息>();
        var templetefs   = new FileStream(xlsxFilename, FileMode.Open, FileAccess.Read);
        var hssfworkbook = new XSSFWorkbook(templetefs);
        var sheet        = hssfworkbook.GetSheetAt(0);
        var rfirst       = sheet.FirstRowNum;
        var rlast        = sheet.LastRowNum;

        //去掉第一条
        for (int i = 1; i < rlast; i++)
        {
            var row = sheet.GetRow(i);
            if (row.GetCell(0) == null)
            {
                continue;
            }
            var r = new 宾馆酒店信息();
            r.City = BaiduApi.DefaultCity;
            r.Name = row.GetCell(0).StringCellValue;
            if (string.IsNullOrEmpty(r.Name))
            {
                continue;
            }
            if (row.GetCell(1) != null)
            {
                r.Grade = row.GetCell(1).StringCellValue;
            }

            var addr = row.GetCell(2).StringCellValue.Split("\n");
            r.Distract = "";
            r.Address  = "";
            if (addr.Length == 3)
            {
                r.Distract = addr[1].Trim();
                r.Address  = addr[2].Trim();
            }
            if (addr.Length == 2)
            {
                r.Distract = addr[0].Trim();
                r.Address  = addr[1].Trim();
            }
            r.ServiceTel = "";
            r.ServiceFax = "";
            if (row.GetCell(3).CellType == CellType.String)
            {
                r.ServiceTel = row.GetCell(3).StringCellValue;
            }

            if (row.GetCell(3).CellType == CellType.Numeric)
            {
                r.ServiceTel = row.GetCell(3).NumericCellValue.ToString();
            }

            if (r.ServiceTel == "联系方式")
            {
                r.ServiceTel = "";
            }
            r.ServiceTel = r.ServiceTel.TrimEnd("纠错".ToArray()).Trim();
            if (r.ServiceTel.Contains("传真"))
            {
                r.ServiceFax = r.ServiceTel.Substring(r.ServiceTel.IndexOf("传真"));
                r.ServiceTel = r.ServiceTel.Substring(0, r.ServiceTel.IndexOf("传真"));
                r.ServiceFax = r.ServiceFax.TrimStart("传真".ToArray()).Trim();
            }
            if (!string.IsNullOrEmpty(r.ServiceTel))
            {
                r.ServiceTel = r.ServiceTel.TrimStart("电话".ToArray()).Trim();
            }
            //Cell4是联系人,一模一样的

            r.Description = row.GetCell(LastColIdx - 1).StringCellValue.Trim();
            r.Price       = 0;
            if (row.GetCell(LastColIdx).CellType == CellType.String)
            {
                var strPrice = row.GetCell(LastColIdx).StringCellValue;
                if (string.IsNullOrEmpty(strPrice) || strPrice == "0")
                {
                    r.Price = 0;
                }
                else
                {
                    int p;
                    if (int.TryParse(strPrice.Substring(1), out p))
                    {
                        r.Price = p;
                    }
                }
            }
            else
            {
                if (row.GetCell(LastColIdx).CellType == CellType.Numeric)
                {
                    r.Price = (int)row.GetCell(LastColIdx).NumericCellValue;
                }
            }
            records.Add(r);
        }
        templetefs.Close();
        records = records.Distinct(new 宾馆酒店信息()).ToList();
        int cnt = 0;

        foreach (var item in records)
        {
            //评论
            var c = Comments.Where(x => x.Name == item.Name).ToList();
            if (c.Count != 0)
            {
                item.WordCloud    = WordCloudItem.Create(c.Select(x => x.Comment).ToList(), 20);
                item.CommentCount = c.Count;
                item.ScoreCnt     = c.Where(x => x.Score != 0).Count();
                if (item.ScoreCnt != 0)
                {
                    item.Score = System.Math.Round(c.Where(x => x.Score != 0).Average(x => x.Score), 2);
                }
                item.Comments = c.Select(x => x.Comment).Take(50).ToList();
            }
            cnt++;
            //GEO信息取得
            var loc = BaiduApi.GetGeoInfo(item.Address);
            item.lat = loc.lat;
            item.lng = loc.lng;
        }

        string json = JsonConvert.SerializeObject(records, Formatting.Indented);

        using (var sw = new StreamWriter(jsonFilename, false))
        {
            sw.Write(json);
            sw.Close();
        }

        return(records);
    }