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

Add Team Assessments #968

Merged
merged 159 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 152 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
e3a6fd2
Update assessment schema and add max_team_size as a required field
LuYiting0913 Jul 5, 2023
009045e
Update assessment schema and add max_team_size as a required field
LuYiting0913 Jul 5, 2023
539dcba
Add max team size to assessment controller payload
LuYiting0913 Jul 6, 2023
71ba4fb
Merge branch 'master' into branch-add-team-size
LuYiting0913 Jul 10, 2023
0644003
Update mix.exs
LuYiting0913 Jul 10, 2023
82fbece
Merge pull request #1 from SA-Teams-Assessment/branch-add-team-size
CheongYeeMing Jul 10, 2023
c8f943b
Create migrations for team assessments
CheongYeeMing Jul 11, 2023
83ccac9
Add Team Formation Models
CheongYeeMing Jul 17, 2023
9fd7bef
Fix line endings
LuYiting0913 Jul 17, 2023
995c56e
Fix line endings
LuYiting0913 Jul 17, 2023
73a4dd1
Merge pull request #2 from SA-Teams-Assessment/branch-fix-git-diff
CheongYeeMing Jul 17, 2023
186350f
Establish connection with Frontend
CheongYeeMing Jul 19, 2023
54f1a48
Generate seeds for team and team_member
LuYiting0913 Jul 20, 2023
6a641d2
Fix line endings
LuYiting0913 Jul 20, 2023
8e1dfd8
Add API call to retrieve team formation students
CheongYeeMing Jul 21, 2023
5c74db8
Add Validation for Create Team
CheongYeeMing Jul 22, 2023
925cb87
Update response for Create and Delete Team API
CheongYeeMing Jul 22, 2023
1b47bc1
Add Update Teams API call
CheongYeeMing Jul 22, 2023
50744dc
Modify helper function
CheongYeeMing Jul 22, 2023
b930226
Update seeds
LuYiting0913 Jul 23, 2023
1188171
Modify TeamMember migration
CheongYeeMing Jul 24, 2023
55dc75d
Update AlterSubmissionsTable migration
CheongYeeMing Jul 26, 2023
7252d4d
Add API to retrieve TeamFormationOverview for students
CheongYeeMing Aug 4, 2023
223c686
Add Delete Team
CheongYeeMing Aug 4, 2023
2d35512
Refactor SQL chunk to fetch both Team and Individual submissions
CheongYeeMing Aug 4, 2023
f1443a8
Add retrieve Team Submission
CheongYeeMing Aug 4, 2023
e1c7da2
Add create empty submission for Team submission
CheongYeeMing Aug 4, 2023
e5cb4ae
Add cascade delete answer when Team is deleted
CheongYeeMing Aug 4, 2023
016dc1d
Update XOR validation in Submission
CheongYeeMing Aug 4, 2023
613eebd
Remove bulk_upload API call and doc
CheongYeeMing Aug 4, 2023
71ece24
Add retrieve of team submission answers
CheongYeeMing Aug 4, 2023
83534b4
Add unsubmit for team submission
CheongYeeMing Aug 4, 2023
bc8a49d
Add retrieval of team submissions for grading
CheongYeeMing Aug 4, 2023
9c95f15
Add handle team submission notifications
CheongYeeMing Aug 4, 2023
2e9668f
Remove io inspect statement
CheongYeeMing Aug 4, 2023
79de1ff
Remove io inspect statement
CheongYeeMing Aug 4, 2023
7e1bc84
Merge branch 'master' into add-team-formation
CheongYeeMing Aug 4, 2023
4f43c98
Merge branch 'add-team-formation' of https://github.com/SA-Teams-Asse…
CheongYeeMing Aug 4, 2023
da2a782
Revert seeds
CheongYeeMing Aug 5, 2023
bf9e4db
Revert seeds
CheongYeeMing Aug 5, 2023
ac88a43
Merge branch 'add-team-formation' of https://github.com/SA-Teams-Asse…
CheongYeeMing Aug 5, 2023
7f908f6
Revert seeds
CheongYeeMing Aug 5, 2023
5e0b3b4
Merge pull request #3 from SA-Teams-Assessment/add-team-formation
CheongYeeMing Aug 5, 2023
8fcaaa3
Add last_modified_at field for Answer
CheongYeeMing Aug 5, 2023
e7dd797
Add Save-Safe
CheongYeeMing Aug 14, 2023
47d446f
Add documentation for models
CheongYeeMing Aug 21, 2023
fec3e70
Minor refactoring of Teams
CheongYeeMing Aug 21, 2023
e1a20d0
Add Swagger Documentation for AdminTeamsController
CheongYeeMing Aug 26, 2023
a811fd7
Write Function Documentation for Teams
CheongYeeMing Aug 26, 2023
0b523c7
Add documentation and minor refactoring
CheongYeeMing Aug 26, 2023
9defe75
Minor changes to existing tests
CheongYeeMing Aug 26, 2023
80b83a5
Cascade delete notification for submission
CheongYeeMing Dec 12, 2023
9d0c1ab
Update error message for team creation
CheongYeeMing Dec 12, 2023
6a957e7
Update assessments Team retrieval
CheongYeeMing Dec 12, 2023
0661252
Add cascading delete for notifications
Dec 13, 2023
8f7684c
Resolve merge conflict
Dec 13, 2023
4685c76
Fix Team Delete Bug
CheongYeeMing Dec 13, 2023
295254c
Fix save answer bug when no team
CheongYeeMing Dec 13, 2023
1ea3252
Merge pull request #6 from SA-Teams-Assessment/yeeming
CheongYeeMing Dec 13, 2023
12512cb
Raise exception when mass team imports violates constraints
Dec 14, 2023
75d25c6
remove test file
LuYiting0913 Dec 14, 2023
f7259cd
Merge pull request #7 from SA-Teams-Assessment/yiting
CheongYeeMing Dec 14, 2023
16fd4ff
Fix bug of importing duplicate students through excel
LuYiting0913 Dec 15, 2023
1e66007
Refactor default max team size to 1
LuYiting0913 Dec 15, 2023
c7c3572
Check size of the team before insertion
Dec 15, 2023
81c608b
Fix format
LuYiting0913 Dec 15, 2023
9b01cf7
Fix unsubmit handle notifications bug
CheongYeeMing Dec 18, 2023
99a21f3
Merge pull request #9 from SA-Teams-Assessment/yeeming
CheongYeeMing Dec 18, 2023
7953f62
Fix end of line issue
LuYiting0913 Dec 19, 2023
ac1ca18
Fix end of line issue
LuYiting0913 Dec 19, 2023
3444aca
Fix end of line issue
LuYiting0913 Dec 19, 2023
5efddde
Raise exception when some of the students in mass team import are not…
LuYiting0913 Dec 19, 2023
408e348
Update docs
LuYiting0913 Dec 19, 2023
6454063
Fix Submission Grading Bug
CheongYeeMing Dec 19, 2023
faf64bd
Merge pull request #10 from SA-Teams-Assessment/yeeming
CheongYeeMing Dec 19, 2023
f83914c
Update docs
LuYiting0913 Dec 19, 2023
2d063c9
Fix team deletion bug when there is a submitted assessment
LuYiting0913 Dec 21, 2023
dd73093
Send proper error msg to frontend when delete team fails
LuYiting0913 Dec 22, 2023
416b82b
Merge conflict
LuYiting0913 Jan 4, 2024
eec1f2b
Merge pull request #8 from SA-Teams-Assessment/yiting
LuYiting0913 Jan 4, 2024
a9e14a9
Resolve merge conflict from upstream
CheongYeeMing Jan 4, 2024
07685ae
Merge conflict
CheongYeeMing Jan 4, 2024
e8be350
Retrieve Team Submission Details
CheongYeeMing Jan 8, 2024
dd41360
Fix failed test cases
LuYiting0913 Jan 11, 2024
93d68c5
Add test cases
Jan 12, 2024
b154ab7
Team Member Factory
CheongYeeMing Jan 15, 2024
4eb59da
add team tests
LuYiting0913 Jan 15, 2024
0f1b347
Modify Submission Factory to include Team Submission
CheongYeeMing Jan 15, 2024
58f86af
Write test for Team Members
CheongYeeMing Jan 15, 2024
7c4aa70
Increase COV for Notification Test
CheongYeeMing Jan 15, 2024
bd627b5
Prepend unused variable with underscore
CheongYeeMing Jan 15, 2024
30718dc
Answer View Test
CheongYeeMing Jan 15, 2024
2571136
Team View Test
CheongYeeMing Jan 15, 2024
b0c0294
Update Admin Teams Controller
CheongYeeMing Jan 15, 2024
4da966e
Admin Teams Controller Test
CheongYeeMing Jan 15, 2024
bc26472
Merge pull request #11 from SA-Teams-Assessment/big-merge
CheongYeeMing Jan 16, 2024
893c226
Clean up test cases
LuYiting0913 Jan 17, 2024
97f156b
Improve test coverage for teams
LuYiting0913 Jan 18, 2024
88a1e2f
Improve test coverage for team controller
LuYiting0913 Jan 18, 2024
7284d2f
Improve submission test coverage
LuYiting0913 Jan 18, 2024
a011725
Remove unrecheable code
CheongYeeMing Jan 18, 2024
197e7f8
Empty Guardian Test
CheongYeeMing Jan 18, 2024
52f6792
Answer Controller Test
CheongYeeMing Jan 18, 2024
b4b9f5a
Notification Test
CheongYeeMing Jan 18, 2024
ecc2fe0
improve test coverage for assessments
LuYiting0913 Jan 19, 2024
66d605b
Merge branch 'big-merge' of github.com:SA-Teams-Assessment/backend in…
LuYiting0913 Jan 19, 2024
230eb86
Improve test coverage for assessments
LuYiting0913 Jan 19, 2024
25b6d6c
Clean up test cases
LuYiting0913 Jan 19, 2024
d6ca364
Update Swagger Documentation
CheongYeeMing Jan 20, 2024
4bb9a2e
Merge pull request #12 from SA-Teams-Assessment/big-merge
CheongYeeMing Jan 20, 2024
317c621
Modify AddMaxTeamSizeToAssessments migration file
CheongYeeMing Jan 20, 2024
82ff5f1
Remove unused variable in notification test
CheongYeeMing Jan 20, 2024
d642ef6
Merge pull request #13 from SA-Teams-Assessment/big-merge
CheongYeeMing Jan 20, 2024
2620c1f
Merge branch 'master' of https://github.com/source-academy/backend in…
RichDom2185 Jan 20, 2024
7d31d8f
Fix format
RichDom2185 Jan 20, 2024
f64cd76
Fix credo errors
RichDom2185 Jan 20, 2024
ef46487
Fix failing tests
RichDom2185 Jan 20, 2024
7852338
Remove unused variables
CheongYeeMing Jan 20, 2024
a33b1eb
Fix failing tests
CheongYeeMing Jan 20, 2024
af335f3
Remove IO.inspect
CheongYeeMing Jan 20, 2024
4219869
Fix dialyzer CI
CheongYeeMing Jan 20, 2024
4fb8b25
Run mix format
CheongYeeMing Jan 20, 2024
c6312c4
Fix format
RichDom2185 Jan 20, 2024
2f2ebd2
Simplify code
RichDom2185 Jan 22, 2024
059cf74
Revert file permission changes
RichDom2185 Jan 22, 2024
168a75c
Remove commented code
RichDom2185 Jan 22, 2024
b61e9cf
Revert status code changes
RichDom2185 Jan 22, 2024
37944c7
Fix tests following status code change revert
RichDom2185 Jan 22, 2024
44a020d
Remove redundant conversion
CheongYeeMing Jan 22, 2024
151a367
Add comment to notifications
CheongYeeMing Jan 22, 2024
65d8367
Add validation for max team size
CheongYeeMing Jan 22, 2024
fbf3b06
Update assessment changeset testcase
CheongYeeMing Jan 22, 2024
d9e0372
Abstract out find teams
CheongYeeMing Jan 22, 2024
a775413
Remove repeated code
CheongYeeMing Jan 22, 2024
300dcd2
Abstraction of XOR logic
CheongYeeMing Jan 22, 2024
e5bb030
Fix format
RichDom2185 Jan 23, 2024
21f672a
Merge branch 'master' of https://github.com/source-academy/backend in…
RichDom2185 Jan 23, 2024
ce1c14f
Fix failing tests
CheongYeeMing Jan 23, 2024
4ee4e16
Run format
RichDom2185 Jan 24, 2024
f30934b
Merge branch 'master' into master
RichDom2185 Jan 28, 2024
0e3d0d9
Merge branch 'master' into master
RichDom2185 Jan 30, 2024
08aff07
Merge branch 'master' into master
RichDom2185 Feb 5, 2024
65293d5
Merge branch 'master' into master
RichDom2185 Feb 13, 2024
bac7906
Merge branch 'master' of https://github.com/source-academy/backend in…
RichDom2185 Feb 22, 2024
a992f0a
Fix format
RichDom2185 Feb 22, 2024
b308228
Redate migrations
RichDom2185 Feb 22, 2024
bded013
Merge branch 'master' of https://github.com/source-academy/backend in…
RichDom2185 Feb 24, 2024
a70477c
Fix format post-merge
RichDom2185 Feb 24, 2024
a8ce4b0
Merge branch 'master' into master
RichDom2185 Mar 1, 2024
a67c794
Merge branch 'master' into master
RichDom2185 Mar 4, 2024
c81537c
Merge branch 'master' into master
RichDom2185 Mar 10, 2024
14d39da
Remove typo
RichDom2185 Mar 16, 2024
71bd6b9
Merge branch 'master' into master
RichDom2185 Mar 21, 2024
5c630de
Revert dependency downgrades
RichDom2185 Mar 21, 2024
ba480ef
Merge branch 'master' into master
RichDom2185 Mar 21, 2024
4bd6544
Revert incorrect merge conflict resolution
YaleChen299 Jun 30, 2023
37ab192
Fix tests
RichDom2185 Mar 21, 2024
434d6d6
Update status code for not found
RichDom2185 Mar 21, 2024
64f5cbc
Fix test for not found status code
RichDom2185 Mar 21, 2024
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
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
{Credo.Check.Readability.SpaceAfterCommas},
{Credo.Check.Refactor.DoubleBooleanNegation},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.CyclomaticComplexity},
{Credo.Check.Refactor.CyclomaticComplexity, max_complexity: 10},
{Credo.Check.Refactor.FunctionArity},
{Credo.Check.Refactor.LongQuoteBlocks},
{Credo.Check.Refactor.MatchInCondition},
Expand Down
2 changes: 1 addition & 1 deletion .iex.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ecto.Query
alias Cadet.Repo
alias Cadet.Accounts.User
alias Cadet.Accounts.{User, Team, TeamMember}
alias Cadet.Assessments.{Answer, Assessment, Question, Submission}
alias Cadet.Courses.Group
76 changes: 64 additions & 12 deletions lib/cadet/accounts/notifications.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Cadet.Accounts.Notifications do
import Ecto.Query

