public static float GetWordWeight(WordCloudItem word) { float weight = word.weight * 10; if (weight > 50) { weight = 40; } return weight; }
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); }
public static RectangleF GetRectangleF(WordCloudItem item) { return new RectangleF (item.x, item.y, item.width, item.height); }
void DrawWord(WordCloudItem word) { Console.WriteLine ("drawing word:"+word); RectangleF myRect = IndexerUtils.GetRectangleF (word); UIFont myFont = UIFont.FromName("Helvetica-BoldOblique", IndexerUtils.GetWordWeight(word)); string myText = word.word; //BEGIN PAINTCODE; // Color Declarations UIColor color = UIColor.FromRGBA(0.000f, 0.429f, 0.143f, 1.000f); UIColor color3 = UIColor.FromRGBA(0.819f, 0.069f, 0.069f, 1.000f); UIColor color2 = UIColor.Purple; UIColor color4 = UIColor.FromRGBA(0.925f, 0.040f, 0.704f, 1.000f); Random rnd = new Random (); int index = rnd.Next (1,4); //NON PAINTCODE SECTION if (index == 1) { color.SetFill(); } if (index == 2) { color2.SetFill(); } if (index == 3) { color3.SetFill(); } if (index == 4) { color4.SetFill(); } //END NON PAINTCODE SECTION // Abstracted Attributes // var hello1Content = "Hello, World!"; // var hello2Content = "Hello, World!"; // Hello1 Drawing //var hello1Rect = new RectangleF(34, 31, 110, 16); new NSString(myText).DrawString(myRect, myFont, UILineBreakMode.WordWrap, UITextAlignment.Center); // //// Hello2 Drawing // var hello2Rect = new RectangleF(44, 72, 76, 26); // color.SetFill(); // new NSString(hello2Content).DrawString(hello2Rect, UIFont.FromName("Helvetica-BoldOblique", 12), UILineBreakMode.WordWrap, UITextAlignment.Center); // Rectangle Drawing // var rectangleRect = new RectangleF(143.5f, 15.5f, 42, 79); // var rectanglePath = UIBezierPath.FromRoundedRect(rectangleRect, 20); // UIColor.White.SetFill(); // rectanglePath.Fill(); // UIColor.Black.SetStroke(); // rectanglePath.LineWidth = 1; // rectanglePath.Stroke(); // color.SetFill(); // new NSString("Kake").DrawString(RectangleF.Inflate(rectangleRect, -6, -7), UIFont.FromName("Helvetica", 12), UILineBreakMode.WordWrap, UITextAlignment.Center); }
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 + ")"); } }
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); }
// public List<Item> SearchItems (string text) // { // // //TODO implement async here when async (mono 3.0) gets out of BETA // List<Item> res = new List<Item>(); // // res.AddRange(dao.GetItemsWithName(text)); // res.AddRange(dao.GetItemsWithDesc(text)); // // //Console.WriteLine("Found "+res.Count + " items "); // return res; // } public List<WordCloudItem> GetWordCloudDictionary() { List<WordCloudItem> dictionary = new List<WordCloudItem> (); List<IndexerDictionaryItem> origin = GetAllSearchableWordsDictionary (); foreach (IndexerDictionaryItem item in origin) { WordCloudItem it = new WordCloudItem (); it.word = item.value; Boolean found = false; foreach (WordCloudItem cloudItem in dictionary) { if (cloudItem != null && it != null) { if (cloudItem.Equals (it)) { cloudItem.weight++; found = true; } } } if (!found) { it.weight = 1; dictionary.Add (it); } } return dictionary; }