Пример #1
0
        /// <summary>
        /// Calculates hits taken
        /// </summary>
        /// <returns></returns>
        private string PrintHitsTaken()
        {
            StringBuilder result = new StringBuilder();

            var teamBlurbs = this.weeklyResults
                             .Where(x => x.HitsTakenCost > 0)
                             .Select(y => $"{y.Name} (-{y.HitsTakenCost} pts)");

            if (teamBlurbs.Count() > 0)
            {
                string blurb = TextUtilities.NaturalParse(teamBlurbs);

                if (teamBlurbs.Count() == 1)
                {
                    result.Append($"The only team to take a hit this week was {blurb}.");
                }
                else if (teamBlurbs.Count() == 2)
                {
                    result.Append($"{blurb} both took transfer hits.");
                }
                else if (teamBlurbs.Count() > 2)
                {
                    result.Append($"{blurb} all took hits this week.");
                }

                return(result.ToString());
            }
            else
            {
                result.Append("No hits were taken this week.");
            }


            return(result.ToString());
        }
Пример #2
0
        /// <summary>
        /// Calculate which chips were used during this gameweek
        /// </summary>
        /// <returns></returns>
        private string CalculateChipsUsed()
        {
            this.logger.Log("Calculating chips used...");

            StringBuilder result = new StringBuilder();

            var teamBlurbs = this.weeklyResults
                             .Where(t => !string.IsNullOrEmpty(t.ChipUsed))
                             .Select(t => $"{t.Name} ({t.ChipUsed})");

            if (teamBlurbs.Count() < 1)
            {
                result.Append("No chips were played this week.");
            }
            else if (teamBlurbs.Count() > 5)
            {
                result.Append($"A flurry of activity this week as {TextUtilities.NaturalParse(teamBlurbs)} all played chips.");
            }
            else if (teamBlurbs.Count() == 1)
            {
                result.Append($"{TextUtilities.NaturalParse(teamBlurbs)} was the only team to use a chip this week.");
            }
            else
            {
                result.Append($"{TextUtilities.NaturalParse(teamBlurbs)} decided to spend one of their chips this week.");
            }

            return(result.ToString());
        }
Пример #3
0
        /// <summary>
        /// Calculates the top 5(ish) placements for this week
        /// </summary>
        /// <returns></returns>
        private string CalculateTop()
        {
            this.logger.Log("Calculating top positions...");

            StringBuilder result = new StringBuilder();

            long topScore      = this.weeklyResults.Max(t => t.Points);
            long topGrossScore = this.weeklyResults.Max(t => t.ScoreBeforeHits);
            long top3Score     = this.weeklyResults.Take(3).Last().Points;

            IEnumerable <string> winnerNames = this.weeklyResults                   // This weeks winner(s)
                                               .Where(x => x.Points == topScore)    // Find all teams with the top score
                                               .Select(x => x.Name);                // Get their name(s)

            IEnumerable <string> topNamesBeforeTransferCost = this.weeklyResults    // Used for Dan Davies rule
                                                              .OrderByDescending(x => x.ScoreBeforeHits)
                                                              .Where(x => x.ScoreBeforeHits == topGrossScore)
                                                              .Select(x => x.Name);

            IEnumerable <string> topNames = this.weeklyResults                          // Top 3ish teams for this week
                                            .Where(x => x.Points >= top3Score)          // Find anyone that had top 3 score or better
                                            .Where(x => x.Points < topScore)            // Exlude the first one
                                            .Select(x => $"{x.Name} ({x.Points} pts)"); // Prepare text

            bool daviesRuleInEffect = !(topNamesBeforeTransferCost.All(x => winnerNames.Contains(x)) && winnerNames.All(x => topNamesBeforeTransferCost.Contains(x)));
            long winnerHitCost      = this.weeklyResults.First().HitsTakenCost;

            if (daviesRuleInEffect)
            {
                result.Append($"{TextUtilities.NaturalParse(topNamesBeforeTransferCost)} {TextUtilities.WasWere(topNamesBeforeTransferCost.Count(), true)} in line to win the week until the ever so controversial Dan Davies rule was applied. But once the dust settled the ");
            }
            else
            {
                result.Append("The ");
            }

            result.Append($"winner{TextUtilities.Pluralize(winnerNames.Count())} for gameweek #{this.currentEventId} {TextUtilities.WasWere(winnerNames.Count())} {TextUtilities.NaturalParse(winnerNames)} with {topScore} points");

            if (winnerHitCost > 0 && winnerNames.Count() == 1)
            {
                result.Append($" despite taking a -{winnerHitCost} point hit! ");
            }
            else
            {
                result.Append("! ");
            }

            result.AppendLine($"Rounding up the top {topNames.Count() + winnerNames.Count()} for the week {TextUtilities.WasWere(winnerNames.Count())} {TextUtilities.NaturalParse(topNames)}.");

            return(result.ToString());
        }
