-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Question and Assessment * Added functionality for grading * Added assessments functionality * Fixed typo * Restructured assessments * Added assessments context * Added controllers * Delete duplicate file * Changes to suit convention * Fixed stuff * Ran mix commands * Fix changes * Removed role validation * Removed all compile time errors * Fixed consistency issues * Refactored * Conversion to spaces * More functionality for questions * Adding tests * Refactored * Added few tests for missions * Few more tests to go * Added more tests * Delete useless migration * Delete useless migration 2 * Added submission test * Added question tests and switched controllers to new branch * Added answers test * Remove unneccesary stuff * Formatting * Fixed compile error * Make changes according to review * Fixes * Added tests to question and answer * Added question types * Various fixes * Changes according to question types * Assessments context * Fixes * Removed invalid test * Fix some tests * Assessments housecleaning (#51) * Improve contexts - Allow using multiple contexts - Cleaned up some imports in /lib/cadet/accessments * Raise exception when using context with invalid arguments * More housecleaning * Add comment to cadet context * Fix credo * Remove duplicate blank line * Remove pre-commit * Refactor json and rename Mission to Assessment * Fix submission model * Use cadet context * Fix some json tests * Fix tests and logic error * Remove untested method and add one test * Remove useless import * Add test * Fix according to code review * Change to pipeline syntax * Reorganise file
- Loading branch information
1 parent
de7d5b9
commit cb56954
Showing
37 changed files
with
933 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ erl_crash.dump | |
.terraform | ||
*.tfstate | ||
*.backup | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule Cadet.Assessments.Answer do | ||
@moduledoc """ | ||
Answers model contains domain logic for answers management for | ||
programming and multiple choice questions. | ||
""" | ||
use Cadet, :model | ||
|
||
alias Cadet.Assessments.ProblemType | ||
alias Cadet.Assessments.Submission | ||
alias Cadet.Assessments.Question | ||
|
||
schema "answers" do | ||
field(:marks, :float, default: 0.0) | ||
field(:answer, :map) | ||
field(:type, ProblemType) | ||
field(:raw_answer, :string, virtual: true) | ||
belongs_to(:submission, Submission) | ||
belongs_to(:question, Question) | ||
timestamps() | ||
end | ||
|
||
@required_fields ~w(answer type)a | ||
@optional_fields ~w(marks raw_answer)a | ||
|
||
def changeset(answer, params) do | ||
answer | ||
|> cast(params, @required_fields ++ @optional_fields) | ||
|> validate_required(@required_fields) | ||
|> validate_number(:marks, greater_than_or_equal_to: 0.0) | ||
|> put_json(:answer, :raw_answer) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
defmodule Cadet.Assessments.Assessment do | ||
@moduledoc """ | ||
The Assessment entity stores metadata of a students' assessment | ||
(mission, sidequest, path, and contest) | ||
""" | ||
use Cadet, :model | ||
use Arc.Ecto.Schema | ||
|
||
alias Cadet.Assessments.Category | ||
alias Cadet.Assessments.Image | ||
alias Cadet.Assessments.Question | ||
alias Cadet.Assessments.Upload | ||
|
||
schema "assessments" do | ||
field(:title, :string) | ||
field(:is_published, :boolean, default: false) | ||
field(:category, Category) | ||
field(:summary_short, :string) | ||
field(:summary_long, :string) | ||
field(:open_at, Timex.Ecto.DateTime) | ||
field(:close_at, Timex.Ecto.DateTime) | ||
field(:max_xp, :integer, default: 0) | ||
field(:cover_picture, Image.Type) | ||
field(:mission_pdf, Upload.Type) | ||
field(:order, :string, default: "") | ||
has_many(:questions, Question, on_delete: :delete_all) | ||
timestamps() | ||
end | ||
|
||
@required_fields ~w(category title open_at close_at max_xp)a | ||
@optional_fields ~w(summary_short summary_long is_published max_xp)a | ||
@optional_file_fields ~w(cover_picture mission_pdf)a | ||
|
||
def changeset(mission, params) do | ||
params = | ||
params | ||
|> convert_date(:open_at) | ||
|> convert_date(:close_at) | ||
|
||
mission | ||
|> cast(params, @required_fields ++ @optional_fields) | ||
|> validate_required(@required_fields) | ||
|> validate_number(:max_xp, greater_than_or_equal_to: 0) | ||
|> cast_attachments(params, @optional_file_fields) | ||
|> validate_open_close_date | ||
end | ||
|
||
defp validate_open_close_date(changeset) do | ||
validate_change(changeset, :open_at, fn :open_at, open_at -> | ||
if Timex.before?(open_at, get_field(changeset, :close_at)) do | ||
[] | ||
else | ||
[open_at: "Open date must be before close date"] | ||
end | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import EctoEnum | ||
|
||
defenum(Cadet.Assessments.ProblemType, :type, [ | ||
:programming, | ||
:multiple_choice | ||
]) |
Oops, something went wrong.