alias Cadet.Repo
alias Cadet.Accounts.{Notification, CourseRegistration, CourseRegistration}
alias Cadet.Accounts.{Notification, CourseRegistration, CourseRegistration, Team, TeamMember}
alias Cadet.Assessments.Submission
alias Ecto.Multi

Expand Down Expand Up @@ -169,17 +169,47 @@ defmodule Cadet.Accounts.Notifications do
@spec write_notification_when_graded(integer(), any()) ::
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
def write_notification_when_graded(submission_id, type) when type in [:graded, :autograded] do
submission =
Submission
|> Repo.get_by(id: submission_id)
case Repo.get(Submission, submission_id) do
nil ->
{:error, %Ecto.Changeset{}}

write(%{
type: type,
read: false,
role: :student,
course_reg_id: submission.student_id,
assessment_id: submission.assessment_id
})
submission ->
case submission.student_id do
nil ->
team = Repo.get(Team, submission.team_id)

query =
from(t in Team,
join: tm in TeamMember,
on: t.id == tm.team_id,
join: cr in CourseRegistration,
on: tm.student_id == cr.id,
where: t.id == ^team.id,
select: cr.id
)

team_members = Repo.all(query)

Enum.each(team_members, fn tm_id ->
write(%{
type: type,
read: false,
role: :student,
course_reg_id: tm_id,
assessment_id: submission.assessment_id
})
end)

