-
Notifications
You must be signed in to change notification settings - Fork 37
TAN-5965 - Survey results refactor #12763
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
Closed
Closed
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6f14fd6
WIP - survey result refactor
jamesspeake 9233201
WIP - survey result refactor
jamesspeake e9218cd
WIP - survey result refactor
jamesspeake d76903f
WIP - survey result refactor
jamesspeake a9381e0
WIP - survey result refactor
jamesspeake 285a036
WIP - survey refactor
jamesspeake f55661e
WIP add option logic
jamesspeake d5fa323
[TAN-5965] Working version of new survey result generator
jamesspeake 81ba50f
[TAN-5965] Updated comments
jamesspeake 6b38dfb
Merge branch 'master' into TAN-5965-survey-results-refactor
jamesspeake 8f2ec66
[TAN-5965] Reduced number of SQL queries used when building results
jamesspeake 070e330
[TAN-5965] Removed commented code
jamesspeake 09c3016
[TAN-5965] Fixed community monitor tests
jamesspeake 0dfeaeb
[TAN-5965] Tidied up structure of results generator to use IDs and no…
jamesspeake 0dce4b6
[TAN-5965] Fixed grouping survey results
jamesspeake 85f1297
Merge branch 'master' into TAN-5965-survey-results-refactor
jamesspeake bb57fb1
[TAN-5965] Moved all logic back into main results generator
jamesspeake 4ae45c8
[TAN-5965] Added multiselect to logic and added more tests
jamesspeake b715bc3
[TAN-5965] Rearranged test code
jamesspeake 7965062
Merge branch 'master' into TAN-5965-survey-results-refactor
jamesspeake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -215,40 +215,6 @@ def supports_selection? | |
| supports_single_selection? || supports_multiple_selection? | ||
| end | ||
|
|
||
| def average_rankings(scope) | ||
| # This basically starts from all combinations of scope ID, option key (value) | ||
| # and position (ordinality) and then calculates the average position for each | ||
| # option. "#>> '{}'" is used to unescape the double quotes in the JSONB value. | ||
| return {} if input_type != 'ranking' | ||
|
|
||
| scope | ||
| .where.not("custom_field_values ->> '#{key}' IS NULL") | ||
| .joins("CROSS JOIN jsonb_array_elements(custom_field_values->'#{key}') WITH ORDINALITY AS elem(value, ordinality)") | ||
| .group("elem.value #>> '{}'") | ||
| .average('elem.ordinality') | ||
| end | ||
|
|
||
| def rankings_counts(scope) | ||
| # This basically starts from all combinations of scope ID, option key (value) | ||
| # and position (ordinality) and then calculates the count for each option and | ||
| # position. "#>> '{}'" is used to unescape the double quotes in the JSONB | ||
| # value. | ||
| return {} if input_type != 'ranking' | ||
|
|
||
| query_result = scope | ||
| .where.not("custom_field_values ->> '#{key}' IS NULL") | ||
| .joins("CROSS JOIN jsonb_array_elements(custom_field_values->'#{key}') WITH ORDINALITY AS elem(value, ordinality)") | ||
| .group("elem.value #>> '{}'", 'elem.ordinality') | ||
| .count | ||
|
|
||
| # Transform pair to ordinality hash into a hash of hashes | ||
| options.pluck(:key).index_with do |option_key| | ||
| (1..options.size).index_with do |ranking| | ||
| query_result[[option_key, ranking]] || 0 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def built_in? | ||
| !!code | ||
| end | ||
|
|
@@ -465,7 +431,7 @@ def ordered_options | |
| @ordered_options ||= if random_option_ordering | ||
| options.shuffle.sort_by { |o| o.other ? 1 : 0 } | ||
| else | ||
| options.order(:ordering) | ||
| options # options are by default ordered by :ordering from the association | ||
|
Comment on lines
-465
to
+430
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed |
||
| end | ||
| end | ||
|
|
||
|
|
@@ -572,12 +538,12 @@ def sanitize_description_multiloc | |
|
|
||
| # Return domicile options with IDs and descriptions taken from areas | ||
| def domicile_options | ||
| return options.order(:ordering) unless domicile? | ||
| return options unless domicile? | ||
|
|
||
| areas = Area.where(custom_field_option_id: options.pluck(:id)) | ||
| area_id_map = areas.map { |a| { a.custom_field_option_id => { id: a.id, title: a.title_multiloc } } }.reduce({}, :merge) | ||
|
|
||
| options.order(:ordering).map do |option| | ||
| options.map do |option| | ||
| option.key = area_id_map.dig(option.id, :id) || 'outside' | ||
| option.title_multiloc = area_id_map.dig(option.id, :title) || MultilocService.new.i18n_to_multiloc('custom_field_options.domicile.outside') | ||
| option | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this to results as no longer being done in SQL