protected static void DemoAlignment() { rc2.Settings.Align = delegate(RowConf me, int colindex, string s) { switch (colindex) { case 0: return(RowCollectionSettings.ALIGN.RIGHT); case 1: return(null); case 2: return(RowCollectionSettings.ALIGN.RIGHT); case 3: return(RowCollectionSettings.ALIGN.CENTER); default: return(RowCollectionSettings.ALIGN.LEFT); } }; rc2.Settings.Border.HorizontalLineBody = delegate(RowConf r) { return(true); }; CoEx.WriteTitleLarge("Tables - Chapter 5"); CoEx.WriteLine(); CoEx.WriteTitle("Column alignment"); CoEx.WriteTable(rc2); }
protected static void BasicTableLongText() { CoEx.WriteTitleLarge("Tables - Chapter 2"); CoEx.WriteLine(); CoEx.WriteTitle("The basic table with long text"); rc2.Import(0, header); CoEx.WriteTable(rc2); }
protected static void DemoBasicTable() { CoEx.WriteTitleLarge("Tables - Chapter 1"); CoEx.WriteLine(); CoEx.WriteTitle("The basic table"); rc1.Settings.StretchHorizontal = false; CoEx.WriteTable(rc1); rc1.Settings.StretchHorizontal = true; CoEx.WriteLine(); CoEx.WriteTitle("The basic table with header, stretched to window width"); rc1.Import(0, header); CoEx.WriteTable(rc1); CoEx.WriteLine(); CoEx.WriteTitle("The basic table, border disabled"); rc1.Settings.Border.Enabled = false; // override default CoEx.WriteTable(rc1); }
protected static void DemoTableSynchronized() { var length = RowCollection.Create().Import(rc1).Import(rc2).Length; rc1.Length = length; rc1.Settings.Border.Enabled = true; // enable border again rc1.Settings.Border.HorizontalLineBody = BorderConf.HorizontalLineAfterHeaderFunc; rc2.Length = length; rc2.Settings.Border.Enabled = true; CoEx.WriteTitleLarge("Tables - Chapter 3"); CoEx.WriteLine(); CoEx.WriteTitle("Synchonize column length over multiple tables"); CoEx.WriteLine(); CoEx.WriteTitle("The basic table, border header-only"); CoEx.WriteTable(rc1); CoEx.WriteLine(); CoEx.WriteTitle("The basic table with long text"); CoEx.WriteTable(rc2); }
protected static void DemoConditionalStyles() { CoEx.WriteTitleLarge("Tables - Chapter 4"); CoEx.WriteLine(); CoEx.WriteTitle("Colorize cells by conditions"); // colorize column by index rc1.Settings.Color = delegate(RowConf me, int colindex, string s) { var temp = new ColorScheme(null, ConsoleColor.Blue); switch (colindex) { case 0: temp.Background = ConsoleColor.Cyan; break; case 1: temp.Background = ConsoleColor.White; break; case 2: temp.Background = ConsoleColor.Magenta; break; case 3: temp.Background = ConsoleColor.Red; break; default: temp.Background = ConsoleColor.Gray; break; } return(temp); }; // Highlight padding every second column rc1.Settings.IsHighlightPadding = delegate(RowConf me, int colindex, string s) { return((colindex % 2) == 0); }; CoEx.WriteLine(); CoEx.WriteTitle("Background color based on column index"); CoEx.WriteTable(rc1); // if hours>10 is column 2 yellow and column 0 red rc2.Settings.Color = delegate(RowConf me, int colindex, string s) { double hours; bool success = double.TryParse(me.Data[2], out hours); if (colindex == 2 && success && hours >= 10) { return(new ColorScheme(ConsoleColor.Yellow, ConsoleColor.Blue)); } else if (colindex == 0 && success && hours >= 10) { return(new ColorScheme(ConsoleColor.Red, null)); } else { return(null); } }; // highlight padding in column 0 rc2.Settings.IsHighlightPadding = delegate(RowConf me, int colindex, string s) { return(colindex == 0); }; CoEx.WriteLine(); CoEx.WriteTitle("Background color based on hours value"); CoEx.WriteTable(rc2); }
private static void PrintStats(string path, string htmloutfile) { using (var thread = Load(path)) using (var writer = new CoExHtmlWriter() { Title = "Das Längste" }) { CoEx.WriteTitleLarge($"Statistics for {thread.StartpageUrl}"); CoEx.WriteLine(); CoEx.WriteLine(new string[] { "If you don't want to appear in this statistic, ", "just add the keyword 'donottrack' to your signature." }); CoEx.WriteLine(); //--> Filter functions bool filteroptoutpost(ThreadPost post) { return((post?.User?.SignatureHtml?.RemoveHtml().Contains("donottrack", StringComparison.InvariantCultureIgnoreCase) ?? false) == false); } bool filteroptoutuser(ForumUser user) { return((user?.SignatureHtml?.RemoveHtml().Contains("donottrack", StringComparison.InvariantCultureIgnoreCase) ?? false) == false); } //--> Default filters var cleanposts = thread.Posts.Where(v => filteroptoutpost(v)); var cleanusers = thread.Users.Users .Where(v => filteroptoutuser(v)) .Intersect(cleanposts.Select(u => u.User).Distinct()); //--> Current status var curstats = new string[][] { new string[] { "JSON file:", Path.GetFileName(path) }, new string[] { "JSON file size:", (new FileInfo(path)).Length.HumanBytes() }, new string[] { "Crawl date:", thread.CrawlTimestamp.ToString("yyyy-MM-dd HH:mm:ss") }, new string[] { "Post count:", cleanposts.Count().ToString("#,###") }, new string[] { "Users involved:", cleanusers.Count().ToString("#,###") }, new string[] { "Banned users:", cleanusers.Where(u => u.IsBanned).Count().ToString("#,###") }, new string[] { "Opt-Out users:", thread.Users.Users.Where(v => filteroptoutuser(v) == false).Count().ToString("#,##0") }, new string[] { "Total likes:", cleanposts.Sum(v => v.LikeCount).ToString("#,##0") }, new string[] { "Total dislikes:", cleanposts.Sum(v => v.DislikeCount).ToString("#,##0") }, new string[] { "Posts with likes:", cleanposts.Where(v => v.LikeCount > 0).Count().ToString("#,##0") }, new string[] { "Posts with dislikes:", cleanposts.Where(v => v.DislikeCount > 0).Count().ToString("#,##0") }, new string[] { "First post:", cleanposts.Min(v => v.Date).ToString("yyyy-MM-dd HH:mm:ss") }, new string[] { "Last post:", cleanposts.Max(v => v.Date).ToString("yyyy-MM-dd HH:mm:ss") }, new string[] { "Thread age:", (cleanposts.Max(v => v.Date) - cleanposts.Min(v => v.Date)).PrettyPrint() }, new string[] { "First user:"******"{v.Key.Username} ({v.Count()})").First() }, new string[] { "Newest user:"******"{v.Key.Username} ({v.Count()})").First() } }; CoEx.WriteTitle("Current status"); CoEx.WriteTable(RowCollection.Create(curstats)); CoEx.WriteLine(); //--> User statistics var userstats = cleanposts .Where(v => v.User != null) .GroupBy(v => v.User) .OrderByDescending(v => v.Count()) .Take(30) .Select(v => new string[] { v.Key.Username, v.Key.PostCount.ToString("#,###"), v.Count().ToString("#,###"), (100.0 * v.Count() / v.Key.PostCount).ToString("0.0") + "%", (100.0 * v.Count() / cleanposts.Count()).ToString("0.0") + "%", v.Min(j => j.Date).ToString("yyyy-MM-dd HH:mm"), v.Max(j => j.Date).ToString("yyyy-MM-dd HH:mm"), v.Key.MemberSince.ToString("yyyy-MM-dd") }) .Prepend(new string[] { "Username", "All Posts", "Thread Posts", "User %", "Thread %", "First Post", "Last Post", "Member since" }); var userrows = RowCollection.Create(userstats.ToArray()); userrows.Settings.Border.Enabled = true; userrows.Settings.Align = (conf, colidx, s) => { switch (colidx) { case 1: case 2: case 3: case 4: return(RowCollectionSettings.ALIGN.RIGHT); default: return(RowCollectionSettings.ALIGN.LEFT); } }; CoEx.WriteTitle("Statistics by user"); CoEx.WriteTable(userrows); CoEx.WriteLine(); //--> User like statistics var userlikes = cleanposts .Where(v => v.User != null) .GroupBy(v => v.User) .Where(v => v.Sum(j => j.LikeCount) > 0) .OrderByDescending(v => v.Sum(j => j.LikeCount)) .Take(10) .Select(v => new string[] { v.Key.Username, v.Sum(j => j.LikeCount).ToString("#,##0"), v.Where(j => j.LikeCount > 0).Min(j => j.Date).ToString("yyyy-MM-dd HH:mm"), v.Where(j => j.LikeCount > 0).Max(j => j.Date).ToString("yyyy-MM-dd HH:mm") }) .Prepend(new string[] { "Username", "Likes", "First like received", "Last like received" }); var userlikerows = RowCollection.Create(userlikes.ToArray()); userlikerows.Settings.Border.Enabled = true; userlikerows.Settings.Align = (conf, colidx, s) => { switch (colidx) { case 1: return(RowCollectionSettings.ALIGN.RIGHT); default: return(RowCollectionSettings.ALIGN.LEFT); } }; CoEx.WriteTitle("Statistics by likes"); CoEx.WriteTable(userlikerows); CoEx.WriteLine(); //--> User title statistics var titlestats = cleanposts .Where(v => v.User != null) .GroupBy(v => v.User.Title) .OrderByDescending(v => v.Count()) .Select(v => new string[] { v.Key, v.Count().ToString("#,###"), v.Min(j => j.Date).ToString("yyyy-MM-dd HH:mm"), v.Max(j => j.Date).ToString("yyyy-MM-dd HH:mm") }) .Prepend(new string[] { "Title", "Posts", "First Post", "Last Post" }); var titlerows = RowCollection.Create(titlestats.ToArray()); titlerows.Settings.Border.Enabled = true; titlerows.Settings.Align = (conf, colidx, s) => { switch (colidx) { case 1: return(RowCollectionSettings.ALIGN.RIGHT); default: return(RowCollectionSettings.ALIGN.LEFT); } }; CoEx.WriteTitle("Statistics by user title"); CoEx.WriteTable(titlerows); CoEx.WriteLine(); //--> Post likes var likeposts = cleanposts .Where(v => v.User != null) .OrderByDescending(v => v.LikeCount) .Take(10) .Select(v => new string[] { v.Date.ToString("yyyy-MM-dd"), v.LikeCount.ToString("#,###"), v.User.Username, v.Url }) .Prepend(new string[] { "Date", "Likes", "Author", "Post Url" }); var likepostrows = RowCollection.Create(likeposts.ToArray()); likepostrows.Settings.Border.Enabled = true; likepostrows.Settings.Align = (conf, colidx, s) => { switch (colidx) { case 1: return(RowCollectionSettings.ALIGN.RIGHT); default: return(RowCollectionSettings.ALIGN.LEFT); } }; CoEx.WriteTitle("Most liked posts"); CoEx.WriteTable(likepostrows); CoEx.WriteLine(); //--> Year statistics var yearmaxlength = cleanposts .GroupBy(v => v.Date.Year) .Select(v => v.Count().ToString().Length) .Max(); var yearstats = cleanposts .GroupBy(v => v.Date.Year) .Select(v => new string[] { v.Key.ToString(), v.Min(j => j.Date).ToString("MM-dd HH:mm"), v.Max(j => j.Date).ToString("MM-dd HH:mm"), v.GroupBy(j => j.User).Count().ToString("#,###"), v.Count().ToString("#,###"), string.Join(", ", v.GroupBy(j => j.User).OrderByDescending(j => j.Count()).Take(3).Select(j => $"{j.Key?.Username??"Guest"} ({j.Count()})")), v.Max(j => j.MessageHtml.RemoveHtml().Length).ToString("#,###") }) .Prepend(new string[] { "Year", "First Post", "Last Post", "Active", "Posts", "Top Users", "Largest Msg" }); var yeargraphstats = cleanposts .GroupBy(v => v.Date.Year) .Select(v => new dynamic[] { v.Key.ToString(), v.Count(), }) .OrderByDescending(v => (string)v[0]) .Take((int)((CoEx.ForcedBufferWidth.Value - yearmaxlength - 4) / 2)) .OrderBy(v => (string)v[0]) .ToDictionary(key => (string)key[0], value => (double)value[1]); var yearrows = RowCollection.Create(yearstats.ToArray()); yearrows.Settings.Border.Enabled = true; yearrows.Settings.Align = (conf, colidx, s) => { switch (colidx) { case 3: case 4: case 6: return(RowCollectionSettings.ALIGN.RIGHT); default: return(RowCollectionSettings.ALIGN.LEFT); } }; CoEx.WriteTitle("Statistics by year"); var graph = new SimpleGraph() { Height = 15 }; graph.Draw(yeargraphstats); CoEx.WriteLine(); CoEx.WriteTable(yearrows); CoEx.WriteLine(); //--> Month statistics var monthstats = cleanposts .GroupBy(v => v.Date.GetMonth()) .Select(v => new string[] { v.Key.ToString("yyyy-MM"), v.Min(j => j.Date).ToString("dd HH:mm"), v.Max(j => j.Date).ToString("dd HH:mm"), v.GroupBy(j => j.User).Count().ToString("#,###"), v.Count().ToString("#,###"), string.Join(", ", v.GroupBy(j => j.User).OrderByDescending(j => j.Count()).Take(3).Select(j => $"{j.Key?.Username??"Guest"} ({j.Count()})")), v.Max(j => j.MessageHtml.RemoveHtml().Length).ToString("#,###") }) .Prepend(new string[] { "Month", "First Post", "Last Post", "Active", "Posts", "Top Users", "Largest Msg" }); var monthmaxlength = cleanposts .GroupBy(v => v.Date.GetMonth()) .Select(v => v.Count().ToString().Length) .Max(); var monthgraphstats = cleanposts .GroupBy(v => v.Date.GetMonth()) .Select(v => new dynamic[] { v.Key.ToString("yyMM"), v.Count(), }) .OrderByDescending(v => (string)v[0]) .Take((int)((CoEx.ForcedBufferWidth.Value - monthmaxlength - 4) / 2)) .OrderBy(v => (string)v[0]) .ToDictionary(key => (string)key[0], value => (double)value[1]); var monthrows = RowCollection.Create(monthstats.ToArray()); monthrows.Settings.Border.Enabled = true; monthrows.Settings.Align = (conf, colidx, s) => { switch (colidx) { case 3: case 4: case 6: return(RowCollectionSettings.ALIGN.RIGHT); default: return(RowCollectionSettings.ALIGN.LEFT); } }; CoEx.WriteTitle("Statistics by month"); graph.Draw(monthgraphstats); CoEx.WriteLine(); CoEx.WriteTable(monthrows); CoEx.WriteLine(); writer.SaveAs(htmloutfile); } }