Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 13, 2024
1 parent ef560b7 commit 2f64c56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
4 changes: 4 additions & 0 deletions mondey_backend/src/mondey_backend/models/milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MilestoneGroup(SQLModel, table=True):
text: Mapped[dict[str, MilestoneGroupText]] = dict_relationship(key="lang_id")
milestones: Mapped[list[Milestone]] = back_populates("group")


class MilestoneGroupPublic(SQLModel):
id: int
text: dict[str, MilestoneGroupTextPublic] = {}
Expand Down Expand Up @@ -103,12 +104,14 @@ class Milestone(SQLModel, table=True):
text: Mapped[dict[str, MilestoneText]] = dict_relationship(key="lang_id")
images: Mapped[list[MilestoneImage]] = back_populates("milestone")


class MilestonePublic(SQLModel):
id: int
expected_age_months: int
text: dict[str, MilestoneTextPublic] = {}
images: list[MilestoneImagePublic] = []


class MilestoneAdmin(SQLModel):
id: int
group_id: int
Expand All @@ -117,6 +120,7 @@ class MilestoneAdmin(SQLModel):
text: dict[str, MilestoneText] = {}
images: list[MilestoneImage] = []


## MilestoneImage


Expand Down
31 changes: 15 additions & 16 deletions mondey_backend/src/mondey_backend/routers/milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def get_milestone(session: SessionDep, milestone_id: int):
"/milestone-groups/{child_id}", response_model=list[MilestoneGroupPublic]
)
def get_milestone_groups(
session: SessionDep, current_active_user: CurrentActiveUserDep,
child_id: int,
session: SessionDep,
current_active_user: CurrentActiveUserDep,
child_id: int,
):
delta_months = 6
child = get_db_child(session, current_active_user, child_id)
Expand All @@ -70,35 +71,33 @@ def get_milestone_groups(
)
).all()

# compute progress from milestone answers. While this is not
# the most efficient way, it is the least intrusive and concentrates
# compute progress from milestone answers. While this is not
# the most efficient way, it is the least intrusive and concentrates
# progress reporting in the least amount of code - this function and the
# MilestonAnswerPublic model.
answer_session = (
get_or_create_current_milestone_answer_session(
session, current_active_user, child_id
)
answer_session = get_or_create_current_milestone_answer_session(
session, current_active_user, child_id
)
# FIXME: this needs to be done better, as it contains a cumbersome
# type conversion that should be avoided.
# when fixing: -make sure pydantic is still as much in effect as possible
# FIXME: this needs to be done better, as it contains a cumbersome
# type conversion that should be avoided.
# when fixing: -make sure pydantic is still as much in effect as possible
# - check if we need it at all. certainly a nice thing
milestone_groups_public = []
for mgroup in milestone_groups:
for mgroup in milestone_groups:
p = 0.0
mgroup_public = MilestoneGroupPublic(
id=mgroup.id,
order=mgroup.order,
text=mgroup.text,
milestones=mgroup.milestones
milestones=mgroup.milestones,
)
for milestone in mgroup.milestones:
for milestone in mgroup.milestones:
answer = answer_session.answers.get(milestone.id)

if answer is not None and answer.answer > 0:
p += 1.0
p += 1.0

mgroup_public.progress = p / len(mgroup.milestones)
mgroup_public.progress = p / len(mgroup.milestones)
milestone_groups_public.append(mgroup_public)

return milestone_groups_public
Expand Down

0 comments on commit 2f64c56

Please sign in to comment.