Example #1
0
        static void ExportGames(Holder holder, string path, Progress progress)
        {
            League league = holder.League;

            var dates = league.AllGames.Select(g => g.Time.Date).Distinct().ToList();

            foreach (var date in dates)
            {
                string fileName = Path.Combine(path, holder.Key, "games" + date.ToString("yyyyMMdd", CultureInfo.InvariantCulture) +
                                               "." + holder.ReportTemplates.OutputFormat.ToExtension());

                var dayGames = league.AllGames.Where(g => g.Time.Date == date);
                if (dayGames.Any(g => !g.Reported) || !File.Exists(fileName))                  // Some of the games for this day are not marked as reported. Report on them.
                {
                    ZoomReports reports = new ZoomReports(league.Title + " games on " + date.ToShortDateString());
                    reports.Colors.BackgroundColor = Color.Empty;
                    reports.Colors.OddColor        = Color.Empty;
                    league.AllGames.Sort();
                    bool detailed = false;

                    var rt = new ReportTemplate()
                    {
                        From = date, To = date.AddSeconds(86399)
                    };
                    reports.Add(Reports.GamesToc(league, false, rt));
                    string gameTitle = "";

                    foreach (Game game in dayGames)
                    {
                        if (gameTitle != game.Title)
                        {
                            reports.Add(new ZoomSeparator());
                            gameTitle = game.Title;
                        }

                        reports.Add(new ZoomHtmlInclusion("<a name=\"game" + game.Time.ToString("HHmm", CultureInfo.InvariantCulture) + "\"><div style=\"display: flex; flex-flow: row wrap; justify-content: space-around; \">\n"));
                        reports.Add(Reports.OneGame(league, game));
                        if (game.ServerGame != null && game.ServerGame.Events.Any() && !game.ServerGame.InProgress)
                        {
                            string imageName = "score" + game.Time.ToString("yyyyMMdd_HHmm", CultureInfo.InvariantCulture) + ".png";
                            string imagePath = Path.Combine(path, holder.Key, imageName);
                            if (!game.Reported || !File.Exists(imagePath))
                            {
                                var bitmap = Reports.GameWorm(league, game, true);
                                if (bitmap != null && (bitmap.Height > 1 || !File.Exists(imagePath)))
                                {
                                    bitmap.Save(imagePath, System.Drawing.Imaging.ImageFormat.Png);
                                }
                            }
                            reports.Add(new ZoomHtmlInclusion("\n<div><p> </p></div><div><p> </p></div>\n<div><img src=\"" + imageName + "\"></div></div>\n"));
                            game.Reported = true;
                            detailed      = true;
                        }
                    }
                    if (detailed)
                    {
                        var eventsUsed = dayGames.Where(g => g.ServerGame != null).SelectMany(g => g.ServerGame.Events.Select(e => e.Event_Type)).Distinct();
                        var sb         = new StringBuilder("</div>\n<p>");
                        if (eventsUsed.Contains(30) || eventsUsed.Contains(31))
                        {
                            sb.Append("\u25cb and \u2b24 are hit and destroyed bases.<br/>");
                        }
                        if (eventsUsed.Contains(1403) || eventsUsed.Contains(1404))
                        {
                            sb.Append("\U0001f61e and \U0001f620 are one- and two-shot denied.<br/>");
                        }
                        if (eventsUsed.Contains(1401) || eventsUsed.Contains(1402))
                        {
                            sb.Append("\u2300 and \u29bb are denied another player.<br/>");
                        }
                        if (eventsUsed.Contains(28))
                        {
                            sb.Append("\U0001f7e8 is warning (yellow card). ");
                        }
                        if (eventsUsed.Contains(28) && !eventsUsed.Contains(29))
                        {
                            sb.Append("<br/>");
                        }
                        if (eventsUsed.Contains(29))
                        {
                            sb.Append("\U0001f7e5 is termination (red card).<br/>");
                        }
                        if (eventsUsed.Contains(32))
                        {
                            sb.Append("\U0001f480 is player eliminated.<br/>");
                        }
                        if (eventsUsed.Contains(33) && !eventsUsed.Contains(34) && !eventsUsed.Any(t => t >= 37 && t <= 46))
                        {
                            sb.Append("! is hit by base, or player self-denied.<br/>");
                        }
                        if (eventsUsed.Contains(34) || eventsUsed.Any(t => t >= 37 && t <= 46))
                        {
                            sb.Append("! is hit by base or mine, or player self-denied, or player tagged target.<br/>");
                        }
                        sb.Append("\u00B7 shows each minute elapsed.<br/>Tags+ includes shots on bases and teammates.</p>\n");
                        sb.Append(@"<p>""Worm"" charts show coloured lines for each team. Vertical dashed lines show time in minutes. <br/>
Sloped dashed lines show lines of constant score: 0 points, 10K points, etc. The slope of these lines shows the average rate of scoring of ""field points"" 
during the game. Field points are points not derived from shooting bases, getting penalised by a referee, etc. A team whose score line is horizontal is 
scoring points  at the average field pointing rate for the game. <br/>
Base hits and destroys are shown with a mark in the colour of the base hit. Base destroys have the alias of the player destroying the base next to them.</p>
<div>");
                        reports.Add(new ZoomHtmlInclusion(sb.ToString()));
                    }

                    reports.Add(new ZoomHtmlInclusion("</div><a href=\"index.html\">Index</a><div>"));
                    if (reports.Count > 1)                      // There were games this day.
                    {
                        using (StreamWriter sw = File.CreateText(fileName))
                            sw.Write(reports.ToOutput(holder.ReportTemplates.OutputFormat));
                    }

                    progress.Advance(1.0 / dates.Count, "Exported games for " + date.ToShortDateString());
                }
            }
        }
Example #2
0
        /// <summary>Generate one report. The type of report generated is specified in the ReportTemplate.</summary>
        public static ZoomReportBase Report(List <League> leagues, bool includeSecret, ReportTemplate rt)
        {
            bool description = rt.Settings.Contains("Description");

            switch (rt.ReportType)
            {
            case ReportType.ColourPerformance:
                return(Reports.ColourReport(leagues, includeSecret, rt));

            case ReportType.Packs:
                return(Reports.PackReport(leagues, null, rt.Title, rt.From, rt.To,
                                          ChartTypeExtensions.ToChartType(rt.Setting("ChartType")), description, rt.Settings.Contains("Longitudinal")));

            case ReportType.Tech:
                return(Reports.TechReport(leagues, rt.Title, rt.From, rt.To,
                                          ChartTypeExtensions.ToChartType(rt.Setting("ChartType")), description));

            case ReportType.SanityCheck:
                return(Reports.SanityReport(leagues, rt.Title, rt.From, rt.To, description));

            default: return(Report(leagues.FirstOrDefault(), includeSecret, rt));
            }
        }