Пример #4
0
        /// <summary>
        /// Calculate the bottom 5 results for this week
        /// </summary>
        /// <returns></returns>
        private string CalculateBottom()
        {
            this.logger.Log("Calculating bottom positions...");

            StringBuilder result = new StringBuilder();

            IEnumerable <string> worstTeams = this.weeklyResults                          // The worst performing teams of the week
                                              .Skip(this.weeklyResults.Count() - 4)       // Get the last 4 teams
                                              .Select(t => $"{t.Name} ({t.Points} pts)"); // Prepare text

            result.AppendLine($"The worst ranking teams this week were {TextUtilities.NaturalParse(worstTeams)}. You should probably be embarrassed. ");

            return(result.ToString());
        }
Пример #5
0
        private string CalculateMoversAndShakers()
        {
            StringBuilder result = new StringBuilder();

            long highestClimbed = this.weeklyResults.Max(team => team.PositionChangedSinceLastWeek);
            long highestDrop    = this.weeklyResults.Min(team => team.PositionChangedSinceLastWeek);

            var bestClimbers = this.weeklyResults
                               .Where(team => team.PositionChangedSinceLastWeek == highestClimbed);

            var worstDroppers = this.weeklyResults
                                .Where(team => team.PositionChangedSinceLastWeek == highestDrop);


            if (highestClimbed < 2 && highestDrop < 2)
            {
                result.Append($"There were no significants movement on the overall standings this week.");
            }
            else
            {
                if (highestClimbed > 1)
                {
                    result.Append($"As for shakers and movers {TextUtilities.NaturalParse(bestClimbers.Select(i => $"{i.Name}").ToList())} climbed {highestClimbed} spots this week.");
                }
                else
                {
                    result.Append($"Nobody made any significant climbs upwards on the table this week.");
                }

                result.Append(" ");

                if (highestDrop < -1)
                {
                    result.Append($"In the not so great department we have {TextUtilities.NaturalParse(worstDroppers.Select(i => $"{i.Name}").ToList())} dropping {Math.Abs(highestDrop)} spots.");
                }
                else
                {
                    result.Append($"On the other hand nobody made any significant drops on the table.");
                }
            }

            result.AppendLine();

            return(result.ToString());
        }
Пример #6
0
        /// <summary>
        /// Calculates the highest left on bench score
        /// </summary>
        /// <returns></returns>
        private string CalculatePointsOnBench()
        {
            this.logger.Log("Calculating points benched...");

            StringBuilder           result = new StringBuilder();
            Dictionary <long, long> teams  = new Dictionary <long, long>();
            long highestPoints             = 0;

            foreach (var team in this.fplTeam.Values)
            {
                var history = team.History.Find(t => t.Event == this.currentEventId);
                teams.Add(team.Entry.Id.Value, history.PointsOnBench.Value);

                if (history.PointsOnBench.Value > highestPoints)
                {
                    highestPoints = history.PointsOnBench.Value;
                }
            }

            var teansWithHighest = teams
                                   .GroupBy(y => y.Value)
                                   .OrderByDescending(y => y.Key)
                                   .First()
                                   .Select(a => this.fplTeam[a.Key].Entry.Name)
                                   .ToList();

            result.Append($"{TextUtilities.NaturalParse(teansWithHighest)} left ");

            if (highestPoints > 20)
            {
                result.Append($"{TextUtilities.GetGoodAdjective()} ");
            }

            result.Append($"{highestPoints} points on the bench which was the highest in the league.");

            return(result.ToString());
        }
