Skip to content

Commit

Permalink
add goal and adjust naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jirathip-k committed Oct 10, 2023
1 parent 882d245 commit 0b28361
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 38 deletions.
3 changes: 2 additions & 1 deletion alembic/versions/553d2c1ee85a_create_challenge_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def upgrade() -> None:
sa.Column("name", sa.String, nullable=False),
sa.Column("type", sa.String, nullable=False),
sa.Column("grade", sa.Integer, nullable=False),
sa.Column("score", sa.Float, nullable=False)
sa.Column("score", sa.Float, nullable=False),
sa.Column("goal", sa.Integer, nullable=False),
)

op.create_table(
Expand Down
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Challenge(Base):
type = Column(String, nullable=False)
grade = Column(Integer, nullable=False)
score = Column(Float, nullable=False)
goal = Column(Integer, nullable=False)
user_challenges = relationship(
"User_Challenge", back_populates="challenge")

Expand Down
4 changes: 1 addition & 3 deletions app/routers/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,7 @@ async def add_challenge_common(
Returns:
- dict: A dictionary containing details about the update status.
"""
print("in add challenge common")
user_id = current_user.user_id
print(user_id)

challenges = db.query(models.Challenge).filter(
models.Challenge.type == challenge_type).all()
Expand Down Expand Up @@ -376,7 +374,7 @@ async def add_challenge_common(
db.refresh(user_challenge)

# If the progress is 1, and score is not added, update score in Redis
if progress == 1.0 and not user_challenge.score_added:
if user_challenge.progress == 1.0 and not user_challenge.score_added:
# Use the score from the challenge
await update_score_in_redis(user_id, challenge.score, r, db)
user_challenge.score_added = True
Expand Down
3 changes: 3 additions & 0 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ class TrackRoomOut(BaseModel):
class Challenge(BaseModel):
name: str
type: str
goal: int
grade: int
score: int


class UserChallengeOut(BaseModel):
Expand Down
85 changes: 51 additions & 34 deletions data/challenges.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,120 +2,137 @@
{
"id": 1,
"type": "route_generation",
"name": "1 Route Generated",
"name": "Generate 1 Route",
"score": 1,
"grade": 1
"grade": 1,
"goal": 1
},
{
"id": 2,
"type": "route_generation",
"name": "5 Routes Generated",
"name": "Generate 5 Routes",
"score": 3,
"grade": 2
"grade": 2,
"goal": 5
},
{
"id": 3,
"type": "route_generation",
"name": "10 Routes Generated",
"name": "Generated 10 Routes",
"score": 5,
"grade": 3
"grade": 3,
"goal": 10
},
{
"id": 4,
"type": "favourited",
"name": "1 Favorited",
"name": "Favorite 1 Route",
"score": 1,
"grade": 1
"grade": 1,
"goal": 1
},
{
"id": 5,
"type": "favourited",
"name": "5 Favorited",
"name": "Favorite 5 Routes",
"score": 3,
"grade": 2
"grade": 2,
"goal": 5
},
{
"id": 6,
"type": "favourited",
"name": "10 Favorited",
"name": "Favorite 10 Routes",
"score": 5,
"grade": 3
"grade": 3,
"goal": 10
},
{
"id": 7,
"type": "shared",
"name": "1 Shared",
"name": "Shared 1 Route",
"score": 1,
"grade": 1
"grade": 1,
"goal": 1
},
{
"id": 8,
"type": "shared",
"name": "5 Shared",
"name": "Share 5 Routes",
"score": 3,
"grade": 2
"grade": 2,
"goal": 5
},
{
"id": 9,
"type": "shared",
"name": "10 Shared",
"name": "Share 10 Routes",
"score": 5,
"grade": 3
"grade": 3,
"goal": 10
},
{
"id": 10,
"type": "published",
"name": "1 Published",
"name": "Publish 1 Route",
"score": 1,
"grade": 1
"grade": 1,
"goal": 1
},
{
"id": 11,
"type": "published",
"name": "5 Published",
"name": "Publish 5 Routes",
"score": 3,
"grade": 2
"grade": 2,
"goal": 5
},
{
"id": 12,
"type": "published",
"name": "10 Published",
"name": "Publish 10 Routes",
"score": 5,
"grade": 3
"grade": 3,
"goal": 10
},
{
"id": 13,
"type": "read_tips",
"name": "1 Read",
"name": "Read 1 Tip",
"score": 1,
"grade": 1
"grade": 1,
"goal": 1
},
{
"id": 14,
"type": "read_tips",
"name": "5 Read",
"name": "Read 5 Tips",
"score": 3,
"grade": 2
"grade": 2,
"goal": 5
},
{
"id": 15,
"type": "read_tipes",
"name": "10 Read",
"name": "Read 10 Tips",
"score": 5,
"grade": 3
"grade": 3,
"goal": 10
},
{
"id": 16,
"type": "logged_in",
"name": "Logged In",
"name": "Daily Log In",
"score": 1,
"grade": 1
"grade": 1,
"goal": 1
},
{
"id": 17,
"type": "accessed_global_feed",
"name": "Accessed Global Feed",
"name": "Access Global Feed",
"score": 1,
"grade": 1
"grade": 1,
"goal": 1
}
]

0 comments on commit 0b28361

Please sign in to comment.