From ed85f32d3bc3b724085095c466a99f99a9846804 Mon Sep 17 00:00:00 2001 From: Will Poynter Date: Fri, 26 May 2017 09:53:51 +0100 Subject: [PATCH 1/6] Removed redundant database calls --- app/controllers/variables_controller.rb | 2 +- app/views/variables/index.json.jbuilder | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/variables_controller.rb b/app/controllers/variables_controller.rb index e7f014af..cb6ced31 100644 --- a/app/controllers/variables_controller.rb +++ b/app/controllers/variables_controller.rb @@ -50,6 +50,6 @@ def collection end def set_dataset - @dataset = policy_scope(Dataset).find(params[:dataset_id]) + @dataset = policy_scope(Dataset).includes(variables: [:questions, :src_variables, :der_variables, :topic] ).find(params[:dataset_id]) end end \ No newline at end of file diff --git a/app/views/variables/index.json.jbuilder b/app/views/variables/index.json.jbuilder index bfd21ae7..24aa8a6d 100644 --- a/app/views/variables/index.json.jbuilder +++ b/app/views/variables/index.json.jbuilder @@ -8,7 +8,12 @@ json.array!(@collection) do |variable| json.used_bys variable.der_variables, :id, :name, :label, :var_type json.topic variable.topic, :id, :code, :name, :parent_id unless variable.topic.nil? json.strand do - json.topic variable.strand.topic, :id, :code, :name, :parent_id + json.topic do + json.id = variable.strand.topic.id + json.code = variable.strand.topic.code + json.name = variable.strand.topic.name + json.parent_id = variable.strand.topic.parent_id + end json.good variable.strand.good end unless variable.strand.topic.nil? json.suggested_topic variable.get_suggested_topic, :id, :code, :name, :parent_id unless variable.get_suggested_topic.nil? From 2c48e84aa71b4f60960fce8b6ac5625e0a4fbad9 Mon Sep 17 00:00:00 2001 From: Will Poynter Date: Fri, 26 May 2017 09:55:11 +0100 Subject: [PATCH 2/6] Increased version number --- config/initializers/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 3009e813..6b52097b 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,6 +1,6 @@ module Archivist class Application - VERSION = '8.1.8' + VERSION = '8.1.9' BETA = false end end From 12ced23c4e8974e588ab88087a1a4b106f49e8ad Mon Sep 17 00:00:00 2001 From: Will Poynter Date: Fri, 26 May 2017 10:26:54 +0100 Subject: [PATCH 3/6] Merged master into develop --- app/controllers/variables_controller.rb | 2 +- app/views/variables/index.json.jbuilder | 7 ++++++- config/initializers/version.rb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/variables_controller.rb b/app/controllers/variables_controller.rb index e7f014af..cb6ced31 100644 --- a/app/controllers/variables_controller.rb +++ b/app/controllers/variables_controller.rb @@ -50,6 +50,6 @@ def collection end def set_dataset - @dataset = policy_scope(Dataset).find(params[:dataset_id]) + @dataset = policy_scope(Dataset).includes(variables: [:questions, :src_variables, :der_variables, :topic] ).find(params[:dataset_id]) end end \ No newline at end of file diff --git a/app/views/variables/index.json.jbuilder b/app/views/variables/index.json.jbuilder index bfd21ae7..24aa8a6d 100644 --- a/app/views/variables/index.json.jbuilder +++ b/app/views/variables/index.json.jbuilder @@ -8,7 +8,12 @@ json.array!(@collection) do |variable| json.used_bys variable.der_variables, :id, :name, :label, :var_type json.topic variable.topic, :id, :code, :name, :parent_id unless variable.topic.nil? json.strand do - json.topic variable.strand.topic, :id, :code, :name, :parent_id + json.topic do + json.id = variable.strand.topic.id + json.code = variable.strand.topic.code + json.name = variable.strand.topic.name + json.parent_id = variable.strand.topic.parent_id + end json.good variable.strand.good end unless variable.strand.topic.nil? json.suggested_topic variable.get_suggested_topic, :id, :code, :name, :parent_id unless variable.get_suggested_topic.nil? diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 3009e813..6b52097b 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,6 +1,6 @@ module Archivist class Application - VERSION = '8.1.8' + VERSION = '8.1.9' BETA = false end end From d0a61e9163f15cbefaa901c93fb667fb360afb38 Mon Sep 17 00:00:00 2001 From: Will Poynter Date: Fri, 26 May 2017 15:42:25 +0100 Subject: [PATCH 4/6] Added main mapper exports --- app/controllers/cc_questions_controller.rb | 9 +++++++++ app/controllers/datasets_controller.rb | 10 ++++++++-- app/controllers/instruments_controller.rb | 2 +- app/controllers/variables_controller.rb | 9 +++++++++ app/models/qv_mapping.rb | 4 ++++ app/models/strand.rb | 1 - app/views/cc_questions/tq.txt.erb | 3 +++ app/views/datasets/dv.txt.erb | 3 +++ app/views/instruments/mapping.txt.erb | 3 +++ app/views/variables/tv.txt.erb | 3 +++ config/routes.rb | 17 ++++++++++------- lib/linkable.rb | 4 ++++ 12 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 app/views/cc_questions/tq.txt.erb create mode 100644 app/views/datasets/dv.txt.erb create mode 100644 app/views/instruments/mapping.txt.erb create mode 100644 app/views/variables/tv.txt.erb diff --git a/app/controllers/cc_questions_controller.rb b/app/controllers/cc_questions_controller.rb index f4182da1..3170f5bf 100644 --- a/app/controllers/cc_questions_controller.rb +++ b/app/controllers/cc_questions_controller.rb @@ -9,6 +9,15 @@ def variables render 'variables/index' end + def tq + @collection = collection.order(:id) + @collection.each { |v| v.strand } + respond_to do |format| + format.text { render 'tq.txt.erb', layout: false, content_type: 'text/plain' } + format.json {} + end + end + def set_topic topic = Topic.find params[:topic_id] diff --git a/app/controllers/datasets_controller.rb b/app/controllers/datasets_controller.rb index 77737712..dc393e1d 100644 --- a/app/controllers/datasets_controller.rb +++ b/app/controllers/datasets_controller.rb @@ -1,13 +1,12 @@ class DatasetsController < BasicController include Importers::Controller - only_set_object { %i{questions} } + only_set_object { %i{ questions dv } } has_importers({ dv: ImportJob::DV, topicv: ImportJob::TopicV }) -# only_set_object { %i{member_imports} } @model_class = Dataset @params_list = [:name] @@ -27,6 +26,13 @@ def show end end + def dv + respond_to do |format| + format.text { render 'dv.txt.erb', layout: false, content_type: 'text/plain' } + format.json {} + end + end + def import files = params[:files].nil? ? [] : params[:files] options = {} diff --git a/app/controllers/instruments_controller.rb b/app/controllers/instruments_controller.rb index b80d8de7..98148add 100644 --- a/app/controllers/instruments_controller.rb +++ b/app/controllers/instruments_controller.rb @@ -6,7 +6,7 @@ class InstrumentsController < BasicController qvmapping: ImportJob::Mapping, topicq: ImportJob::TopicQ }) - only_set_object { %i{copy response_domains response_domain_codes reorder_ccs stats export mapper member_imports variables} } + only_set_object { %i{copy response_domains response_domain_codes reorder_ccs stats export mapper mapping member_imports variables} } @model_class = Instrument @params_list = %i{agency version prefix label study files import_question_grids} diff --git a/app/controllers/variables_controller.rb b/app/controllers/variables_controller.rb index cb6ced31..e88180eb 100644 --- a/app/controllers/variables_controller.rb +++ b/app/controllers/variables_controller.rb @@ -5,6 +5,15 @@ class VariablesController < BasicController @model_class = Variable @params_list = [:name, :label, :var_type, :dataset_id] + def tv + @collection = collection.order(:id) + @collection.each { |v| v.strand } + respond_to do |format| + format.text { render 'tv.txt.erb', layout: false, content_type: 'text/plain' } + format.json {} + end + end + def set_topic topic = Topic.find_by_id params[:topic_id] diff --git a/app/models/qv_mapping.rb b/app/models/qv_mapping.rb index e2bb54b8..a8a318a6 100644 --- a/app/models/qv_mapping.rb +++ b/app/models/qv_mapping.rb @@ -3,4 +3,8 @@ class QvMapping < ActiveRecord::Base belongs_to :dataset belongs_to :instrument + + def question_with_cell + self.question + ((self.x.nil? || self.y.nil?) ? '' : "$#{self.x};#{self.y}") + end end \ No newline at end of file diff --git a/app/models/strand.rb b/app/models/strand.rb index 3a9e4aa9..2f97587a 100644 --- a/app/models/strand.rb +++ b/app/models/strand.rb @@ -160,7 +160,6 @@ def save (do_eval = false) @id = Strand.redis.incr SCOPE + ':count' self.class.active[@id.to_i] = self end - puts @members.map(&:typed_id).inspect Strand.redis.sadd SCOPE + ':' + @id.to_s, @members.map(&:typed_id) @members.each do |member| Strand.redis.hset LOOKUP, member.typed_id, @id.to_s diff --git a/app/views/cc_questions/tq.txt.erb b/app/views/cc_questions/tq.txt.erb new file mode 100644 index 00000000..ac635c84 --- /dev/null +++ b/app/views/cc_questions/tq.txt.erb @@ -0,0 +1,3 @@ +<% @collection.each do |qc| %> +<%= qc.label %> <%= qc.fully_resolved_topic_code %> +<% end %> \ No newline at end of file diff --git a/app/views/datasets/dv.txt.erb b/app/views/datasets/dv.txt.erb new file mode 100644 index 00000000..b9ca9203 --- /dev/null +++ b/app/views/datasets/dv.txt.erb @@ -0,0 +1,3 @@ +<% @object.dv_mappings.order(id: 'ASC').each do |map| %> +<%= map.variable %> <%= map.source %> +<% end %> \ No newline at end of file diff --git a/app/views/instruments/mapping.txt.erb b/app/views/instruments/mapping.txt.erb new file mode 100644 index 00000000..3c46622a --- /dev/null +++ b/app/views/instruments/mapping.txt.erb @@ -0,0 +1,3 @@ +<% @object.qv_mappings.order(id: 'ASC').each do |map| %> +<%= map.question_with_cell %> <%= map.variable %> +<% end %> \ No newline at end of file diff --git a/app/views/variables/tv.txt.erb b/app/views/variables/tv.txt.erb new file mode 100644 index 00000000..2b88d74f --- /dev/null +++ b/app/views/variables/tv.txt.erb @@ -0,0 +1,3 @@ +<% @collection.each do |v| %> +<%= v.name %> <%= v.fully_resolved_topic_code %> +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9d23a853..d46bd05e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,7 +38,12 @@ get 'external' end end - resources :datasets, constraints: -> (r) { (r.format == :json || r.format == :xml) } do + + request_processor = lambda do |request| + [:json, :xml, :text].include?(request.format.symbol) + end + + resources :datasets, constraints: request_processor do resources :variables do member do post 'set_topic', to: 'variables#set_topic' @@ -49,14 +54,10 @@ member do match 'imports', to: 'datasets#member_imports', via: [:post, :put] get 'questions', to: 'datasets#questions' + get 'dv', to: 'datasets#dv' end end - - request_processor = lambda do |request| - # binding.pry if request.path =~ %r{/instruments/13/imports} - # 1 - [:json, :xml, :text].include?(request.format.symbol) - end + get 'datasets/:dataset_id/tv', to: 'variables#tv', constraints: request_processor resources :instruments, constraints: request_processor do resources :cc_sequences @@ -88,10 +89,12 @@ get 'stats', to: 'instruments#stats' get 'export', to: 'instruments#export' get 'mapper', to: 'instruments#mapper' + get 'mapping', to: 'instruments#mapping' match 'imports', to: 'instruments#member_imports', via: [:post, :put] get 'variables', to: 'instruments#variables' end end + get 'instruments/:instrument_id/tq', to: 'cc_questions#tq', constraints: request_processor get 'instruments/:id/export', to: 'instruments#latest_document' get 'datasets/:id/export', to: 'datasets#latest_document' diff --git a/lib/linkable.rb b/lib/linkable.rb index f0941127..64993e07 100644 --- a/lib/linkable.rb +++ b/lib/linkable.rb @@ -60,5 +60,9 @@ def get_suggested_topic cluster = Cluster.find_by_member self cluster&.suggested_topic end + + def fully_resolved_topic_code + (get_topic || get_suggested_topic)&.code&.to_s || '0' + end end end \ No newline at end of file From fd023ed13452284b3900ee55859dd12d5dfc79a0 Mon Sep 17 00:00:00 2001 From: Will Poynter Date: Fri, 26 May 2017 15:43:07 +0100 Subject: [PATCH 5/6] Incremented version number --- config/initializers/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 6b52097b..50de7844 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,6 +1,6 @@ module Archivist class Application - VERSION = '8.1.9' + VERSION = '8.2.0' BETA = false end end From 1b75410938a9ee2ec04e44f2aaf2973124dde55e Mon Sep 17 00:00:00 2001 From: Will Poynter Date: Fri, 26 May 2017 16:12:13 +0100 Subject: [PATCH 6/6] Fixed tab bug in txt files --- app/views/cc_questions/tq.txt.erb | 2 +- app/views/datasets/dv.txt.erb | 2 +- app/views/instruments/mapping.txt.erb | 2 +- app/views/variables/tv.txt.erb | 2 +- config/initializers/version.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/cc_questions/tq.txt.erb b/app/views/cc_questions/tq.txt.erb index ac635c84..0f6e1662 100644 --- a/app/views/cc_questions/tq.txt.erb +++ b/app/views/cc_questions/tq.txt.erb @@ -1,3 +1,3 @@ <% @collection.each do |qc| %> -<%= qc.label %> <%= qc.fully_resolved_topic_code %> +<%= qc.label %><%= "\t" %><%= qc.fully_resolved_topic_code %> <% end %> \ No newline at end of file diff --git a/app/views/datasets/dv.txt.erb b/app/views/datasets/dv.txt.erb index b9ca9203..4ca1f234 100644 --- a/app/views/datasets/dv.txt.erb +++ b/app/views/datasets/dv.txt.erb @@ -1,3 +1,3 @@ <% @object.dv_mappings.order(id: 'ASC').each do |map| %> -<%= map.variable %> <%= map.source %> +<%= map.variable %><%= "\t" %><%= map.source %> <% end %> \ No newline at end of file diff --git a/app/views/instruments/mapping.txt.erb b/app/views/instruments/mapping.txt.erb index 3c46622a..dd5d1c44 100644 --- a/app/views/instruments/mapping.txt.erb +++ b/app/views/instruments/mapping.txt.erb @@ -1,3 +1,3 @@ <% @object.qv_mappings.order(id: 'ASC').each do |map| %> -<%= map.question_with_cell %> <%= map.variable %> +<%= map.question_with_cell %><%= "\t" %><%= map.variable %> <% end %> \ No newline at end of file diff --git a/app/views/variables/tv.txt.erb b/app/views/variables/tv.txt.erb index 2b88d74f..ee21b789 100644 --- a/app/views/variables/tv.txt.erb +++ b/app/views/variables/tv.txt.erb @@ -1,3 +1,3 @@ <% @collection.each do |v| %> -<%= v.name %> <%= v.fully_resolved_topic_code %> +<%= v.name %><%= "\t" %><%= v.fully_resolved_topic_code %> <% end %> \ No newline at end of file diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 50de7844..93dc8baa 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,6 +1,6 @@ module Archivist class Application - VERSION = '8.2.0' + VERSION = '8.2.1' BETA = false end end