Example #1
0
        private int GetNumberOfGames(int tournamentId)
        {
            Tournament tournament = context
                                    .Tournaments
                                    .Include(t => t.EventFormat)
                                    .Where(t => t.Id == tournamentId)
                                    .FirstOrDefault();

            EventFormat eventFormat          = tournament.EventFormat;
            int         numberOfParticipants = tournament.NumberOfParticipants;

            switch (eventFormat.Name)
            {
            case "Round-robin":
                return(numberOfParticipants * (numberOfParticipants - 1) / 2);

            case "Single elimination":
                return(numberOfParticipants - 1);

            case "Group stage":
                int groupSize = numberOfParticipants / 4;
                return((groupSize * (groupSize - 1) / 2) * 4);

            default:
                return(0);
            }
        }
Example #2
0
        public void GetEventFormat(string czEventId, EventFormat eventFormat)
        {
            Console.WriteLine("GetEventFormatTest\nCZ Event ID: " + czEventId);
            EventFormat ef = Parser.GetEventFormat(czEventId);

            Xunit.Assert.Equal(eventFormat, ef);
        }
Example #3
0
 public EventType(TeamType teamType, int numberOfEnds, Guid eventId, EventFormat eventFormat)
 {
     this.teamType        = teamType;
     this.NumberOfPlayers = GetNumberOfPlayersFromTeamType(teamType);
     this.Gender          = GetGenderFromTeamType(this.teamType);
     this.NumberOfEnds    = numberOfEnds;
     this.EventTypeId     = Guid.NewGuid();
     this.EventId         = eventId;
     this.EventFormat     = eventFormat;
 }
Example #4
0
        public bool DeleteEventFormat(int eventFormatId)
        {
            if (!context.EventFormats.Where(ef => ef.Id == eventFormatId).Any())
            {
                return(false);
            }
            EventFormat eventFormat = context.EventFormats.Where(ef => ef.Id == eventFormatId).First();

            context.Remove(eventFormat);
            context.SaveChanges();
            return(true);
        }
Example #5
0
        public static Event GetEventInfoFromJson(string json, Event e = null)
        {
            var game         = Api.GetGameObject(json);
            int numberOfEnds = 8;

            int.TryParse(game.numberOfEnds, out numberOfEnds);
            Guid           eventId     = Guid.NewGuid();
            EventFormat    eventFormat = GetEventFormat([email protected]);
            Standings      standings   = null;
            List <Bracket> brackets    = null;

            if (eventFormat == EventFormat.ROUND_ROBIN)
            {
                standings = GetEventStandings([email protected]);
            }
            else if (eventFormat == EventFormat.KNOCKOUT)
            {
                brackets = GetBrackets([email protected]);
            }
            Playoff playoff = GetPlayoff([email protected]);

            //TODO More robust parsing for dates in case of error.
            if (e == null)
            {
                e = new Event(
                    [email protected],
                    DateTime.Parse([email protected]),
                    DateTime.Parse([email protected]),
                    [email protected],
                    new EventType(GetTeamTypeFromDivision([email protected]), numberOfEnds, eventId, eventFormat),
                    czId: [email protected],
                    eventId: eventId,
                    standings: standings,
                    brackets: brackets,
                    playoff: playoff
                    );
            }
            else
            {
                e.Name      = [email protected];
                e.StartDate = DateTime.Parse([email protected]);
                e.EndDate   = DateTime.Parse([email protected]);
                e.Location  = [email protected];
                e.Type.SetTeamType(GetTeamTypeFromDivision([email protected]));
                e.Type.NumberOfEnds = numberOfEnds;
                e.Type.EventFormat  = eventFormat;
                e.Standings         = standings;
                e.Brackets          = brackets;
                e.Playoff           = playoff;
            }
            return(e);
        }
Example #6
0
        public JsonResult AddEventFormat(string name)
        {
            EventFormat eventFormat = adminRepository.AddEventFormat(name);
            JsonResult  jr          = Json(eventFormat);

            if (eventFormat.Id == 0)
            {
                jr.StatusCode = 400;
            }
            else
            {
                jr.StatusCode = 200;
            }
            return(jr);
        }