Пример #7
0
        /// <summary>
        /// Calculates the captaincy choices for the week.
        /// </summary>
        /// <returns></returns>
        private async Task <string> CalculateCaptains()
        {
            this.logger.Log("Calculating captains...");

            StringBuilder result = new StringBuilder();

            var groupedCaptains = this.fplPicks
                                  .Select(p => p.Value.Picks.Find(y => y.IsCaptain.Value).Element)
                                  .GroupBy(id => id.Value)
                                  .OrderByDescending(g => g.Count());

            var groupedViceCaptains = this.fplPicks
                                      .Select(p => p.Value.Picks.Find(y => y.IsViceCaptain.Value).Element)
                                      .GroupBy(id => id.Value)
                                      .OrderByDescending(g => g.Count());

            foreach (var p in groupedCaptains.AsParallel())
            {
                if (!this.fplPlayerSummaries.ContainsKey(p.Key))
                {
                    FplPlayerSummary summary = await string.Format(this.PlayerSummaryUrI, p.Key).GetJsonAsync <FplPlayerSummary>().ConfigureAwait(false);

                    this.fplPlayerSummaries.Add(p.Key, summary);
                }
            }

            foreach (var p in groupedViceCaptains.AsParallel())
            {
                if (!this.fplPlayerSummaries.ContainsKey(p.Key))
                {
                    FplPlayerSummary summary = await string.Format(this.PlayerSummaryUrI, p.Key).GetJsonAsync <FplPlayerSummary>().ConfigureAwait(false);

                    this.fplPlayerSummaries.Add(p.Key, summary);
                }
            }

            List <CaptainChoice> captains = new List <CaptainChoice>();

            foreach (var pick in this.fplPicks)
            {
                long teamId   = pick.Key;
                var  cptPick  = pick.Value.Picks.Find(p => p.IsCaptain.Value);
                var  vicePick = pick.Value.Picks.Find(p => p.IsViceCaptain.Value);

                var cptPlayer  = this.fplPlayers[cptPick.Element.Value];
                var vicePlayer = this.fplPlayers[vicePick.Element.Value];

                CaptainChoice cc = new CaptainChoice()
                {
                    CaptainMultiplier  = cptPick.Multiplier.Value,
                    CaptainId          = cptPlayer.Id.Value,
                    CaptainEventPoints = this.fplPlayerSummaries[cptPlayer.Id.Value].History.FindAll(y => y.Round == this.currentEventId).Sum(x => x.TotalPoints.Value),
                    TeamEntryId        = teamId,
                    CaptainPlayed      = this.fplPlayerSummaries[cptPlayer.Id.Value].History.FindAll(y => y.Round == this.currentEventId).Sum(x => x.Minutes.Value) > 0,
                    ViceMultiplier     = vicePick.Multiplier.Value,
                    ViceEventPoints    = this.fplPlayerSummaries[vicePlayer.Id.Value].History.FindAll(y => y.Round == this.currentEventId).Sum(x => x.TotalPoints.Value),
                    ViceId             = vicePlayer.Id.Value,
                    VicePlayed         = this.fplPlayerSummaries[vicePlayer.Id.Value].History.FindAll(y => y.Round == this.currentEventId).Sum(x => x.Minutes.Value) > 0
                };

                captains.Add(cc);
            }

            var groupedScores = captains
                                .Where(c => !c.BothBlanked)
                                .GroupBy(c => c.EventScoreMultiplied)
                                .OrderByDescending(g => g.Key);

            int  noBest     = groupedScores.First().Count();
            int  noWorst    = groupedScores.Last().Count();
            long bestScore  = groupedScores.First().Key;
            long worstScore = groupedScores.Last().Key;

            List <long> bestPlayerIds  = new List <long>();
            List <long> worstPlayerIds = new List <long>();
            List <long> bestTeamIds    = new List <long>();
            List <long> worstTeamIds   = new List <long>();

            foreach (var p in groupedScores.First())
            {
                if (!bestPlayerIds.Contains(p.ActivePlayerId))
                {
                    bestPlayerIds.Add(p.ActivePlayerId);
                }

                if (!bestTeamIds.Contains(p.TeamEntryId))
                {
                    bestTeamIds.Add(p.TeamEntryId);
                }
            }

            foreach (var p in groupedScores.Last())
            {
                if (!worstPlayerIds.Contains(p.ActivePlayerId))
                {
                    worstPlayerIds.Add(p.ActivePlayerId);
                }

                if (!worstTeamIds.Contains(p.TeamEntryId))
                {
                    worstTeamIds.Add(p.TeamEntryId);
                }
            }

            result.Append($"When it came to captaincy choice{TextUtilities.Pluralize(noBest)} {TextUtilities.NaturalParse(bestTeamIds.Select(i => $"{this.fplTeam[i].Entry.Name}").ToList())} did the best this week with {bestScore} point{TextUtilities.Pluralize(noBest)} from {TextUtilities.NaturalParse(bestPlayerIds.Select(i => $"{this.fplPlayers[i].FirstName} {this.fplPlayers[i].SecondName}").ToList())}. ");
            result.AppendLine($"On the other end of the spectrum were {TextUtilities.NaturalParse(worstTeamIds.Select(i => $"{this.fplTeam[i].Entry.Name}").ToList())} who had picked {TextUtilities.NaturalParse(worstPlayerIds.Select(i => $"{this.fplPlayers[i].FirstName} {this.fplPlayers[i].SecondName}").ToList())} for a total of {worstScore} point{TextUtilities.Pluralize((int)worstScore)}. You receive the armband of shame for this week. ");

            return(result.ToString());
        }