From f72bb98868ff00bf5262fbc9a9ede6430cc7f690 Mon Sep 17 00:00:00 2001 From: Meghan Date: Tue, 14 May 2024 16:20:32 -0700 Subject: [PATCH] Add and display stats --- Wordle.Api/Wordle.Api/Services/GameService.cs | 21 ++++++++++++ wordle-web/pages/index.vue | 34 ++++++++++++++++--- wordle-web/scripts/game.ts | 8 ++++- wordle-web/scripts/gameStats.ts | 15 ++++++++ 4 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 wordle-web/scripts/gameStats.ts diff --git a/Wordle.Api/Wordle.Api/Services/GameService.cs b/Wordle.Api/Wordle.Api/Services/GameService.cs index ed59432a..f4e38a99 100644 --- a/Wordle.Api/Wordle.Api/Services/GameService.cs +++ b/Wordle.Api/Wordle.Api/Services/GameService.cs @@ -54,4 +54,25 @@ public async Task GetGameStats(Game game) return stats; } + + public IQueryable StatsForAllWords() + { + IQueryable result = Db.Games + .Include(g => g.Word) + .GroupBy(g => g.Word!.Text) + .Select(g => new AllWordStats() + { + Word = g.Key, + AverageGuesses = g.Average(x => x.Attempts) + }); + + return result; + } +} + +public class AllWordStats() +{ + public required string Word { get; set; } + + public double AverageGuesses { get; set; } } diff --git a/wordle-web/pages/index.vue b/wordle-web/pages/index.vue index bca138fb..f7271593 100644 --- a/wordle-web/pages/index.vue +++ b/wordle-web/pages/index.vue @@ -1,10 +1,6 @@