mirror of
https://github.com/TomasiDeveloping/PlayerManagement.git
synced 2026-04-16 17:22:21 +00:00
MVP for R4 and R5
This commit is contained in:
parent
c1b67c721e
commit
9ccfc034da
@ -77,6 +77,29 @@ namespace Api.Controllers.v1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("[action]/{allianceId:guid}")]
|
||||||
|
public async Task<ActionResult<List<PlayerMvpDto>>> GetAllianceLeadershipMvp(Guid allianceId,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var alliancePlayersResult =
|
||||||
|
await playerRepository.GetAllianceLeadershipMvp(allianceId, cancellationToken);
|
||||||
|
|
||||||
|
if (alliancePlayersResult.IsFailure) return BadRequest(alliancePlayersResult.Error);
|
||||||
|
|
||||||
|
return alliancePlayersResult.Value.Count > 0
|
||||||
|
? Ok(alliancePlayersResult.Value)
|
||||||
|
: NoContent();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.LogError(e, e.Message);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult<PlayerDto>> CreatePlayer(CreatePlayerDto createPlayerDto,
|
public async Task<ActionResult<PlayerDto>> CreatePlayer(CreatePlayerDto createPlayerDto,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
|
|||||||
@ -11,6 +11,8 @@ public interface IPlayerRepository
|
|||||||
|
|
||||||
Task<Result<List<PlayerMvpDto>>> GetAlliancePlayersMvp(Guid allianceId, CancellationToken cancellationToken);
|
Task<Result<List<PlayerMvpDto>>> GetAlliancePlayersMvp(Guid allianceId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
Task<Result<List<PlayerMvpDto>>> GetAllianceLeadershipMvp(Guid allianceId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
Task<Result<PlayerDto>> CreatePlayerAsync(CreatePlayerDto createPlayerDto, string createdBy, CancellationToken cancellationToken);
|
Task<Result<PlayerDto>> CreatePlayerAsync(CreatePlayerDto createPlayerDto, string createdBy, CancellationToken cancellationToken);
|
||||||
|
|
||||||
Task<Result<PlayerDto>> UpdatePlayerAsync(UpdatePlayerDto updatePlayerDto, string modifiedBy, CancellationToken cancellationToken);
|
Task<Result<PlayerDto>> UpdatePlayerAsync(UpdatePlayerDto updatePlayerDto, string modifiedBy, CancellationToken cancellationToken);
|
||||||
|
|||||||
@ -83,6 +83,52 @@ public class PlayerRepository(ApplicationContext context, IMapper mapper, ILogge
|
|||||||
return playerMvps;
|
return playerMvps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Result<List<PlayerMvpDto>>> GetAllianceLeadershipMvp(Guid allianceId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var currentDate = DateTime.Now;
|
||||||
|
var threeWeeksAgo = currentDate.AddDays(-21);
|
||||||
|
|
||||||
|
var playerMvps = await context.Players
|
||||||
|
.Where(p => p.AllianceId == allianceId && (p.Rank.Name == "R4" || p.Rank.Name == "R5"))
|
||||||
|
.Select(p => new
|
||||||
|
{
|
||||||
|
p.Id,
|
||||||
|
p.PlayerName,
|
||||||
|
Rank = p.Rank.Name,
|
||||||
|
|
||||||
|
VsDuels = context.VsDuelParticipants
|
||||||
|
.Where(vp => vp.PlayerId == p.Id && vp.VsDuel.EventDate <= currentDate && !vp.VsDuel.IsInProgress)
|
||||||
|
.OrderByDescending(vp => vp.VsDuel.EventDate)
|
||||||
|
.Take(3)
|
||||||
|
.Sum(vp => vp.WeeklyPoints),
|
||||||
|
|
||||||
|
MarshalGuardParticipationCount = context.MarshalGuardParticipants
|
||||||
|
.Count(mpg => mpg.PlayerId == p.Id && mpg.Participated && mpg.MarshalGuard.EventDate > threeWeeksAgo),
|
||||||
|
|
||||||
|
DessertStormParticipationCount = context.DesertStormParticipants
|
||||||
|
.Count(dsp => dsp.PlayerId == p.Id && dsp.Participated && dsp.DesertStorm.EventDate > threeWeeksAgo)
|
||||||
|
})
|
||||||
|
.Select(p => new PlayerMvpDto()
|
||||||
|
{
|
||||||
|
PlayerName = p.PlayerName,
|
||||||
|
Rank = p.Rank,
|
||||||
|
TotalVsDuelPoints = p.VsDuels,
|
||||||
|
MarshalGuardParticipationCount = p.MarshalGuardParticipationCount,
|
||||||
|
DesertStormParticipationCount = p.DessertStormParticipationCount,
|
||||||
|
MvpPoints = Math.Round(
|
||||||
|
(decimal)((p.VsDuels / 1000000.0 * 0.7) +
|
||||||
|
(p.MarshalGuardParticipationCount * 15) +
|
||||||
|
(p.DessertStormParticipationCount * 10))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.OrderByDescending(p => p.MvpPoints)
|
||||||
|
.ThenByDescending(p => p.TotalVsDuelPoints)
|
||||||
|
.ThenByDescending(p => p.MarshalGuardParticipationCount)
|
||||||
|
.ThenBy(p => p.PlayerName)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return playerMvps;
|
||||||
|
}
|
||||||
public async Task<Result<PlayerDto>> CreatePlayerAsync(CreatePlayerDto createPlayerDto, string createdBy, CancellationToken cancellationToken)
|
public async Task<Result<PlayerDto>> CreatePlayerAsync(CreatePlayerDto createPlayerDto, string createdBy, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var newPlayer = mapper.Map<Player>(createPlayerDto);
|
var newPlayer = mapper.Map<Player>(createPlayerDto);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user