Skip to content

Commit

Permalink
Merge branch 'release/0.10' into release/0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
waj committed Oct 13, 2017
2 parents bbfe80e + 1c4380c commit dd16a8c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ In this release the development platform was updated (Elixir 1.5, Phoenix 1.3, E

* Fixed inconsistent number of contacted respondents [#1128](https://github.com/instedd/ask/issues/1128)

## Juniper 0.10.4

### Bugfixes

* Fix respondent stats that were breaking sometimes when a respondent is in "completed" disposition but still active

## Juniper 0.10.3

### Features
Expand Down
35 changes: 25 additions & 10 deletions test/controllers/respondent_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ defmodule Ask.RespondentControllerTest do
survey = insert(:survey, project: project, cutoff: 10, started_at: t)
questionnaire = insert(:questionnaire, name: "test", project: project, steps: @dummy_steps)
insert_list(10, :respondent, survey: survey, questionnaire: questionnaire, disposition: "partial")
insert(:respondent, survey: survey, disposition: "completed", questionnaire: questionnaire, completed_at: Timex.parse!("2016-01-01T10:00:00Z", "{ISO:Extended}"))
insert(:respondent, survey: survey, disposition: "completed", questionnaire: questionnaire, completed_at: Timex.parse!("2016-01-01T11:00:00Z", "{ISO:Extended}"))
insert_list(3, :respondent, survey: survey, disposition: "completed", questionnaire: questionnaire, completed_at: Timex.parse!("2016-01-02T10:00:00Z", "{ISO:Extended}"))
insert(:respondent, survey: survey, disposition: "completed", questionnaire: questionnaire, updated_at: Ecto.DateTime.cast!("2016-01-01T10:00:00Z"))
insert(:respondent, survey: survey, disposition: "completed", questionnaire: questionnaire, updated_at: Ecto.DateTime.cast!("2016-01-01T11:00:00Z"))
insert_list(3, :respondent, survey: survey, disposition: "completed", questionnaire: questionnaire, updated_at: Ecto.DateTime.cast!("2016-01-02T10:00:00Z"))

conn = get conn, project_survey_respondents_stats_path(conn, :stats, project.id, survey.id)
data = json_response(conn, 200)["data"]
Expand Down Expand Up @@ -120,6 +120,21 @@ defmodule Ask.RespondentControllerTest do
assert data["total_respondents"] == 15
end

test "stats do not crash when a respondent has 'completed' disposition but no 'completed_at'", %{conn: conn, user: user} do
t = Timex.parse!("2016-01-01T10:00:00Z", "{ISO:Extended}")
project = create_project_for_user(user)
survey = insert(:survey, project: project, cutoff: 1, started_at: t)
questionnaire = insert(:questionnaire, name: "test", project: project, steps: @dummy_steps)
insert(:respondent, survey: survey, disposition: "completed", questionnaire: questionnaire, updated_at: t |> Timex.to_erl |> Ecto.DateTime.from_erl)

conn = get conn, project_survey_respondents_stats_path(conn, :stats, project.id, survey.id)
data = json_response(conn, 200)["data"]

cumulative_percentages = data["cumulative_percentages"][to_string(questionnaire.id)]
assert Enum.at(cumulative_percentages, 0)["date"] == "2016-01-01"
assert Enum.at(cumulative_percentages, 0)["percent"] == 100
end

test "lists stats for a given survey with quotas", %{conn: conn, user: user} do
t = Timex.parse!("2016-01-01T10:00:00Z", "{ISO:Extended}")
project = create_project_for_user(user)
Expand All @@ -128,10 +143,10 @@ defmodule Ask.RespondentControllerTest do
bucket_2 = insert(:quota_bucket, survey: survey, quota: 3, count: 3)
questionnaire = insert(:questionnaire, name: "test", project: project, steps: @dummy_steps)
insert_list(10, :respondent, survey: survey, questionnaire: questionnaire, disposition: "partial")
insert(:respondent, survey: survey, questionnaire: questionnaire, disposition: "completed", completed_at: Timex.parse!("2016-01-01T10:00:00Z", "{ISO:Extended}"), quota_bucket: bucket_1)
insert(:respondent, survey: survey, questionnaire: questionnaire, disposition: "completed", completed_at: Timex.parse!("2016-01-01T11:00:00Z", "{ISO:Extended}"), quota_bucket: bucket_1)
insert(:respondent, survey: survey, questionnaire: questionnaire, disposition: "rejected", completed_at: Timex.parse!("2016-01-02T10:00:00Z", "{ISO:Extended}"), quota_bucket: bucket_2)
insert_list(3, :respondent, survey: survey, questionnaire: questionnaire, disposition: "completed", completed_at: Timex.parse!("2016-01-02T10:00:00Z", "{ISO:Extended}"), quota_bucket: bucket_2)
insert(:respondent, survey: survey, questionnaire: questionnaire, disposition: "completed", updated_at: Ecto.DateTime.cast!("2016-01-01T10:00:00Z"), quota_bucket: bucket_1)
insert(:respondent, survey: survey, questionnaire: questionnaire, disposition: "completed", updated_at: Ecto.DateTime.cast!("2016-01-01T11:00:00Z"), quota_bucket: bucket_1)
insert(:respondent, survey: survey, questionnaire: questionnaire, disposition: "rejected", updated_at: Ecto.DateTime.cast!("2016-01-02T10:00:00Z"), quota_bucket: bucket_2)
insert_list(3, :respondent, survey: survey, questionnaire: questionnaire, disposition: "completed", updated_at: Ecto.DateTime.cast!("2016-01-02T10:00:00Z"), quota_bucket: bucket_2)

conn = get conn, project_survey_respondents_stats_path(conn, :stats, project.id, survey.id)
data = json_response(conn, 200)["data"]
Expand Down Expand Up @@ -187,9 +202,9 @@ defmodule Ask.RespondentControllerTest do
survey = insert(:survey, project: project, cutoff: 10, started_at: t)
questionnaire = insert(:questionnaire, name: "test", project: project, steps: @dummy_steps)
insert_list(10, :respondent, survey: survey, state: "pending", disposition: "registered")
insert(:respondent, survey: survey, state: "completed", questionnaire: questionnaire, disposition: "partial", completed_at: Timex.parse!("2016-01-01T10:00:00Z", "{ISO:Extended}"))
insert(:respondent, survey: survey, state: "completed", questionnaire: questionnaire, disposition: "completed", completed_at: Timex.parse!("2016-01-01T11:00:00Z", "{ISO:Extended}"))
insert_list(3, :respondent, survey: survey, state: "completed", questionnaire: questionnaire, disposition: "ineligible", completed_at: Timex.parse!("2016-01-02T10:00:00Z", "{ISO:Extended}"))
insert(:respondent, survey: survey, state: "completed", questionnaire: questionnaire, disposition: "partial", updated_at: Ecto.DateTime.cast!("2016-01-01T10:00:00Z"))
insert(:respondent, survey: survey, state: "completed", questionnaire: questionnaire, disposition: "completed", updated_at: Ecto.DateTime.cast!("2016-01-01T11:00:00Z"))
insert_list(3, :respondent, survey: survey, state: "completed", questionnaire: questionnaire, disposition: "ineligible", updated_at: Ecto.DateTime.cast!("2016-01-02T10:00:00Z"))

conn = get conn, project_survey_respondents_stats_path(conn, :stats, project.id, survey.id)
data = json_response(conn, 200)["data"]
Expand Down
24 changes: 12 additions & 12 deletions web/controllers/respondent_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,17 @@ defmodule Ask.RespondentController do
defp respondents_by_questionnaire_and_completed_at(survey) do
Repo.all(
from r in Respondent, where: r.survey_id == ^survey.id and r.disposition == "completed",
group_by: fragment("questionnaire_id, DATE(completed_at)"),
order_by: fragment("DATE(completed_at) ASC"),
select: {r.questionnaire_id, fragment("DATE(completed_at)"), count("*")})
group_by: fragment("questionnaire_id, DATE(updated_at)"),
order_by: fragment("DATE(updated_at) ASC"),
select: {r.questionnaire_id, fragment("DATE(updated_at)"), count("*")})
end

defp respondents_by_questionnaire_mode_and_completed_at(survey) do
Repo.all(
from r in Respondent, where: r.survey_id == ^survey.id and r.disposition == "completed",
group_by: fragment("questionnaire_id, mode, DATE(completed_at)"),
order_by: fragment("DATE(completed_at) ASC"),
select: {r.questionnaire_id, r.mode, fragment("DATE(completed_at)"), count("*")})
group_by: fragment("questionnaire_id, mode, DATE(updated_at)"),
order_by: fragment("DATE(updated_at) ASC"),
select: {r.questionnaire_id, r.mode, fragment("DATE(updated_at)"), count("*")})
|> Enum.map(fn({questionnaire_id, mode, completed_at, count}) ->
reference_id = if mode && questionnaire_id do
"#{questionnaire_id}#{mode |> Enum.join("")}"
Expand All @@ -360,17 +360,17 @@ defmodule Ask.RespondentController do
defp respondents_by_mode_and_completed_at(survey) do
Repo.all(
from r in Respondent, where: r.survey_id == ^survey.id and r.disposition == "completed",
group_by: fragment("mode, DATE(completed_at)"),
order_by: fragment("DATE(completed_at) ASC"),
select: {r.mode, fragment("DATE(completed_at)"), count("*")})
group_by: fragment("mode, DATE(updated_at)"),
order_by: fragment("DATE(updated_at) ASC"),
select: {r.mode, fragment("DATE(updated_at)"), count("*")})
end

defp respondents_by_quota_bucket_and_completed_at(survey) do
Repo.all(
from r in Respondent, where: r.survey_id == ^survey.id and r.disposition == "completed",
group_by: fragment("quota_bucket_id, DATE(completed_at)"),
order_by: fragment("DATE(completed_at) ASC"),
select: {r.quota_bucket_id, fragment("DATE(completed_at)"), count("*")})
group_by: fragment("quota_bucket_id, DATE(updated_at)"),
order_by: fragment("DATE(updated_at) ASC"),
select: {r.quota_bucket_id, fragment("DATE(updated_at)"), count("*")})
end

defp add_disposition_percent(respondents_count_by_disposition_and_questionnaire, total_respondents) do
Expand Down

0 comments on commit dd16a8c

Please sign in to comment.