public override void Generate(ReportContext context) { Dictionary<string, Dictionary<DateTime, int>> result = new Dictionary<string, Dictionary<DateTime, int>>(); var messages = GetMessages(); var minDate = DateTime.MaxValue; var maxDate = DateTime.MinValue; foreach (var message in messages) { var monthPart = DateUtils.GetMonth(message.Timestamp); Dictionary<DateTime, int> childDict; if (!result.ContainsKey(message.Author)) { childDict = new Dictionary<DateTime, int>(); result.Add(message.Author, childDict); } else { childDict = result[message.Author]; } if (childDict.ContainsKey(monthPart)) { childDict[monthPart]++; } else { childDict.Add(monthPart, 1); } // for sorting purpose if (monthPart > maxDate) maxDate = monthPart; if (monthPart < minDate) minDate = monthPart; } CommonWriter.WriteTitle(context, "Report by month message count"); GenerateHeader(context, minDate, maxDate); Dictionary<string, string> normalNames = result.Select(pair => new Tuple<string, string>(GetMember(pair.Key).DisplayName, pair.Key)).OrderBy( i => i.Item1).ToDictionary(i => i.Item1, i => i.Item2); foreach (var key in normalNames) { var value = result[key.Value]; List<string> data = new List<string>(); data.Add(key.Key); for (DateTime item = minDate; item <= maxDate; item = item.AddMonths(1)) { if (value.ContainsKey(item)) data.Add(value[item].ToString()); else { data.Add("0"); } } TableWriter.WriteBody(context, data.ToArray()); } TableWriter.WriteFooter(context); }
public void WriteHeader(ReportContext context, params string[] data) { context.Writer.WriteLine("<table>"); context.Writer.Write("<tr>"); foreach (var item in data) { context.Writer.Write("<th>{0}</th>", item); } context.Writer.WriteLine("</tr>"); }
public override void Generate(ReportContext context) { var result = new Dictionary<string, Dictionary<DayOfWeek, int>>(); var messages = GetMessages(); foreach (var message in messages) { var day = message.Timestamp.DayOfWeek; Dictionary<DayOfWeek, int> childDict; if (!result.ContainsKey(message.Author)) { childDict = new Dictionary<DayOfWeek, int>(); result.Add(message.Author, childDict); } else { childDict = result[message.Author]; } if (childDict.ContainsKey(day)) { childDict[day]++; } else { childDict.Add(day, 1); } } CommonWriter.WriteTitle(context, "Report by day of week message count"); GenerateHeader(context); Dictionary<string, string> normalNames = result.Select(pair => new Tuple<string, string>(GetMember(pair.Key).DisplayName, pair.Key)).OrderBy( i => i.Item1).ToDictionary(i => i.Item1, i => i.Item2); foreach (var key in normalNames) { var value = result[key.Value]; List<string> data = new List<string>(); data.Add(key.Key); foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek))) { if (value.ContainsKey(day)) { data.Add(value[day].ToString()); } else { data.Add("0"); } } TableWriter.WriteBody(context, data.ToArray()); } TableWriter.WriteFooter(context); }
public override void Generate(ReportContext context) { var groups = GetMessages().GroupBy(i => i.Author).Select(group => new Tuple<string, int>(group.Key, group.Count())). OrderByDescending(i => i.Item2); CommonWriter.WriteTitle(context, "Report by total message count"); TableWriter.WriteHeader(context, "Author","Message count"); foreach (var item in groups) { var member = GetMember(item.Item1); if (member == null) continue; TableWriter.WriteBody(context, member.DisplayName, item.Item2.ToString()); } TableWriter.WriteFooter(context); }
public void WriteBody(ReportContext context, params string[] data) { if (data.Length == 0) return; context.Writer.Write("<tr>"); foreach (var item in data) { if (item == "0") { context.Writer.Write("<td class='inactive'>{0}</td>", item); } else { context.Writer.Write("<td>{0}</td>", item); } } context.Writer.WriteLine("</tr>"); }
private string GenerateReportBody(IEnumerable<IReportGenerator> reports) { var stream = new MemoryStream(); using (var writer = new StreamWriter(stream)) { writer.AutoFlush = true; var context = new ReportContext(); context.Writer = writer; foreach (IReportGenerator reportGenerator in reports) { this.reportManager.NextStep(reportGenerator.Name); reportGenerator.Generate(context); } writer.Flush(); } return Encoding.UTF8.GetString(stream.GetBuffer()); }
private void GenerateHeader(ReportContext context) { List<string> header = new List<string>(); header.Add("Author"); foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek))) { header.Add(day.ToString()); } TableWriter.WriteHeader(context, header.ToArray()); }
private string GenerateReportBody(IEnumerable<IReportGenerator> reports) { var stream = new MemoryStream(); using (var writer = new StreamWriter(stream)) { writer.AutoFlush = true; var context = new ReportContext(); context.Parameters.Add( TimerangeReport.TimeRangeParametersKey, new TimerangeParameters() { From = this.dtpTimeRangeFrom.Value, To = this.dtpTimeRangeTo.Value, SplitTime = cbSplitTimeEnabled.Checked ? (int)nudIntervalNewChat.Value : int.MaxValue }); context.Writer = writer; foreach (IReportGenerator reportGenerator in reports) { this.reportManager.NextStep(reportGenerator.Name); reportGenerator.Generate(context); } writer.Flush(); } return Encoding.UTF8.GetString(stream.GetBuffer()); }
private void GenerateHeader(ReportContext context, DateTime minDate, DateTime maxDate) { List<string> header = new List<string>(); header.Add("Author"); for (DateTime item = minDate; item <= maxDate; item = item.AddMonths(1)) { header.Add(item.ToString("MMMM yyyy")); } TableWriter.WriteHeader(context, header.ToArray()); }
public override void Generate(ReportContext context) { var result = new Dictionary<string, Dictionary<short, int>>(); var messages = GetMessages(); var min = short.MaxValue; var max = short.MinValue; foreach (var message in messages) { short day = (short)message.Timestamp.Hour; Dictionary<short, int> childDict; if (!result.ContainsKey(message.Author)) { childDict = new Dictionary<short, int>(); result.Add(message.Author, childDict); } else { childDict = result[message.Author]; } if (childDict.ContainsKey(day)) { childDict[day]++; } else { childDict.Add(day, 1); } // for sorting purpose if (day > max) max = day; if (day < min) min = day; } CommonWriter.WriteTitle(context, "Report by hourly message count"); GenerateHeader(context, min, max); Dictionary<string, string> normalNames = result.Select(pair => new Tuple<string, string>(GetMember(pair.Key).DisplayName, pair.Key)).OrderBy( i => i.Item1).ToDictionary(i => i.Item1, i => i.Item2); foreach (var key in normalNames) { var value = result[key.Value]; List<string> data = new List<string>(); data.Add(key.Key); for (var i = min; i <= max; i++) { if (value.ContainsKey(i)) { data.Add(value[i].ToString()); } else { data.Add("0"); } } TableWriter.WriteBody(context, data.ToArray()); } TableWriter.WriteFooter(context); }
private void GenerateHeader(ReportContext context, short min, short max) { List<string> header = new List<string>(); header.Add("Author"); for (short i = min; i <= max; i++) { header.Add(string.Format("{0}:00", i)); } TableWriter.WriteHeader(context, header.ToArray()); }
public void WriteFooter(ReportContext context, params string[] data) { context.Writer.Write("</table>"); }
public abstract void Generate(ReportContext context);
public void WriteTitle(ReportContext context, string header) { context.Writer.WriteLine("<h2>{0}</h2>", header); }
public void WriteDelimiter(ReportContext context) { context.Writer.WriteLine("<hr align='left' width='100%'/>"); }