Add controler actions to return stats for

the current season
This commit is contained in:
Sébastien André
2020-02-14 16:48:43 +01:00
parent b8a1115d6a
commit 6e804b1ae4
5 changed files with 132 additions and 0 deletions

View File

@@ -14,5 +14,13 @@ namespace skydiveLogs_api.Business.Interface
IEnumerable<Statistic> GetStatsByGear();
IEnumerable<Statistic> GetStatsByYear();
IEnumerable<Statistic> GetStatsForLastYearByDz();
IEnumerable<Statistic> GetStatsForLastYearByJumpType();
IEnumerable<Statistic> GetStatsForLastMonthByDz();
IEnumerable<Statistic> GetStatsForLastMonthByJumpType();
}
}

View File

@@ -85,6 +85,80 @@ namespace skydiveLogs_api.Business
.ToList();
}
public IEnumerable<Statistic> GetStatsForLastYearByDz()
{
var allJumps = _jumpRepository.GetAll();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
var yearOfLastJump = lastJump.JumpDate.Year;
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
.GroupBy(j => j.DropZone.Name,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsForLastYearByJumpType()
{
var allJumps = _jumpRepository.GetAll();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
var yearOfLastJump = lastJump.JumpDate.Year;
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump)
.GroupBy(j => j.JumpType.Name,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsForLastMonthByDz()
{
var allJumps = _jumpRepository.GetAll();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
var yearOfLastJump = lastJump.JumpDate.Year;
var monthOfLastJump = lastJump.JumpDate.Month;
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
.GroupBy(j => j.DropZone.Name,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
public IEnumerable<Statistic> GetStatsForLastMonthByJumpType()
{
var allJumps = _jumpRepository.GetAll();
var lastJump = allJumps.OrderByDescending(j => j.JumpDate).FirstOrDefault();
var yearOfLastJump = lastJump.JumpDate.Year;
var monthOfLastJump = lastJump.JumpDate.Month;
return allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump)
.GroupBy(j => j.JumpType.Name,
j => j,
(groupby, jumps) => new Statistic
{
Label = groupby.ToString(),
Nb = jumps.Count()
})
.ToList();
}
private readonly IJumpRepository _jumpRepository;
}
}