Exemplo n.º 1
0
        public static string GamePage(League league, Game game, OutputFormat outputFormat = OutputFormat.Svg)
        {
            ZoomReports reports = new ZoomReports();

            reports.Colors.BackgroundColor = Color.Empty;
            reports.Colors.OddColor        = Color.Empty;
            reports.Add(Reports.OneGame(league, game));
            reports.Add(new ZoomHtmlInclusion("</div><br/><a href=\"index.html\">Index</a><div>"));
            return(reports.ToOutput(outputFormat));
        }
Exemplo n.º 2
0
        /// <summary>Display fixtures for a league, both as a list and as a grid.</summary>
        public static string FixturePage(Fixture fixture, League league, OutputFormat outputFormat = OutputFormat.Svg)
        {
            ZoomReports reports = new ZoomReports
            {
                Reports.FixtureList(fixture, league, GameHyper),
                Reports.FixtureGrid(fixture, league),
                new ZoomHtmlInclusion(@"
</div><br/><a href=""index.html"">Index</a> <a href=""fixture.html"">Fixture</a>

<script>
  var tables = document.querySelectorAll('.fixturelist');
    for (const table of tables)
      for (const tr of table.querySelectorAll('tr'))
        for (const td of tr.querySelectorAll('.time')) {
          var year = parseInt(td.innerHTML.substr(0, 4), 10);
          var month = parseInt(td.innerHTML.substr(5, 2), 10);
          var day = parseInt(td.innerHTML.substr(8, 2), 10);
          var hour = parseInt(td.innerHTML.substr(11, 2), 10);
          var minute = parseInt(td.innerHTML.substr(14, 2), 10);
          var gameTime = new Date(year, month - 1, day, hour, minute, 0);
          if (td.innerHTML.substr(0, 3) == '<a ' || gameTime < Date.now())
            td.style.backgroundColor = 'gainsboro';
        }

  var url = new URL(window.location.href);
  var team = url.searchParams.get('team');

  if (team) {
    var tables = document.querySelectorAll('.fixturelist');
      for (const table of tables)
        for (const tr of table.querySelectorAll('tr:not(.t' + team + ')'))
          tr.style = 'display:none';

    var tables = document.querySelectorAll('.fixturegrid');
      for (const table of tables)
        for (const tr of table.querySelectorAll('tr'))
          for (const td of tr.querySelectorAll('td.t' + team))
            if (td.innerHTML == '')
              td.style.backgroundColor = 'gainsboro';
  }
</script>
")
            };

            return(outputFormat == OutputFormat.Svg ? reports.ToHtml() : reports.ToOutput(outputFormat));
        }
Exemplo n.º 3
0
        string ScoreboardPage(League league, OutputFormat outputFormat = OutputFormat.Svg)
        {
            if (MostRecentGame == null)
            {
                Update();
            }

            if (MostRecentGame == null)
            {
                return(NowPage());
            }

            ZoomReports reports = new ZoomReports();

            reports.Colors.BackgroundColor = Color.Empty;
            reports.Colors.OddColor        = Color.Empty;
            reports.Add(Reports.OneGame(league, MostRecentGame));

            if (NextGame != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("</div><br/><a href=\"fixture.html\">Up Next</a>:");

                foreach (var ft in NextGame.Teams)
                {
                    sb.Append(ft.Key.LeagueTeam.Name + "; ");
                }
                sb.Length -= 2;
                sb.Append("<div>");
                reports.Add(new ZoomHtmlInclusion(sb.ToString()));
            }

            reports.Add(new ZoomHtmlInclusion("</div><br/><a href=\"index.html\">Index</a><div>"));

/*
 *                      reports.Add(new ZoomHtmlInclusion(@"
 * <script>
 * </script>
 * "));
 */
            return(reports.ToOutput(outputFormat));
        }
Exemplo n.º 4
0
        /// <summary>Generate a page with results for a team.</summary>
        public static string TeamPage(League league, bool includeSecret, LeagueTeam leagueTeam, OutputFormat outputFormat)
        {
            ZoomReports reports = new ZoomReports(leagueTeam.Name)
            {
                Reports.OneTeam(league, includeSecret, leagueTeam, DateTime.MinValue, DateTime.MaxValue, true)
            };

            foreach (var player in leagueTeam.Players)
            {
                reports.Add(new ZoomHtmlInclusion("<a name=\"player" + player.Id + "\">"));
                reports.Add(Reports.OnePlayer(league, player, new List <LeagueTeam>()
                {
                    leagueTeam
                }));
            }

            reports.Add(new ZoomHtmlInclusion("</div><br/><a href=\"fixture.html?team=" + leagueTeam.TeamId.ToString(CultureInfo.InvariantCulture) + "\">Fixture</a><br/><a href=\"index.html\">Index</a><div>"));

            return(reports.ToOutput(outputFormat));
        }
Exemplo n.º 5
0
        static void ExportPlayers(Holder holder, string path)
        {
            League league = holder.League;

            var         playerTeams   = league.BuildPlayerTeamList();
            ZoomReports playerReports = new ZoomReports("Players in " + league.Title);

            playerReports.Colors.BackgroundColor = Color.Empty;
            playerReports.Colors.OddColor        = Color.Empty;

            foreach (var pt in playerTeams)
            {
                playerReports.Add(new ZoomHtmlInclusion("<a name=\"player" + pt.Key.Id + "\">"));
                playerReports.Add(Reports.OnePlayer(league, pt.Key, pt.Value, ReportPages.GameHyper));
            }

            playerReports.Add(new ZoomHtmlInclusion("<br/><a href=\"index.html\">Index</a>"));

            if (playerReports.Count > 1)
            {
                using (StreamWriter sw = File.CreateText(Path.Combine(path, holder.Key, "players." + holder.ReportTemplates.OutputFormat.ToExtension())))
                    sw.Write(playerReports.ToOutput(holder.ReportTemplates.OutputFormat));
            }
        }
Exemplo n.º 6
0
        private void ButtonSaveClick(object sender, EventArgs e)
        {
            var outputFormat = radioSvg.Checked ? OutputFormat.Svg :
                               radioTables.Checked ? OutputFormat.HtmlTable :
                               radioTsv.Checked ? OutputFormat.Tsv :
                               OutputFormat.Csv;

            string file = report.Title.Replace('/', '-').Replace(' ', '_') + "." + outputFormat.ToExtension();                 // Replace / with - so dates still look OK, and  space with _ to make URLs easier if this file is uploaded to the web.

            saveFileDialog.FileName = Path.GetInvalidFileNameChars().Aggregate(file, (current, c) => current.Replace(c, '_')); // Replace all other invalid chars with _.

            var reports = new ZoomReports()
            {
                report
            };

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                using (StreamWriter sw = File.CreateText(saveFileDialog.FileName))
                    sw.Write(reports.ToOutput(outputFormat));
                fileName           = saveFileDialog.FileName;
                buttonShow.Enabled = true;
            }
        }
Exemplo n.º 7
0
        static void ExportGames(Holder holder, string path)
        {
            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 heatMap = false;

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

                    foreach (Game game in dayGames)
                    {
                        reports.Add(new ZoomHtmlInclusion("<a name=\"game" + game.Time.ToString("HHmm", CultureInfo.InvariantCulture) + "\">"));
                        reports.Add(Reports.OneGame(league, game));
                        if (game.ServerGame != null && game.ServerGame.Events.Any() && !game.ServerGame.InProgress)
                        {
                            reports.Add(Reports.GameHeatMap(league, game));
                            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("<img src=\"" + imageName + "\">"));
                            game.Reported = true;
                            heatMap       = true;
                        }
                    }
                    if (heatMap)
                    {
                        reports.Add(new ZoomHtmlInclusion("</div><p>\u25cb and \u2b24 are hit and destroyed bases.<br/>\u2300 and &olcross; are one- and two-shot denies;<br/>\U0001f61e and \U0001f620 are one- and two-shot denied.<br/>\u25af and \u25ae are warning and termination.<br/>Tags+ includes shots on bases and teammates.</p><div>"));
                    }

                    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));
                    }
                }
            }
        }
Exemplo n.º 8
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());
                }
            }
        }