Пример #1
0
        public void SeasonResultInitializedToInputParams()
        {
            var sut = new SeasonResult("abc", 2, 3);

            Assert.Equal("abc", sut.Team);
            Assert.Equal(2, sut.GoalsFor);
            Assert.Equal(3, sut.GoalsAgainst);
        }
Пример #2
0
        public async Task FindsMinimumGoalDifferentialSingleResult()
        {
            var result1 = new SeasonResult("abc", 2, 10);

            _seasonResultData.Add(result1);

            var sut = new SeasonResultService(_mockFileParser.Object, _mockLoggingService.Object);

            var result = await sut.GetSeasonResultWithSmallestPointDifferential();

            Assert.Equal(result1.Team, result.Team);
        }
Пример #3
0
        /// <summary>
        /// Creates a SeasonResult object.
        /// </summary>
        /// <returns>True if object successfully created with input params. False if not and out param is set to empty object.</returns>
        public bool TryCreate(string team, int goalsFor, int goalsAgainst, out ISeasonResult seasonResult)
        {
            try
            {
                seasonResult = new SeasonResult(team, goalsFor, goalsAgainst);
            }
            catch (Exception ex)
            {
                _loggingService.Log("Unable to create SeasonResult object from numeric values.", ex);
                seasonResult = SeasonResult.EmptySeasonResult;
            }

            return((SeasonResult)seasonResult != SeasonResult.EmptySeasonResult);
        }
Пример #4
0
        public string GetResultRaw(long discordGuildId, long matchId)
        {
            using DBContext c = new DBContext();
            SeasonResult result = c.SeasonResult.FirstOrDefault(r => r.MatchId == matchId &&
                                                                r.DiscordGuildId == discordGuildId);

            if (result == null)
            {
                return(new ApiResponse(System.Net.HttpStatusCode.NotFound, "Match not found"));
            }

            SessionResult sr = SessionResult.FromResult(result);

            return(new ApiObject <SessionResult>(sr));
        }
Пример #5
0
        public async Task FindsMinimumGoalDifferentialAmongManyResults()
        {
            var result1 = new SeasonResult("abc", 2, 10);
            var result2 = new SeasonResult("def", 4, 7);
            var result3 = new SeasonResult("ghi", 11, 13);
            var result4 = new SeasonResult("jkl", 5, 6);


            _seasonResultData.AddRange(new SeasonResult[] { result1, result2, result3, result4 });

            var sut = new SeasonResultService(_mockFileParser.Object, _mockLoggingService.Object);

            var result = await sut.GetSeasonResultWithSmallestPointDifferential();

            Assert.Equal(result4.Team, result.Team);
        }
Пример #6
0
        public static SessionResult FromResult(SeasonResult r)
        {
            if (r == null)
            {
                throw new ArgumentNullException(nameof(r));
            }

            using DBContext c = new DBContext();

            SessionResult      result = new SessionResult(r.DiscordGuildId, r.MatchId, r.MatchName, r.Stage, r.WinningTeam, r.LosingTeam, r.TimeStamp);
            List <SeasonScore> scores = c.SeasonScore.Where(s => s.SeasonResultId == r.Id).ToList();

            //Convert players + maps and add maps to result
            List <long> scoreUserIds = scores.Select(s => s.SeasonPlayerId).Distinct().ToList();
            List <long> scoreMapIds  = scores.Select(s => s.BeatmapId).Distinct().ToList();

            List <SeasonPlayer>  players = new List <SeasonPlayer>(scoreUserIds.Count);
            List <SeasonBeatmap> maps    = new List <SeasonBeatmap>(scoreMapIds.Count);

            for (int i = 0; i < scoreUserIds.Count; i++)
            {
                players.Add(c.SeasonPlayer.First(p => p.Id == scoreUserIds[i]));
            }

            for (int i = 0; i < scoreMapIds.Count; i++)
            {
                maps.Add(c.SeasonBeatmap.FirstOrDefault(b => b.Id == scoreMapIds[i]));
            }

            result.Beatmaps = maps.Select(m => (SessionBeatmap)m).ToArray();

            //Convert teams and add them to the result
            Dictionary <string, List <SeasonPlayer> > teams = players.GroupBy(p => p.TeamName).ToDictionary(p => p.Key, p => p.ToList());

            string teamA = teams.Keys.ElementAt(0);
            string teamB = teams.Keys.ElementAt(1);

            result.Teams = new SessionTeam[]
            {
                new SessionTeam(teamA, teams[teamA].Select(p => (SessionPlayer)p).ToArray()),
                new SessionTeam(teamB, teams[teamB].Select(p => (SessionPlayer)p).ToArray()),
            };
            //

            //Convert scores and add them + players to the teams
            Dictionary <long, List <SeasonScore> >  uscores = scores.GroupBy(s => s.SeasonPlayerId).ToDictionary(s => s.Key, s => s.ToList());
            Dictionary <long, List <SessionScore> > rscores = new Dictionary <long, List <SessionScore> >(uscores.Count);

            for (int i = 0; i < uscores.Keys.Count; i++)
            {
                long key = uscores.Keys.ElementAt(i);
                List <SeasonScore> scs = uscores[key];

                key = players.First(p => p.Id == key).OsuUserId;

                rscores.Add(key, scs.Select(s => (SessionScore)s).ToList());
            }

            for (int i = 0; i < result.Teams.Length; i++)
            {
                for (int x = 0; x < result.Teams[x].Players.Length; x++)
                {
                    result.Teams[x].Players[i].Scores = rscores[result.Teams[x].Players[i].OsuUserId].ToArray();
                }
            }
            //

            return(result);
        }