You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently in backend/models/Badge.py the serialize_to_json function hardcodes the year to be 2018 which should be changed to the current year the badge was earned.
"year": 2018, # if we get a table in to track current year we need to use that
}
The data is organized in a hierarchy of BadgeCategory having a set of Badges. Each BadgeCategory would represent a category such as completing n number of quizzes, or achieving n number of perfect quizzes. Each subclass of BadgeCategory would have to implement a get_progress function which takes in a user which recently completed a quiz represented by quiz_result and returns the user's progress in that badge category.
Right now each user has an array of badge ids saved in the database. These badge ids are generated by each Badge and are numbers such as (11, 21, 25).
The first digit represents the type of badge (e.g. 1 means NthQuizBadge) and the second digit represents the quantity when the badge is awarded. So the badge 15 is the badge earned when a student completes 5 quizzes.
One possible way to include a year would be to encode that data into each user's badge array. Instead of just saving an id like 11 or 21, a year could also be encoded and included. So the array of badge ids could change to look like [112018, 212019]. This would represent earning badge 11 in year 2018 and earning badge 21 in 2019. This does look a little messy so perhaps the array of int ids could be changed to an array of string ids [11:2018, 21:2019] which may make parsing a little easier. Then to complete the implementation simply parse out the year from each entry in the user's badge array and add that in as data when the badge is serialized and sent to the frontend via the get_user_badges(user) function
There may be additional work to make sure that each BadgeCategory is up to date for each new year of Reading Olympics, but hopefully it can be solved without too much additional work or model rewrites.
These are just ideas though. Do feel free to more thoroughly refactor the badge model to make it easier to extend for complex functionality or store badges differently in the database.
The text was updated successfully, but these errors were encountered:
Currently in backend/models/Badge.py the serialize_to_json function hardcodes the year to be 2018 which should be changed to the current year the badge was earned.
philareads/backend/api/models/Badge.py
Lines 22 to 31 in 5f97816
The data is organized in a hierarchy of
BadgeCategory
having a set ofBadge
s. Each BadgeCategory would represent a category such as completing n number of quizzes, or achieving n number of perfect quizzes. Each subclass ofBadgeCategory
would have to implement aget_progress
function which takes in auser
which recently completed a quiz represented byquiz_result
and returns the user's progress in that badge category.Right now each user has an array of badge ids saved in the database. These badge ids are generated by each Badge and are numbers such as (11, 21, 25).
philareads/backend/api/models/Badge.py
Lines 115 to 117 in 5f97816
The first digit represents the type of badge (e.g. 1 means NthQuizBadge) and the second digit represents the quantity when the badge is awarded. So the badge 15 is the badge earned when a student completes 5 quizzes.
One possible way to include a year would be to encode that data into each user's badge array. Instead of just saving an id like 11 or 21, a year could also be encoded and included. So the array of badge ids could change to look like
[112018, 212019]
. This would represent earning badge 11 in year 2018 and earning badge 21 in 2019. This does look a little messy so perhaps the array of int ids could be changed to an array of string ids[11:2018, 21:2019]
which may make parsing a little easier. Then to complete the implementation simply parse out the year from each entry in the user's badge array and add that in as data when the badge is serialized and sent to the frontend via theget_user_badges(user)
functionphilareads/backend/api/models/Badge.py
Lines 209 to 210 in 5f97816
There may be additional work to make sure that each
BadgeCategory
is up to date for each new year of Reading Olympics, but hopefully it can be solved without too much additional work or model rewrites.These are just ideas though. Do feel free to more thoroughly refactor the badge model to make it easier to extend for complex functionality or store badges differently in the database.
The text was updated successfully, but these errors were encountered: