[go: nahoru, domu]

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 DB crash due to timeout #1031

Merged
merged 9 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move views under AdminGradingView
  • Loading branch information
RichDom2185 committed Nov 6, 2023
commit ab9ac011b1f7eae4fae5ca53fe68ddc9a859138b
88 changes: 88 additions & 0 deletions lib/cadet_web/admin_views/admin_grading_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,94 @@ defmodule CadetWeb.AdminGradingView do
render_many(answers, CadetWeb.AdminGradingView, "grading_info.json", as: :answer)
end

def render("gradingsummaries.json", %{
users: users,
assessments: assessments,
submissions: submissions
}) do
for submission <- submissions do
user = users |> Enum.find(&(&1.id == submission.student_id))
assessment = assessments |> Enum.find(&(&1.id == submission.assessment_id))

render(
CadetWeb.AdminGradingView,
"gradingsummary.json",
%{
user: user,
assessment: assessment,
submission: submission,
unsubmitter:
case submission.unsubmitted_by_id do
nil -> nil
_ -> users |> Enum.find(&(&1.id == submission.unsubmitted_by_id))
end
}
)
end
end

def render("gradingsummary.json", %{
user: user,
assessment: a,
submission: s,
unsubmitter: unsubmitter
}) do
s
|> transform_map_for_view(%{
id: :id,
status: :status,
unsubmittedAt: :unsubmitted_at,
xp: :xp,
xpAdjustment: :xp_adjustment,
xpBonus: :xp_bonus,
gradedCount:
&case &1.graded_count do
nil -> 0
x -> x
end
})
|> Map.merge(%{
assessment:
render_one(a, CadetWeb.AdminGradingView, "gradingsummaryassessment.json", as: :assessment),
student: render_one(user, CadetWeb.AdminGradingView, "gradingsummaryuser.json", as: :cr),
unsubmittedBy:
case unsubmitter do
nil -> nil
cr -> transform_map_for_view(cr, %{id: :id, name: & &1.user.name})
end
})
end

def render("gradingsummaryassessment.json", %{assessment: a}) do
%{
id: a.id,
title: a.title,
assessmentNumber: a.number,
isManuallyGraded: a.config.is_manually_graded,
type: a.config.type,
maxXp: a.questions |> Enum.map(& &1.max_xp) |> Enum.sum(),
questionCount: a.questions |> Enum.count()
}
end

def render("gradingsummaryuser.json", %{cr: cr}) do
%{
id: cr.id,
name: cr.user.name,
username: cr.user.username,
groupName:
case cr.group do
nil -> nil
_ -> cr.group.name
end,
groupLeaderId:
case cr.group do
nil -> nil
_ -> cr.group.leader_id
end
}
end

def render("grading_info.json", %{answer: answer}) do
transform_map_for_view(answer, %{
student:
Expand Down
88 changes: 0 additions & 88 deletions lib/cadet_web/views/assessments_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,94 +8,6 @@ defmodule CadetWeb.AssessmentsView do
render_many(assessments, CadetWeb.AssessmentsView, "overview.json", as: :assessment)
end

def render("gradingsummaries.json", %{
users: users,
assessments: assessments,
submissions: submissions
}) do
for submission <- submissions do
user = users |> Enum.find(&(&1.id == submission.student_id))
assessment = assessments |> Enum.find(&(&1.id == submission.assessment_id))

render(
CadetWeb.AssessmentsView,
"gradingsummary.json",
%{
user: user,
assessment: assessment,
submission: submission,
unsubmitter:
case submission.unsubmitted_by_id do
nil -> nil
_ -> users |> Enum.find(&(&1.id == submission.unsubmitted_by_id))
end
}
)
end
end

def render("gradingsummary.json", %{
user: user,
assessment: a,
submission: s,
unsubmitter: unsubmitter
}) do
s
|> transform_map_for_view(%{
id: :id,
status: :status,
unsubmittedAt: :unsubmitted_at,
xp: :xp,
xpAdjustment: :xp_adjustment,
xpBonus: :xp_bonus,
gradedCount:
&case &1.graded_count do
nil -> 0
x -> x
end
})
|> Map.merge(%{
assessment:
render_one(a, CadetWeb.AssessmentsView, "gradingsummaryassessment.json", as: :assessment),
student: render_one(user, CadetWeb.AssessmentsView, "gradingsummaryuser.json", as: :cr),
unsubmittedBy:
case unsubmitter do
nil -> nil
cr -> transform_map_for_view(cr, %{id: :id, name: & &1.user.name})
end
})
end

def render("gradingsummaryassessment.json", %{assessment: a}) do
%{
id: a.id,
title: a.title,
assessmentNumber: a.number,
isManuallyGraded: a.config.is_manually_graded,
type: a.config.type,
maxXp: a.questions |> Enum.map(& &1.max_xp) |> Enum.sum(),
questionCount: a.questions |> Enum.count()
}
end

def render("gradingsummaryuser.json", %{cr: cr}) do
%{
id: cr.id,
name: cr.user.name,
username: cr.user.username,
groupName:
case cr.group do
nil -> nil
_ -> cr.group.name
end,
groupLeaderId:
case cr.group do
nil -> nil
_ -> cr.group.leader_id
end
}
end

def render("overview.json", %{assessment: assessment}) do
transform_map_for_view(assessment, %{
id: :id,
Expand Down