Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
jirathip-k committed Oct 10, 2023
2 parents 5470c85 + cc33ecb commit e08f89a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions alembic/versions/553d2c1ee85a_create_challenge_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def upgrade() -> None:
"challenges",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("name", sa.String, nullable=False),
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),
Expand Down
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class Challenge(Base):

id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
name_ = Column(String, nullable=False)
type = Column(String, nullable=False)
grade = Column(Integer, nullable=False)
score = Column(Float, nullable=False)
Expand Down
18 changes: 17 additions & 1 deletion app/schemas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, ValidationError, field_validator, constr, conint
from pydantic import BaseModel, ValidationError, field_validator, constr, conint, root_validator
from datetime import datetime
from .models import Route
from typing import Optional
Expand Down Expand Up @@ -260,6 +260,7 @@ class Challenge(BaseModel):
goal: int
grade: int
score: int
name_: str


class UserChallengeOut(BaseModel):
Expand All @@ -268,6 +269,21 @@ class UserChallengeOut(BaseModel):
month: int
day: int
progress: float
current_progress: int
progress_name: str

@root_validator(pre=True)
@classmethod
def current_progress(cls, values):
progress = values.progress
goal = values.challenge.goal
name_ = values.challenge.name_

current = int(progress * goal)
values.current_progress = current
values.progress_name = name_.replace("_", f"{current}/{goal}")

return values


class RouteGenerationChallenge(BaseModel):
Expand Down
29 changes: 18 additions & 11 deletions data/challenges.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"id": 1,
"type": "route_generation",
"name": "Generate 1 Route",
"name_": "Generated _ Route",
"score": 1,
"grade": 1,
"goal": 1
Expand All @@ -11,14 +12,16 @@
"id": 2,
"type": "route_generation",
"name": "Generate 5 Routes",
"name_": "Generated _ Routes",
"score": 3,
"grade": 2,
"goal": 5
},
{
"id": 3,
"id": 2,
"type": "route_generation",
"name": "Generate 10 Routes",
"name": "Generate 5 Routes",
"name_": "Generated _ Routes",
"score": 5,
"grade": 3,
"goal": 10
Expand All @@ -27,6 +30,7 @@
"id": 4,
"type": "favourited",
"name": "Favorite 1 Route",
"name_": "Favorited _ Route",
"score": 1,
"grade": 1,
"goal": 1
Expand All @@ -35,6 +39,7 @@
"id": 5,
"type": "favourited",
"name": "Favorite 5 Routes",
"name_": "Favorited _ Routes",
"score": 3,
"grade": 2,
"goal": 5
Expand All @@ -43,22 +48,15 @@
"id": 6,
"type": "favourited",
"name": "Favorite 10 Routes",
"name_": "Favorited _ Routes",
"score": 5,
"grade": 3,
"goal": 10
},
{
"id": 7,
"type": "shared",
"name": "Share 1 Route",
"score": 1,
"grade": 1,
"goal": 1
},
{
"id": 8,
"type": "shared",
"name": "Share 5 Routes",
"name": "Share 1 Route","name_": "Shared _ Routes",
"score": 3,
"grade": 2,
"goal": 5
Expand All @@ -67,6 +65,7 @@
"id": 9,
"type": "shared",
"name": "Share 10 Routes",
"name_": "Shared _ Routes",
"score": 5,
"grade": 3,
"goal": 10
Expand All @@ -75,6 +74,7 @@
"id": 10,
"type": "published",
"name": "Publish 1 Route",
"name_": "Published _ Routes",
"score": 1,
"grade": 1,
"goal": 1
Expand All @@ -83,6 +83,7 @@
"id": 11,
"type": "published",
"name": "Publish 5 Routes",
"name_": "Published _ Routes",
"score": 3,
"grade": 2,
"goal": 5
Expand All @@ -91,6 +92,7 @@
"id": 12,
"type": "published",
"name": "Publish 10 Routes",
"name_": "Published _ Routes",
"score": 5,
"grade": 3,
"goal": 10
Expand All @@ -99,6 +101,7 @@
"id": 13,
"type": "read_tips",
"name": "Read 1 Tip",
"name_": "Read _ Tip",
"score": 1,
"grade": 1,
"goal": 1
Expand All @@ -107,6 +110,7 @@
"id": 14,
"type": "read_tips",
"name": "Read 5 Tips",
"name_": "Read _ Tips",
"score": 3,
"grade": 2,
"goal": 5
Expand All @@ -115,6 +119,7 @@
"id": 15,
"type": "read_tipes",
"name": "Read 10 Tips",
"name_": "Read _ Tips",
"score": 5,
"grade": 3,
"goal": 10
Expand All @@ -123,6 +128,7 @@
"id": 16,
"type": "logged_in",
"name": "Daily Log In",
"name_": "Logged in Today",
"score": 1,
"grade": 1,
"goal": 1
Expand All @@ -131,6 +137,7 @@
"id": 17,
"type": "accessed_global_feed",
"name": "Access Global Feed",
"name_": "Accessed Global Feed Today",
"score": 1,
"grade": 1,
"goal": 1
Expand Down

0 comments on commit e08f89a

Please sign in to comment.