Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Badge Model To Have Current Year #248

Open
davidenwang opened this issue Apr 24, 2019 · 0 comments
Open

Fix Badge Model To Have Current Year #248

davidenwang opened this issue Apr 24, 2019 · 0 comments
Assignees
Labels
bug Something isn't working profile-badges

Comments

@davidenwang
Copy link
Contributor

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.

def serialize_to_json(self):
return {
"id": self.id,
"title": self.title,
"progress_text": self.progress_text,
"description": self.description,
"congrats_text": self.congrats_text,
"graphic": self.graphic,
"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).

class NthQuizBadge(Badge):
def __init__(self, quantity, graphic):
badge_id = int(str(1) + str(quantity))

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

def get_user_badges(user):
return [all_badge_map[badge_id] for badge_id in user.badges]

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working profile-badges
Projects
None yet
Development

No branches or pull requests

2 participants