Skip to content

Commit

Permalink
Merge pull request #137 from sushant12/226-fix-csv-download-of-submis…
Browse files Browse the repository at this point in the history
…sions

update csv headers
  • Loading branch information
sushant12 authored Nov 27, 2024
2 parents f62ddcc + 8aad9db commit 38ce53b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/handin/assignment_submissions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule Handin.AssignmentSubmissions do

Map.merge(test_result_marks, %{
"full_name" => DisplayHelper.get_full_name(user),
"email" => user.email,
"id" => user.id,
"attempt_marks" => attempt_marks,
"total" => total_points
})
Expand All @@ -68,15 +68,15 @@ defmodule Handin.AssignmentSubmissions do
end

defp calculate_test_result_marks(nil, assignment_tests) do
Enum.reduce(assignment_tests, %{}, &Map.put(&2, &1.command, 0))
Enum.reduce(assignment_tests, %{}, &Map.put(&2, &1.name, 0))
end

defp calculate_test_result_marks(build, _assignment_tests) do
Enum.reduce(build.test_results, %{}, fn test_result, acc ->
test_marks =
if test_result.state == :pass, do: test_result.assignment_test.points_on_pass, else: 0

Map.put(acc, test_result.assignment_test.command, test_marks)
Map.put(acc, test_result.assignment_test.name, test_marks)
end)
end

Expand Down
8 changes: 5 additions & 3 deletions lib/handin_web/controllers/submission_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ defmodule HandinWeb.SubmissionController do
conn = prepare_conn_for_csv_download(conn, assignment.name)

Repo.transaction(fn ->
student_grades = AssignmentSubmissions.get_student_grades_for_assignment(assignment_id)
student_grades =
AssignmentSubmissions.get_student_grades_for_assignment(assignment_id)

headers = generate_headers(student_grades)

send_csv_data(conn, headers, student_grades)
Expand All @@ -28,9 +30,9 @@ defmodule HandinWeb.SubmissionController do
test_headers =
List.first(student_grades)
|> Map.keys()
|> Enum.filter(&(&1 not in ["full_name", "email", "attempt_marks", "total"]))
|> Enum.filter(&(&1 not in ["full_name", "id", "attempt_marks", "total"]))

["full_name", "email", "attempt_marks"] ++ test_headers ++ ["total"]
["full_name", "id", "attempt_marks"] ++ test_headers ++ ["total"]
end

defp send_csv_data(conn, headers, student_grades) do
Expand Down

0 comments on commit 38ce53b

Please sign in to comment.