Example #7
0
 public async Task<HttpInput?> CreateHttpInputAsync(string name, string description = "", EventFormat format = EventFormat.Json)
 {
     var content = new FormUrlEncodedContent
     (new Dictionary<string, string>
     {
         {"name" , name},
         {"description", description},
         {"service", "http" },
         { "format", "json" },
     });
     var response = await _client.PostAsync("inputs/", content);
     if (response.IsSuccessStatusCode)
     {
         var json = await response.Content.ReadAsStringAsync();
         return HttpInput.Parse(json);
     }
     else
     {
         return null;
     }
 }
 public TournamentRankItemComparer(EventFormat tournamentFormat)
 {
     Format = tournamentFormat;
 }
 public LeagueRankItemComparer(EventFormat tournamentFormat)
 {
     format = tournamentFormat;
     RankByPoints = false;
 }
 public LeagueRankItemComparer()
 {
     format = EventFormat.None;
     RankByPoints = true;
 }
        static void sortResults(ref List<MatchResult> results, EventFormat eventFormat)
        {
            results.Sort((a, b) =>
            {
                var playerA = Config.Settings.GetPlayer(a.PlayerID);
                var playerB = Config.Settings.GetPlayer(b.PlayerID);

                if (a.Forfeited && b.Forfeited)
                    return playerA.Name.CompareTo(playerB.Name);
                if (a.Forfeited)
                    return 1;
                if (b.Forfeited)
                    return -1;

                switch (eventFormat)
                {
                    case EventFormat.Domination:
                        if (a.TournamentPoints != b.TournamentPoints)
                            return b.TournamentPoints.CompareTo(a.TournamentPoints);
                        return a.Differential != b.Differential ?
                            b.Differential.CompareTo(a.Differential) :
                            b.VictoryPoints.CompareTo(a.VictoryPoints);

                    case EventFormat.Disparity:
                        if (a.Differential != b.Differential)
                            return b.Differential.CompareTo(a.Differential);
                        return a.VictoryPoints != b.VictoryPoints ?
                            b.VictoryPoints.CompareTo(a.VictoryPoints) :
                            b.TournamentPoints.CompareTo(a.TournamentPoints);

                    case EventFormat.Victory:
                        if (a.VictoryPoints != b.VictoryPoints)
                            return b.VictoryPoints.CompareTo(a.VictoryPoints);
                        return a.TournamentPoints != b.TournamentPoints ?
                            b.TournamentPoints.CompareTo(a.TournamentPoints) :
                            b.Differential.CompareTo(a.Differential);
                }

                // Worst case, compare the names.
                return playerA.Name.CompareTo(playerB.Name);

            });
        }
 private void formatScores(ref string data, ref MonospacedValues monoValues, EventFormat eventFormat, Scores scores)
 {
     if (eventFormat == EventFormat.Domination)
         data += scores.tps.ToString().PadRight(monoValues.tpsLength) +
                 scores.diff.ToString().PadRight(monoValues.diffLength) +
                 scores.vps.ToString().PadRight(monoValues.vpsLength);
     else if (eventFormat == EventFormat.Disparity)
         data += scores.diff.ToString().PadRight(monoValues.diffLength) +
                 scores.vps.ToString().PadRight(monoValues.vpsLength) +
                 scores.tps.ToString().PadRight(monoValues.tpsLength);
     else //if(tournament.Format == EventFormat.Victory)
         data += scores.vps.ToString().PadRight(monoValues.vpsLength) +
                 scores.tps.ToString().PadRight(monoValues.tpsLength) +
                 scores.diff.ToString().PadRight(monoValues.diffLength);
 }
 private void formatScores(ref string data, ref Tags tag, EventFormat eventFormat, Scores scores)
 {
     if (eventFormat == EventFormat.Domination)
         data += tag.cellStart + scores.tps + tag.cellEnd + tag.cellStart +
                 scores.diff + tag.cellEnd + tag.cellStart +
                 scores.vps + tag.cellEnd;
     else if (eventFormat == EventFormat.Disparity)
         data += tag.cellStart + scores.diff + tag.cellEnd + tag.cellStart +
                 scores.vps + tag.cellEnd + tag.cellStart +
                 scores.tps + tag.cellEnd;
     else //if(tournament.Format == EventFormat.Victory)
         data += tag.cellStart + scores.vps + tag.cellEnd + tag.cellStart +
                 scores.tps + tag.cellEnd + tag.cellStart +
                 scores.diff + tag.cellEnd;
 }
Example #14
0
        public async Task <HttpInput?> CreateHttpInputAsync(string name, string description = "", EventFormat format = EventFormat.Json)
        {
            var content = new FormUrlEncodedContent
                              (new Dictionary <string, string>
            {
                { "name", name },
                { "description", description },
                { "service", "http" },
                { "format", "json" },
            });
            var response = await _client.PostAsync("inputs/", content);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                return(HttpInput.Parse(json));
            }
            else
            {
                return(null);
            }
        }
Example #15
0
        public void GetEventInfoTest(string czId, Gender g, string startDate, string endDate, string name, EventType.TeamType teamType, EventFormat eventFormat, bool standingsIsNull)
        {
            Console.WriteLine("GetEventInfoTest\nCZID: " + czId);
            Event e = Request.GetEventInfo(czId);

            Xunit.Assert.Equal(czId, e.CZId);
            Xunit.Assert.Equal(g, e.Type.Gender);
            Xunit.Assert.Equal(DateTime.Parse(startDate), e.StartDate);
            Xunit.Assert.Equal(DateTime.Parse(endDate), e.EndDate);
            Xunit.Assert.Equal(teamType, e.Type.teamType);
            Xunit.Assert.Equal(name, e.Name);
            Xunit.Assert.Equal(eventFormat, e.Type.EventFormat);
            Xunit.Assert.Equal(standingsIsNull, (e.Standings == null));
            Xunit.Assert.True(Utility.ValidatePlayoffHtml(e.Playoff.Html));
        }