示例#1
0
        public static string Wednesday()
        {
            var topLine = new StringBuilder();

            using (var db = new LBClubsEntities())
            {
                var teams = db.WednesdayTeams.Count();

                var rinks = teams / 2;

                var tline = new StringBuilder();
                tline.Append("WK,Date,GRN,DIR,Bound,");
                for (var rink = 0; rink < rinks; rink++)
                {
                    tline.Append($"{rink},");
                }

                var tline1 = tline.ToString();
                topLine.Append(tline1.Substring(0, tline1.Length - 1) + "\n");


                var weeks = db.WednesdaySchedules.SortBy("Id");
                foreach (var week in weeks)
                {
                    var    matches  = db.WednesdayMatches.Where(x => x.GameDate == week.id).OrderBy(x => x.Rink);
                    var    weekLine = new StringBuilder();
                    string grn      = string.Empty;
                    string dir      = string.Empty;
                    string bound    = string.Empty;
                    switch ((week.id - 1) % 9)
                    {
                    case 1:
                        grn   = "Luba";
                        dir   = "N-S";
                        bound = "Red";
                        break;

                    case 2:
                        grn   = "Phillips";
                        dir   = "E-W";
                        bound = "White";
                        break;

                    case 3:
                        grn   = "Luba";
                        dir   = "E-W";
                        bound = "Yellow";
                        break;

                    case 4:
                        grn   = "Phillips";
                        dir   = "N-S";
                        bound = "Red";
                        break;

                    case 5:
                        grn   = "Luba";
                        dir   = "N-S";
                        bound = "White";
                        break;

                    case 6:
                        grn   = "Phillips";
                        dir   = "E-W";
                        bound = "Yellow";
                        break;

                    case 7:
                        grn   = "Luba";
                        dir   = "E-W";
                        bound = "Red";
                        break;

                    case 8:
                        grn   = "Phillips";
                        dir   = "N-S";
                        bound = "White";
                        break;

                    case 0:
                        grn   = "Luba";
                        dir   = "N-S";
                        bound = "Yellow";
                        break;
                    }
                    var date = $"{week.GameDate.Month}/{week.GameDate.Day}";
                    weekLine.Append($"{week.id},{date},{grn},{dir},{bound},");
                    foreach (var match in matches)
                    {
                        if (match.Rink != -1)
                        {
                            weekLine.Append($"{match.Team1}-{match.Team2},");
                        }
                    }
                    var wline = weekLine.ToString();

                    topLine.Append(wline.Substring(0, wline.Length - 1) + "\n");
                }
            }
            return(topLine.ToString());
        }
