Merged Daily Value retrieval with GameDataResponseToList.

This commit is contained in:
Hipposgrumm 2025-10-19 12:48:44 -06:00
parent a74eea66a4
commit 695cc761b6

View File

@ -39,24 +39,24 @@ public class GameDataService {
return true; return true;
} }
List<GameDataResponse> GameDataResponseToList(IQueryable<Model.GameData> originalQuery, string key, int count, bool AscendingOrder, string apiKey) { List<GameDataResponse> GameDataResponseToList(IQueryable<Model.GameData> originalQuery, string key, int count, bool AscendingOrder, string apiKey, bool daily=false) {
var query = originalQuery.SelectMany(e => e.GameDataPairs) var query = originalQuery.SelectMany(e => e.GameDataPairs)
.Where(x => x.Name == key); .Where(x => x.Name == key);
if (AscendingOrder) if (AscendingOrder)
query = query.OrderBy(e => e.Value); query = query.OrderBy(e => daily ? e.DailyValue : e.Value);
else else
query = query.OrderByDescending(e => e.Value); query = query.OrderByDescending(e => daily ? e.DailyValue : e.Value);
uint gameVersion = ClientVersion.GetVersion(apiKey); uint gameVersion = ClientVersion.GetVersion(apiKey);
if (gameVersion <= ClientVersion.Max_OldJS) if (gameVersion <= ClientVersion.Max_OldJS)
// use DisplayName instead of Name // use DisplayName instead of Name
return query.Select(e => new GameDataResponse( return query.Select(e => new GameDataResponse(
XmlUtil.DeserializeXml<AvatarData>(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value) XmlUtil.DeserializeXml<AvatarData>(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, daily ? e.DailyValue : e.Value)
).Take(count).ToList(); ).Take(count).ToList();
else else
return query.Select(e => new GameDataResponse( return query.Select(e => new GameDataResponse(
e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value) e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, daily ? e.DailyValue : e.Value)
).Take(count).ToList(); ).Take(count).ToList();
} }
@ -74,28 +74,15 @@ public class GameDataService {
} }
public GameDataSummary GetDailyGameData(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, bool buddyFilter, string apiKey) { public GameDataSummary GetDailyGameData(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, bool buddyFilter, string apiKey) {
IQueryable<GameDataPair> query = ctx.GameData IQueryable<Model.GameData> query = ctx.GameData
.Where(x => .Where(x =>
x.GameId == gameId && x.IsMultiplayer == false && x.GameId == gameId && x.IsMultiplayer == false &&
x.Difficulty == difficulty && x.GameLevel == gameLevel && x.Difficulty == difficulty && x.GameLevel == gameLevel &&
x.DatePlayed.Date == DateTime.UtcNow.Date x.DatePlayed.Date == DateTime.UtcNow.Date);
).SelectMany(e => e.GameDataPairs).Where(x => x.Name == key);
// TODO: Buddy filter // TODO: Buddy filter
if (AscendingOrder) query = query.OrderBy(e => e.Value); List<GameDataResponse> selectedData = GameDataResponseToList(query, key, count, AscendingOrder, apiKey, true);
else query = query.OrderByDescending(e => e.Value);
List<GameDataResponse> selectedData;
if (ClientVersion.GetVersion(apiKey) <= ClientVersion.Max_OldJS)
// use DisplayName instead of Name
selectedData = query.Select(e => new GameDataResponse(
XmlUtil.DeserializeXml<AvatarData>(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, false, false, e.DailyValue)
).Take(count).ToList();
else
selectedData = query.Select(e => new GameDataResponse(
e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, false, false, e.DailyValue)
).Take(count).ToList();
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData); return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
} }