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

Assessments #34

Merged
merged 69 commits into from
Jun 24, 2018
Merged

Assessments #34

merged 69 commits into from
Jun 24, 2018

Conversation

sreycodes
Copy link
Contributor

@sreycodes sreycodes commented May 20, 2018

Fixes #26 #28

@indocomsoft indocomsoft added this to To do in Sprint 1 via automation May 20, 2018
@indocomsoft indocomsoft added this to the Sprint 1 milestone May 20, 2018
@indocomsoft indocomsoft moved this from To do to In Progress in Sprint 1 May 20, 2018
@sreycodes sreycodes self-assigned this May 20, 2018
@@ -0,0 +1,5 @@
import EctoEnum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a duplicate file, should be located in lib/cadet/assessments/ instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump

@@ -0,0 +1,29 @@
defmodule Cadet.Assessments.Assessment do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need assessment entity since all this does is has_one :mission, Mission, is redundant.

@indocomsoft indocomsoft moved this from In Progress to Under Review in Sprint 1 May 23, 2018
@indocomsoft indocomsoft moved this from Under Review to In Progress in Sprint 1 May 23, 2018
Copy link
Member

@indocomsoft indocomsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I added some more comments.

field :title, :string
field :display_order, :integer
field :weight, :integer
field :question_json, :map
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the convention in source-academy, I think the field name should be :question

field :weight, :integer
field :question_json, :map
field :type, ProblemType
field :raw_json, :string, virtual: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And similarly this shuld be :raw_question

|> put_json
end

defp put_json(changeset) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this should be put_question


schema "answers" do
field :marks, :float, default: 0.0
field :answer_json, :map
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

field :marks, :float, default: 0.0
field :answer_json, :map
field :type, ProblemType
field :raw_json, :string, virtual: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

end

@required_fields ~w(order category title open_at close_at)a
@optional_fields ~w(summary_short summary_long)
@required_fields ~w(name order category title open_at close_at library)a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to remove from here too

@required_fields ~w(order category title open_at close_at)a
@optional_fields ~w(summary_short summary_long)
@required_fields ~w(name order category title open_at close_at library)a
@optional_fields ~w(summary_short summary_long is_published max_xp priority raw_library)a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

@@ -0,0 +1,5 @@
import EctoEnum

defenum Cadet.Assessments.ProblemType, :type, [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency The enum should be named QuestionType since it is the type of Question

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum must be used for question and answer I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

end

def validate_role(changeset, user, role) do
validate_change(changeset, user, fn _, user ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fn ^user, user although I think you may want to reconsider the variable names

@@ -0,0 +1,5 @@
import EctoEnum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump

Copy link
Member

@indocomsoft indocomsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do plan out with swagger first before writing your controller, I think that way the code we produce will be of higher quality. Also as much as possible run mix format, mix test and mix credo and fix any problem before pushing. Generally a good idea


alias Cadet.Assessments

@tabs_map %{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have tabs?

@@ -0,0 +1,77 @@
defmodule CadetWeb.AssessmentController do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write swagger specification so I can review your code better :)

Assessments.update_question(params["id"], params["question"])
end

def delete(conn, %{"mission_id" => mission_id, "id" => id}) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclosed def

@coveralls
Copy link

coveralls commented May 26, 2018

Pull Request Test Coverage Report for Build 486

  • 74 of 75 (98.67%) changed or added relevant lines in 11 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+3.3%) to 97.818%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/cadet/assessments/submission.ex 4 5 80.0%
Totals Coverage Status
Change from base Build 444: 3.3%
Covered Lines: 269
Relevant Lines: 275

💛 - Coveralls

tuesmiddt and others added 10 commits June 18, 2018 21:33
* 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
@indocomsoft
Copy link
Member

@tuesmiddt I feel this should be ready to merge, but since I made the edits, I think it's good that you have a lookthrough. If everything is alright, I'll merge this tomorrow.

def all_open_assessments(category) do
now = Timex.now()

assessment_with_category = Repo.all(from(a in Assessment, where: a.category == ^category))
Copy link
Contributor

@tuesmiddt tuesmiddt Jun 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use the all_assessments(category) method above but I think just leave it for now.

In general I think we should combine this and the Enum.filter below into one query string so that the DB engine only gives us the results we want instead of fetching too much data into memory and then filtering it. Can leave that for a later refactor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll write it down as a TODO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#58

end

def create_assessment(params) do
changeset = build_assessment(params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pipeline syntax

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/lexmag/elixir-style-guide#needless-pipeline
Basically for single function call, don't use pipeline syntax.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was thinking of

params
|> build_assessment()
|> Repo.insert()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh makes sense

end

def publish_assessment(id) do
assessment = get_assessment(id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pipeline syntax

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about

id
|> get_assessment()
|> change(%{is_published: true})
|> Repo.update()

Repo.get(Assessment, id)
end

def create_question(params, assessment_id) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think can combine this with create_question_for_assessment

end

defp put_question(changeset) do
{:ok, json} = Poison.decode(get_change(changeset, :raw_question) || "{}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is clearer if we split it into two lines or do this instead:

    {:ok, json} =
      changeset
      |> get_change(:raw_question)
      |> Kernel.||("{}")
      |> Poison.decode()

@indocomsoft indocomsoft merged commit cb56954 into master Jun 24, 2018
Sprint 3 automation moved this from In progress to Done Jun 24, 2018
@indocomsoft indocomsoft deleted the assessments branch June 24, 2018 16:20
indocomsoft added a commit that referenced this pull request Aug 17, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Sprint 1
  
Under Review
Sprint 3
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants