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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public override void Generate(ReportContext context)
        {
            var result     = new Dictionary <string, int>(StringComparer.CurrentCultureIgnoreCase);
            var messages   = GetMessages();
            var smileRegex = new Regex("<[^>]*>", RegexOptions.Compiled | RegexOptions.CultureInvariant);

            foreach (var message in messages)
            {
                if (string.IsNullOrEmpty(message.Text))
                {
                    continue;
                }
                var text = message.Text;
                text = smileRegex.Replace(text, string.Empty);
                var words = text.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var word in words)
                {
                    if (word.Length <= 1)
                    {
                        continue;
                    }
                    if (result.ContainsKey(word))
                    {
                        result[word]++;
                    }
                    else
                    {
                        result.Add(word, 1);
                    }
                }
            }
            CommonWriter.WriteTitle(context, "Report by top words");
            TableWriter.WriteHeader(context, "Word", "Count");
            foreach (var item in result.OrderByDescending(i => i.Value).Take(40))
            {
                TableWriter.WriteBody(context, item.Key, item.Value.ToString());
            }
            TableWriter.WriteFooter(context);
        }
        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);
        }
Пример #5
0
        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.Day;
                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 days of month 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);
        }