示例#2
0
        /// <summary>
        /// Gets the object to be serialized to XML.
        /// </summary>
        public ActionResult GenerateReport(int id)
        {
            var topLine = new StringBuilder();



            var league = _db.Leagues.Find(id);

            if (league == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }
            var startWeek = league.StartWeek;

            using (var db = new  LBClubsEntities())
            {
                topLine.AppendLine("<table class='table table-striped table-sm'>");

                var teams = db.Teams.Where(x => x.Leagueid == id).OrderBy(x => x.TeamNo).ToList();


                var rinks = teams.Count / 2;
                topLine.AppendLine("<thead class='thead dark'>");
                topLine.AppendLine("<th>WK</th>");
                topLine.AppendLine("<th>Date</th>");
                topLine.AppendLine("<th>GRN</th>");
                topLine.AppendLine("<th>DIR</th>");
                topLine.AppendLine("<th>Bound</th>");
                if (rinks * 2 < teams.Count)
                {
                    topLine.AppendLine("<th>Bye</th>");
                }

                for (var rink = 0; rink < rinks; rink++)
                {
                    topLine.AppendLine($"<th align='center'>{rink + 1}</th>");
                }
                topLine.AppendLine("</thead>");

                var rinkList = db.RinkOrders.OrderBy(x => x.id).ToList();



                var weeks = db.Schedules.Where(x => x.Leagueid == id).OrderBy(x => x.GameDate);

                int i          = startWeek;
                int weekNumber = 1;
                foreach (Schedule week in weeks)
                {
                    topLine.AppendLine("<tr>");
                    var matches     = db.Matches.Where(x => x.WeekId == week.id).OrderBy(x => x.Rink).ToList();
                    var matchesByes = db.Matches.Where(x => x.Rink == -1 && x.WeekId == week.id).ToList();


                    int index    = ((i - 1) % rinkList.Count) + 1;
                    var rinklist = rinkList.Find(x => x.id == index);
                    i++;
                    topLine.AppendLine($"<td>{weekNumber++}</td>");
                    topLine.AppendLine($"<td>{week.GameDate.Month}/{week.GameDate.Day}</td>");
                    topLine.AppendLine($"<td>{rinklist.Green}</td>");
                    topLine.AppendLine($"<td>{rinklist.Direction}</td>");
                    topLine.AppendLine($"<td>{rinklist.Boundary}</td>");
                    if (matchesByes.Any())
                    {
                        topLine.AppendLine($"<td>{matchesByes.First().Team.TeamNo}</td>");
                    }
                    foreach (var match in matches)
                    {
                        if (match.Rink != -1)
                        {
                            topLine.AppendLine($"<td>{match.Team.TeamNo}-{match.Team1.TeamNo}</td>");
                        }
                    }
                    topLine.AppendLine("</tr>");
                }
                topLine.AppendLine("</table>");
                ViewBag.Report = topLine.ToString();
            }
            return(View());
        }
        /// <summary>
        /// Determine the standings based on all the games played so far
        /// </summary>
        /// <param name="weekid">the record id of the week in the schedule table</param>
        /// <param name="teamsize">number of players per team</param>
        /// <param name="leagueid">the record id of the league table</param>
        /// <returns></returns>
        public static TournamentDS.StandDataTable Doit(int weekid, League league)
        {
            int teamsize = league.TeamSize;
            var ds       = new TournamentDS();
            var list     = new List <Standing>();

            using (var db = new  LBClubsEntities())
            {
                // get the names of the player for each team
                foreach (var team in db.Teams.Where(x => x.Leagueid == league.id))
                {
                    string players = "";
                    switch (teamsize)
                    {
                    case 1:
                        players = team.Player.Membership.NickName;
                        break;

                    case 2:
                        players = $"{team.Player.Membership.NickName}, {team.Player2.Membership.NickName}";
                        break;

                    case 3:
                        players = $"{team.Player.Membership.NickName}, {team.Player1.Membership.NickName}, {team.Player2.Membership.NickName}";
                        break;
                    }
                    list.Add(new Standing()
                    {
                        TeamNumber = team.TeamNo,
                        Wins       = 0,
                        Loses      = 0,
                        TotalScore = 0,
                        Ties       = 0,
                        Byes       = 0,
                        Players    = players
                    });
                }

                // determine the total score and wins and loses for each team for each week
                foreach (var week in db.Schedules.Where(x => x.id <= weekid && x.Leagueid == league.id))
                {
                    //cancelled weeks do not count
                    if (week.Cancelled)
                    {
                        continue;
                    }
                    var  total      = 0;
                    var  numMatches = 0;
                    var  bye        = false;
                    bool forfeit    = false;
                    foreach (var match in db.Matches.Where(x => x.WeekId == week.id))
                    {
                        // tie game
                        if (match.Team1Score == match.Team2Score && match.Rink != -1 && match.ForFeitId == 0)
                        {
                            var winner = list.Find(x => x.TeamNumber == match.Team.TeamNo);
                            var loser  = list.Find(x => x.TeamNumber == match.Team1.TeamNo);
                            winner.Ties++;
                            loser.Ties++;
                            winner.TotalScore += Math.Min(20, match.Team1Score);
                            loser.TotalScore  += Math.Min(20, match.Team2Score);
                            total             += Math.Min(20, match.Team1Score);
                            numMatches++;
                        }
                        //team 1 wins
                        else if (match.Team1Score > match.Team2Score && match.Rink != -1 && match.ForFeitId == 0)
                        {
                            var winner = list.Find(x => x.TeamNumber == match.Team.TeamNo);
                            var loser  = list.Find(x => x.TeamNumber == match.Team1.TeamNo);
                            winner.Wins++;
                            loser.Loses++;
                            winner.TotalScore += Math.Min(20, match.Team1Score);
                            loser.TotalScore  += Math.Min(20, match.Team2Score);
                            total             += Math.Min(20, match.Team1Score);
                            numMatches++;
                        }
                        //team 2 wins
                        else if (match.Rink != -1 && match.ForFeitId == 0)
                        {
                            var winner = list.Find(x => x.TeamNumber == match.Team1.TeamNo);
                            var loser  = list.Find(x => x.TeamNumber == match.Team.TeamNo);
                            winner.Wins++;
                            loser.Loses++;
                            winner.TotalScore += Math.Min(20, match.Team2Score);
                            loser.TotalScore  += Math.Min(20, match.Team1Score);
                            total             += Math.Min(20, match.Team2Score);
                            numMatches++;
                        }
                        // forfeit
                        else if (match.Rink != -1 && match.ForFeitId != 0)
                        {
                            var winner = list.Find(x => x.TeamNumber == (match.Team.TeamNo == match.ForFeitId? match.Team1.TeamNo: match.Team.TeamNo));
                            var loser  = list.Find(x => x.TeamNumber == match.ForFeitId);
                            forfeit = true;
                            winner.Wins++;
                            loser.Loses++;
                        }
                        //bye
                        else
                        {
                            var winner = list.Find(x => x.TeamNumber == match.Team.TeamNo);
                            winner.Byes++;
                            bye = true;
                        }
                    }

                    // for byes or forfeit (the team that did not forfeit), the team gets the average score of all winning games that week and a win
                    if (bye || forfeit)
                    {
                        foreach (var match in db.Matches.Where(x => x.WeekId == week.id))
                        {
                            if (match.Rink != -1 && match.ForFeitId != 0)
                            {
                                var winner = list.Find(x => x.TeamNumber == (match.Team.TeamNo == match.ForFeitId ? match.Team1.TeamNo : match.Team.TeamNo));
                                winner.TotalScore += total / numMatches;
                            }
                            else if (match.Rink == -1)
                            {
                                var winner = list.Find(x => x.TeamNumber == match.Team.TeamNo);
                                winner.TotalScore += total / numMatches;
                            }
                        }
                    }
                }
            }
            int      place     = 1;
            int      nextplace = 1;
            Standing previous  = new Standing()
            {
                Loses      = 0,
                TotalScore = 0,
                Wins       = 0,
                Ties       = 0,
                Byes       = 0
            };

            foreach (var item in list)
            {
                var points = item.Wins * league.WinPoints +
                             item.Ties * league.TiePoints + item.Byes * league.ByePoints;
                if (league.PointsCount)
                {
                    item.TotalPoints = points * 1000 + item.TotalScore;
                }
                else
                {
                    item.TotalPoints = points;
                    item.TotalScore  = points;
                }
            }
            ds.Stand.Clear();
            list.Sort((a, b) => (b.TotalPoints).CompareTo(a.TotalPoints));
            foreach (var item in list)
            {
                if (item.TotalPoints != previous.TotalPoints)
                {
                    place = nextplace;
                }
                ds.Stand.AddStandRow(item.TeamNumber, item.Players, item.TotalScore, place, item.Wins, item.Loses, item.Ties, item.Byes);
                previous = item;
                nextplace++;
            }
            return(ds.Stand);
        }