public static PLEntry BuildPLEntry(VerifiedEntry fplEntry, VerifiedPLEntry plEntry) { return(new( EntryId : fplEntry.EntryId, Slug : plEntry.PlayerFullName.ToLower().Replace(" ", "-"), TeamName : fplEntry.EntryTeamName, RealName : fplEntry.FullName, Alias : fplEntry.Alias, Description : fplEntry.Description, PointsThisGw : fplEntry.EntryStats?.PointsThisGw, TotalPoints : fplEntry.EntryStats?.CurrentGwTotalPoints, OverallRank : fplEntry.EntryStats?.OverallRank, Captain : fplEntry.EntryStats?.Captain, ViceCaptain : fplEntry.EntryStats?.ViceCaptain, ChipUsed : fplEntry.EntryStats?.ActiveChip, Gameweek : fplEntry.EntryStats?.Gameweek, PLPlayerId : plEntry.PlayerId, PLName : plEntry.PlayerFullName, PlaysForTeam : plEntry.TeamName, ShirtImageUrl : $"https://fantasy.premierleague.com/dist/img/shirts/standard/shirt_{plEntry.TeamCode}-66.png", // move url-gen to client ? ImageUrl : $"https://resources.premierleague.com/premierleague/photos/players/110x140/p{plEntry.PlayerCode}.png", // move url-gen to client ? SelfOwnershipWeekCount : plEntry.SelfOwnershipStats.WeekCount, SelfOwnershipTotalPoints : plEntry.SelfOwnershipStats.TotalPoints )); }
private static HashEntry[] AllWriteFields(VerifiedPLEntry entry) { var hashEntries = new List <HashEntry>() { new("entryId", entry.EntryId), new("teamId", entry.TeamId), new("teamCode", entry.TeamCode), new("teamName", entry.TeamName), new("playerId", entry.PlayerId), new("playerCode", entry.PlayerCode), new("playerFullname", entry.PlayerFullName) }; if (entry.SelfOwnershipStats != null) { hashEntries.Add(new("selfOwnerShipWeekCount", entry.SelfOwnershipStats.WeekCount)); hashEntries.Add(new("selfOwnerShipTotalPoints", entry.SelfOwnershipStats.TotalPoints)); hashEntries.Add(new("gameweek", entry.SelfOwnershipStats.Gameweek)); } ; return(hashEntries.ToArray()); }
public async Task Insert(VerifiedPLEntry entry) { await _db.HashSetAsync($"pl-entry-{entry.EntryId}", AllWriteFields(entry)); }
private async Task UpdateSelfishStatsForPLEntry(int gameweek, CancellationToken cancellationToken, ICollection <LiveItem> liveItems, VerifiedPLEntry plEntry) { var gameweeks = Enumerable.Range(gameweek, 1); var nullFillers = Enumerable.Repeat <ICollection <LiveItem> >(null, gameweek - 1).ToList(); nullFillers.Add(liveItems); var pointsForSelfPick = await _calculator.CalculateSelfOwnershipPoints(plEntry.EntryId, plEntry.PlayerId, gameweeks, nullFillers.ToArray()); await _mediator.Publish( new IncrementPointsFromSelfOwnership(EntryId : plEntry.EntryId, PointsFromSelf : Enumerable.Sum((IEnumerable <int>)pointsForSelfPick)), cancellationToken); if (Enumerable.Any <int>(pointsForSelfPick)) { await _mediator.Publish(new IncrementSelfOwnershipWeekCounter(EntryId : plEntry.EntryId), cancellationToken); } }