private void UpdateTree() { treeView1.BeginUpdate(); var userIdx = 0; foreach (KeyValuePair <string, Stats> item in UserInfos.OrderBy(key => - key.Value.Likes)) { var userNode = userIdx < GetUsersNode().Nodes.Count ? GetUsersNode().Nodes[userIdx++] : GetUsersNode().Nodes.Add(userIdx++.ToString()); userNode.Text = item.Key + " — " + item.Value.ToShortString(); userNode.ToolTipText = item.Key + "\r\n" + item.Value.ToString(); userNode.Tag = item.Key; } GetUsersNode().Text = "Юзеры — " + UserInfos.Count(); var catIdx = 0; foreach (KeyValuePair <string, Stats> item in CatInfos.OrderBy(key => key.Key)) { var catNode = catIdx < GetCatsNode().Nodes.Count ? GetCatsNode().Nodes[catIdx++] : GetCatsNode().Nodes.Add(catIdx++.ToString()); catNode.Text = item.Key + " — " + item.Value.ToShortString(); catNode.ToolTipText = item.Key + "\r\n" + item.Value.ToString(); catNode.Tag = item.Key; } GetCatsNode().Text = "Категории — " + CatInfos.Count(); var monthIdx = 0; foreach (KeyValuePair <MonthYear, Stats> item in MonthInfos.OrderBy(key => key.Key.GetDate(1)).Reverse()) { var monthNode = monthIdx < GetMonthsNode().Nodes.Count ? GetMonthsNode().Nodes[monthIdx++] : GetMonthsNode().Nodes.Add(monthIdx++.ToString()); monthNode.Text = item.Key.ToString() + " — " + item.Value.ToShortString(); monthNode.ToolTipText = item.Key.ToString() + "\r\n" + item.Value.ToString(); monthNode.Tag = item.Key; } GetMonthsNode().Text = "Месяцы — " + MonthInfos.Count(); treeView1.EndUpdate(); }
private void UpdateStats(TorrentInfo t) { using (var db = new NnmContext()) { var uri = new Uri("http://nnmclub.to/" + t.Ref); var query = HttpUtility.ParseQueryString(uri.Query); var tt = query.Get("t"); t.ID = int.Parse(tt); db.InsertOrReplace(t); } if (!UserInfos.ContainsKey(t.User)) { UserInfos.Add(t.User, new Stats { Count = 1, Likes = t.Likes }); using (var db = new NnmContext()) { db.Insert(new UserInfo { Name = t.User }); } } else { UserInfos[t.User].Count += 1; UserInfos[t.User].Likes += t.Likes; } if (!CatInfos.ContainsKey(t.Category)) { CatInfos.Add(t.Category, new Stats { Count = 1, Likes = t.Likes }); using (var db = new NnmContext()) { db.Insert(new CategoryInfo { Name = t.Category }); } } else { CatInfos[t.Category].Count += 1; CatInfos[t.Category].Likes += t.Likes; } if (!MonthInfos.ContainsKey(new MonthYear(t.Published))) { MonthInfos.Add(new MonthYear(t.Published), new Stats { Count = 1, Likes = t.Likes }); } else { MonthInfos[new MonthYear(t.Published)].Count += 1; MonthInfos[new MonthYear(t.Published)].Likes += t.Likes; } }
private void Form1_Load(object sender, EventArgs e) { splitContainer1.SplitterDistance = Settings.Default.TreeViewWidth; using (var db = new NnmContext()) { (from t in db.Torrents group t by t.Category into g select new { Category = g.Key, Count = g.Count(), Likes = g.Sum(t => t.Likes) } ).ToList().ForEach(c => { CatInfos.Add(c.Category, new Stats { Count = c.Count, Likes = c.Likes }); }); (from t in db.Torrents group t by t.User into g select new { User = g.Key, Count = g.Count(), Likes = g.Sum(u => u.Likes) } ).ToList().ForEach(c => { UserInfos.Add(c.User, new Stats { Count = c.Count, Likes = c.Likes }); }); } }