Skip to content

Conversation

@sreycodes
Copy link
Contributor

@sreycodes sreycodes commented May 20, 2018

Fixes #26 #28

@indocomsoft indocomsoft added this to the Sprint 1 milestone 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.

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


@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

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.

  • You still have not refactored all the json deserialisation as requested during the meeting
  • Please check the warnings produced by the compiler -- there are many useless variables and import, use statements
  • Try to have only a single assert for each unit test

.gitignore Outdated
# Uploaded file
/uploads


Copy link
Member

Choose a reason for hiding this comment

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

Please remove duplicate blank line


import Ecto.Changeset
import Ecto.Query
import Cadet.ContextHelper
Copy link
Member

Choose a reason for hiding this comment

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

Move all the import statements to cadet.ex in the :context part instead

use Cadet, :model
use Arc.Ecto.Schema

import Cadet.ModelHelper
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 import again because this has already been imported in cadet.ex


import Ecto.Query

alias Cadet.Assessments.Assessment
Copy link
Member

Choose a reason for hiding this comment

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

Please remove unused alias

@moduledoc false
use Cadet, :model

import Ecto.Query
Copy link
Member

Choose a reason for hiding this comment

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

Please remove unused import. Model should not be doing any query anyway

is_published: true
)

result = Enum.map(Assessments.missions_due_soon(), fn m -> m.id end)
Copy link
Member

Choose a reason for hiding this comment

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

missions_due_ids is a better name

assert mission.title == "changed_mission"
end

test "all missions with category" 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 split each category into separate tests

end

test "update question" do
mission = insert(:mission)
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

end

test "delete question" do
mission = insert(:mission)
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?


result = Enum.map(Assessments.missions_due_soon(), fn m -> m.id end)
assert mission_in_timerange.id in result
refute mission_far.id in result
Copy link
Member

Choose a reason for hiding this comment

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

you need to add refute mission_before_now.id in result too

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 indocomsoft requested a review from tuesmiddt June 23, 2018 14:29
@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
@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

None yet

Development

Successfully merging this pull request may close these issues.

5 participants