예제 #1
0
        public ActionResult Index(bool?change)
        {
            if (change != true && SelectedBattle != null)
            {
                return(RedirectToAction("Index", "Teams"));
            }

            IntelReport  reportsAlias = null;
            BattleHeader dto          = null;

            var battles = Session.QueryOver <Battle>()
                          .Left.JoinAlias(x => x.Reports, () => reportsAlias)
                          .Where(() => reportsAlias.Id == null || reportsAlias.ReportStatsCount > 0) //ignore the chat and botmessages
                          .SelectList(list => list
                                      .SelectGroup(x => x.Id).WithAlias(() => dto.Id)
                                      .SelectGroup(x => x.Name).WithAlias(() => dto.Name)
                                      .SelectGroup(x => x.StartDateUTC).WithAlias(() => dto.StartDateUTC)
                                      .SelectGroup(x => x.EndDateUTC).WithAlias(() => dto.EndDateUTC)
                                      .SelectCountDistinct(() => reportsAlias.UserId).WithAlias(() => dto.NumUsersReporting)
                                      .SelectCountDistinct(() => reportsAlias.MessageId).WithAlias(() => dto.NumReports)
                                      .SelectCountDistinct(() => reportsAlias.Team.Id).WithAlias(() => dto.NumTeams)
                                      .SelectSum(() => reportsAlias.NewStatsCount).WithAlias(() => dto.NumStats))
                          .OrderBy(x => x.StartDateUTC).Desc
                          .TransformUsing(Transformers.AliasToBean <BattleHeader>())
                          .List <BattleHeader>();

            return(View(battles));
        }
예제 #2
0
 private IntelReport GetDuplicateBattleReport(IntelReport report)
 {
     return(Session.QueryOver <IntelReport>()
            .Where(x => x.Battle.Id == Battle.Id)
            .And(x => x.Id != report.Id)
            .And(x => x.TextHash == report.TextHash)
            .OrderBy(x => x.CreateDateUTC).Asc
            .Take(1)
            .SingleOrDefault());
 }
예제 #3
0
        private void ParseReportText(IntelReport report)
        {
            bool hadTruncatedLine;
            var  Text          = report.UpdatedText ?? report.Text;
            var  nonEmptyLines = Text.SplitToNonEmptyLines(255, out hadTruncatedLine);

            report.HadTruncatedLine  = hadTruncatedLine;
            report.NonEmptyLineCount = nonEmptyLines.Count();
            report.IsChat            = report.NonEmptyLineCount < 2; //assume chat if only 1 line

            if (report.IsChat || report.HadTruncatedLine)
            {
                return;
            }

            string teamName;

            nonEmptyLines = nonEmptyLines.RemoveTeamName(out teamName);
            if (string.IsNullOrEmpty(teamName)) //flag as unknown team and generate a name
            {
                report.IsUnknownTeamName = true;
                teamName = "Unknown Team " + report.Id;
            }
            ;
            var team = GetOrCreateTeam(teamName);

            report.Team = team;

            var reportStats = nonEmptyLines.Select(x => Stat.Parse(x)).Distinct();

            report.ReportStatsCount = reportStats.Count();

            //check for existing battle stats for this team
            var currentTeamStats = GetCurrentTeamStats(team);
            var newStats         = reportStats.Except(currentTeamStats);

            report.NewStatsCount = newStats.Count();

            this.NewStatsCount += report.NewStatsCount;

            foreach (var stat in newStats)
            {
                report.Stats.Add(new BattleStat
                {
                    Battle = Battle,
                    Team   = team,
                    Stat   = stat
                });
            }
        }
예제 #4
0
        private IntelReport SaveReport(GroupMessage message)
        {
            var report = new IntelReport
            {
                Battle        = Battle,
                MessageId     = message.id,
                GroupId       = message.group_id,
                UserId        = message.user_id,
                UserName      = message.name,
                CreateDateUTC = message.created_at.ToUniversalTime(),
                ReadDateUTC   = DateTime.UtcNow,
                Text          = message.text ?? string.Empty
            };

            report.TextHash = ComputeHash(report.Text);

            Session.Save(report);

            return(report);
        }
예제 #5
0
 public void ReParseReportText(IntelReport report)
 {
     report.ClearStats();
     Session.Flush(); //flush the stat deletes
     ParseReportText(report);
 }