Skip to content

Commit

Permalink
Exclude accepted answer in stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Apr 8, 2024
1 parent b3f362c commit ad119ed
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions MyApp.ServiceInterface/LeaderboardServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task<object> Any(CalculateLeaderBoard request)
{
var statTotals = await Db.SelectAsync<StatTotals>();
// filter to answers only
var answers = statTotals.Where(x => x.Id.Contains('-')).ToList();
var answers = statTotals.Where(x => x.Id.Contains('-') && !x.Id.Contains("-accepted")).ToList();
// Sum up votes by model, first group by UserName
var statsByUser = answers.GroupBy(x => x.Id.SplitOnFirst('-')[1]).Select(x => new StatTotals
{
Expand Down Expand Up @@ -143,7 +143,7 @@ double CalculateWinRate(List<StatTotals> statTotalsList, string name, int questi

public async Task<object> Any(GetLeaderboardStatsByTag request)
{
var statTotals = Db.Select<StatTotals>(@"SELECT st.*
var statTotals = await Db.SelectAsync<StatTotals>(@"SELECT st.*
FROM main.StatTotals st
JOIN main.post p ON st.PostId = p.Id
WHERE (p.Tags LIKE @TagMiddle OR p.Tags LIKE @TagLeft OR p.Tags LIKE @TagRight OR p.Tags = @TagSolo)", new { TagSolo = $"[{request.Tag}]",
Expand All @@ -152,7 +152,7 @@ FROM main.StatTotals st
TagMiddle = $",{request.Tag},",
});
// filter to answers only
var answers = statTotals.Where(x => x.Id.Contains('-')).ToList();
var answers = statTotals.Where(x => x.Id.Contains('-') && !x.Id.Contains("-accepted")).ToList();
// Sum up votes by model, first group by UserName
var statsByUser = answers.GroupBy(x => x.Id.SplitOnFirst('-')[1]).Select(x => new StatTotals
{
Expand All @@ -168,13 +168,13 @@ FROM main.StatTotals st

public async Task<object> Any(GetLeaderboardStatsHuman request)
{
var statTotals = Db.Select<StatTotals>(@"
var statTotals = await Db.SelectAsync<StatTotals>(@"
select * from main.StatTotals where PostId in (select PostId from StatTotals
where PostId in (select StatTotals.PostId from StatTotals
where Id like '%-accepted')
group by PostId) and (Id like '%-accepted' or Id like '%-most-voted' or Id not like '%-%')");
// filter to answers only
var answers = statTotals.Where(x => x.Id.Contains('-')).ToList();
var answers = statTotals.Where(x => x.Id.Contains('-') && !x.Id.Contains("-accepted")).ToList();
// Sum up votes by model, first group by UserName
var statsByUser = answers.GroupBy(x => x.Id.SplitOnFirst('-')[1]).Select(x => new StatTotals
{
Expand Down

0 comments on commit ad119ed

Please sign in to comment.