student_id ->
write(%{
type: type,
read: false,
role: :student,
course_reg_id: student_id,
assessment_id: submission.assessment_id
})
end
end
end

@doc """
Expand Down Expand Up @@ -223,7 +253,29 @@ defmodule Cadet.Accounts.Notifications do
@spec write_notification_when_student_submits(Submission.t()) ::
{:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
def write_notification_when_student_submits(submission = %Submission{}) do
avenger_id = get_avenger_id_of(submission.student_id)
id =
case submission.student_id do
nil ->
team_id = submission.team_id

team =
Repo.one(
from(t in Team,
where: t.id == ^team_id,
preload: [:team_members]
)
)

# Does not matter if team members have different Avengers
# Just require one of them to be notified of the submission
s_id = team.team_members |> hd() |> Map.get(:student_id)
CheongYeeMing marked this conversation as resolved.
Show resolved Hide resolved
s_id

_ ->
submission.student_id
end

avenger_id = get_avenger_id_of(id)

if is_nil(avenger_id) do
{:ok, nil}
Expand Down
45 changes: 45 additions & 0 deletions lib/cadet/accounts/team.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
defmodule Cadet.Accounts.Team do
@moduledoc """
This module defines the Ecto schema and changeset for teams in the Cadet.Accounts context.
Teams represent groups of students collaborating on an assessment within a course.
"""

use Cadet, :model

alias Cadet.Accounts.TeamMember
alias Cadet.Assessments.{Assessment, Submission}

@doc """
Ecto schema definition for teams.
This schema represents a group of students collaborating on a specific assessment within a course.
Fields:
- `assessment`: A reference to the assessment associated with the team.
- `submission`: A reference to the team's submission for the assessment.
- `team_members`: A list of team members associated with the team.
"""
schema "teams" do
belongs_to(:assessment, Assessment)
has_one(:submission, Submission, on_delete: :delete_all)
has_many(:team_members, TeamMember, on_delete: :delete_all)

timestamps()
end

@required_fields ~w(assessment_id)a

@doc """
Builds an Ecto changeset for a team.
This function is used to create or update a team record based on the provided attributes.
Args:
- `team`: The existing team struct.
- `attrs`: The attributes to be cast and validated for the changeset.
Returns:
A changeset struct with cast and validated attributes.
"""
def changeset(team, attrs) do
team
|> cast(attrs, @required_fields)
|> validate_required(@required_fields)
|> foreign_key_constraint(:assessment_id)
end
end
45 changes: 45 additions & 0 deletions lib/cadet/accounts/team_member.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
defmodule Cadet.Accounts.TeamMember do
@moduledoc """
This module defines the Ecto schema and changeset for team members in the Cadet.Accounts context.
Team members represent the association between a student and a team within a course.
"""

use Ecto.Schema

import Ecto.Changeset

alias Cadet.Accounts.{CourseRegistration, Team}

@doc """
Ecto schema definition for team members.
This schema represents the relationship between a student and a team within a course.
Fields:
- `student`: A reference to the student's course registration.
- `team`: A reference to the team associated with the student.
"""
schema "team_members" do
belongs_to(:student, CourseRegistration)
belongs_to(:team, Team)

timestamps()
end

@required_fields ~w(student_id team_id)a

@doc """
Builds an Ecto changeset for a team member.
This function is used to create or update a team member record based on the provided attributes.
Args:
- `team_member`: The existing team member struct.
- `attrs`: The attributes to be cast and validated for the changeset.
Returns:
A changeset struct with cast and validated attributes.
"""
def changeset(team_member, attrs) do
team_member
|> cast(attrs, @required_fields)
|> validate_required(@required_fields)
|> foreign_key_constraint(:team_id)
|> foreign_key_constraint(:student_id)
end
end
Loading
Loading