Page MenuHomePhabricator

Update game statistics to use database instead of SharedPrefs.
Closed, ResolvedPublic

Description

This task is to convert the current logic of storing gameplay history to use a proper database table, instead of the current json structure in SharedPreferences.
(Note: the "current" day's gameState can remain in SharedPrefs; this only applies to game history, which will need to be queried for statistics and archives.)

In order to future-proof the database table somewhat, let's think deliberately about the structure that the table should have:

Table name: DailyGameHistory

gameNamelanguageyearmonthdayscoreplayTypegameData
Identifier for the game, e.g. whichcamefirstLanguage wiki on which this game was playedYearMonthDayThe score for the game on this dayThe "type" of gameplay this row represents.Additional data for this game, e.g. results for each question; can be a json string

example:

whichcamefirsten2025042040{"true","true","false","true","true"}
  • The score field is technically redundant, since it can be calculated based on the gameData field, but it will be useful and efficient this way for statistics.
  • The playType field is a special field that indicates "how" this day's game was played. For example, was this game played on the day that it happened? Or was it played as part of an archived game? This can be an integer enum with values like PLAYED_ON_SAME_DAY=0 and PLAYED_ON_ARCHIVE=1. This will be useful for calculating proper "streaks". If we allow users to play previous days' games, those games should not retroactively increase the streak of the player.

Event Timeline

For the gameName, would it be better to store a long ID from an enum class instead of a plain string?

enum class WikiGames {
      WhichCameFirst(1, ...),
      Game2(2, ...),
}

For the gameName, would it be better to store a long ID from an enum class instead of a plain string?

Sure! That will probably make it more efficient to query.

@Dbrant did someone test an existing install with a preexisting score migrated with no issues?

@Dbrant did someone test an existing install with a preexisting score migrated with no issues?

Definitely - this was tested as part of reviewing and merging the PR.