private static List <StatsPerDay> GenerateStatsPerDay(ChannelReport channelReport)
        {
            var result = new List <StatsPerDay>();

            var suspensionCount = channelReport.SuspensionsPerDay.OrderBy(x => x.Key).ToList();
            var banCount        = channelReport.BansPerDay.OrderBy(x => x.Key).ToList();
            var timeoutCount    = channelReport.TimeoutsPerDay.OrderBy(x => x.Key).ToList();

            for (int i = 0; i < suspensionCount.Count; i++)
            {
                var suspensionForDate = suspensionCount[i];
                var banForDate        = banCount[i];
                var timeoutForDate    = timeoutCount[i];

                result.Add(new StatsPerDay
                {
                    Date             = suspensionForDate.Key,
                    SuspensionsCount = suspensionForDate.Value,
                    BansCount        = banForDate.Value,
                    TimeoutCount     = timeoutForDate.Value
                });
            }

            return(result);
        }
 public static ChannelReportModel Map(this ChannelReport channelReport)
 {
     return(new ChannelReportModel
     {
         ChannelName = channelReport.ChannelName,
         SuspendedUsers = channelReport.SuspendedUsers,
         BannedUsers = channelReport.BannedUsers,
         TimedoutUsers = channelReport.TimedoutUsers,
         SuspensionsPerDay = GenerateStatsPerDay(channelReport),
         TagAppearances = channelReport.TagAppearances.Select(x => new TagCountModel {
             Tag = x.Key.Map(), Count = x.Value
         }).ToList(),
         TotalBans = channelReport.TotalBans,
         TotalSuspensions = channelReport.TotalSuspensions,
         TotalTimeouts = channelReport.TotalTimeouts,
         UniqueUsers = channelReport.UniqueUsers,
         UniqueUsersBan = channelReport.UniqueUsersBan,
         UniqueUsersSuspensions = channelReport.UniqueUsersSuspensions,
         UniqueUsersTimeout = channelReport.UniqueUsersTimeout,
         RuleCounts = channelReport.RulesTriggered.Select(x => new RuleCountModel {
             ChannelRuleName = x.Key, Count = x.Value
         }).ToList(),
         TotalSystemBanCount = channelReport.TotalSystemBans,
         SystemBansPerDay = GetSystemBanPerDays(channelReport)
     });
 }
        public async Task <IResult <ChannelReport> > GenerateReportForChannel(string channelName, IApplicationContext context)
        {
            var channel = await channelRepository.GetChannel(channelName).ConfigureAwait(false);

            if (!context.HaveAccessTo(channel))
            {
                return(Result <ChannelReport> .Unauthorized());
            }

            var suspensionsForChannel = await suspensionRepository.GetAuditedSuspensionsForChannel(channelName, datetimeProvider.UtcNow.AddYears(-1)).ConfigureAwait(false);

            if (suspensionsForChannel.Count == 0)
            {
                return(Result <ChannelReport> .NoContentFound());
            }

            var usersForChannel = await chatRepository.GetUniqueChattersForChannel(channelName).ConfigureAwait(false);

            var suspensionsForChannelWithoutSystem = suspensionsForChannel.Where(x => x.SuspensionSource != SuspensionSource.System).ToList();
            var systemSuspensionsForChannel        = suspensionsForChannel.Where(x => x.SuspensionSource == SuspensionSource.System).ToList();

            var channelReport = new ChannelReport(channelName, suspensionsForChannelWithoutSystem, systemSuspensionsForChannel, usersForChannel.Count);

            return(Result <ChannelReport> .Succeeded(channelReport));
        }
        private static List <SystemBanPerDay> GetSystemBanPerDays(ChannelReport channelReport)
        {
            var result = new List <SystemBanPerDay>();

            foreach (var item in channelReport.SystemBanPerDay)
            {
                result.Add(new SystemBanPerDay {
                    Date = item.Key, Count = item.Value
                });
            }

            return(result);
        }
            public override string ToString()
            {
                StringBuilder sb = new StringBuilder();

                foreach (var property in this.GetType().GetProperties())
                {
                    sb.Append(property + "=" + property.GetValue(this, null) + "\r\n");
                }

                if (ChannelReport != null)
                {
                    sb.Append(ChannelReport.ToString());
                }
                if (ResponseData != null)
                {
                    sb.Append(ResponseData.ToString());
                }

                return(sb.ToString());
            }