From 28ad2e4a1ea45b833ba6a0f7eb5284f35ec0717b Mon Sep 17 00:00:00 2001 From: Bastian Greshake Date: Mon, 26 Sep 2011 18:37:51 +0200 Subject: [PATCH] fixed some minor bugs, added user-chrom.sex and user-yearofbirth --- app/controllers/phenotypes_controller.rb | 2 +- app/jobs/zipgenotypingfiles.rb | 4 +- app/models/phenotype.rb | 7 ++- app/models/user.rb | 2 +- app/views/users/_edit.html.erb | 8 ++++ ...10926172905_add_sex_age_columns_to_user.rb | 11 +++++ db/schema.rb | 46 +++++++++---------- 7 files changed, 49 insertions(+), 31 deletions(-) create mode 100644 db/migrate/20110926172905_add_sex_age_columns_to_user.rb diff --git a/app/controllers/phenotypes_controller.rb b/app/controllers/phenotypes_controller.rb index c2a4baf..f23b799 100644 --- a/app/controllers/phenotypes_controller.rb +++ b/app/controllers/phenotypes_controller.rb @@ -37,7 +37,7 @@ class PhenotypesController < ApplicationController @phenotype = Phenotype.find_by_characteristic(params[:phenotype][:characteristic]) end - unless @phenotype.known_phenotypes.include?(params[:user_phenotype][:variation]) + if @phenotype.known_phenotypes.include?(params[:user_phenotype][:variation]) == false @phenotype.known_phenotypes << params[:user_phenotype][:variation] end diff --git a/app/jobs/zipgenotypingfiles.rb b/app/jobs/zipgenotypingfiles.rb index ba70966..f8ec4ea 100644 --- a/app/jobs/zipgenotypingfiles.rb +++ b/app/jobs/zipgenotypingfiles.rb @@ -10,7 +10,7 @@ class Zipgenotypingfiles @user = User.find_by_id(up.user_id) print @user if @user.genotypes[0] != nil - @genotyping_files << @user.genotypes[0].fs_filename + @genotyping_files << @user.genotypes[0] end end @@ -19,7 +19,7 @@ class Zipgenotypingfiles if File.exists?(::Rails.root.to_s+"/public/data/zip/"+phenotype_id.to_s+"."+@time.to_s.gsub(" ","_")+".zip") == false Zip::ZipFile.open(::Rails.root.to_s+"/public/data/zip/"+phenotype_id.to_s+"."+@time.to_s.gsub(" ","_")+".zip", Zip::ZipFile::CREATE) do |zipfile| @genotyping_files.each do |gen_file| - zipfile.add(gen_file, "#{RAILS_ROOT}/public/data/"+ gen_file) + zipfile.add("user"+gen_file.user_id.to_s+"_file"+gen_file.id.to_s+"_yearofbirth"+gen_file.user.yearofbirth+"_sex"+gen_file.user.sex+"."+gen_file.filetype+".txt", "#{RAILS_ROOT}/public/data/"+ gen_file.fs_filename) end end end diff --git a/app/models/phenotype.rb b/app/models/phenotype.rb index 3cb48a5..b7c99d9 100644 --- a/app/models/phenotype.rb +++ b/app/models/phenotype.rb @@ -9,7 +9,10 @@ class Phenotype < ActiveRecord::Base text :characteristic end - def known_phenotypes - read_attribute(:known_phenotypes) || [] + after_create :default_array + + def default_array + self.known_phenotypes ||= [] end + end diff --git a/app/models/user.rb b/app/models/user.rb index 34c4d0b..a1459d2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,7 @@ class User < ActiveRecord::Base has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>#", :head => "32x32#" }, :default_url => '/images/standard_:style.png' - attr_accessible :user_phenotypes_attributes, :variation, :characteristic, :name, :password_confirmation, :password, :email, :description, :homepages, :homepages_attributes,:avatar, :phenotype_creation_counter, :phenotype_additional_counter,:delete_avatar + attr_accessible :user_phenotypes_attributes, :variation, :characteristic, :name, :password_confirmation, :password, :email, :description, :homepages, :homepages_attributes,:avatar, :sex, :yearofbirth, :phenotype_creation_counter, :phenotype_additional_counter,:delete_avatar before_validation :clear_avatar validates_attachment_size :avatar, :less_than=>1.megabyte diff --git a/app/views/users/_edit.html.erb b/app/views/users/_edit.html.erb index 77d816b..1a777e2 100644 --- a/app/views/users/_edit.html.erb +++ b/app/views/users/_edit.html.erb @@ -42,6 +42,14 @@

Your Phenotypes

+
+ <%= f.label :sex, "Chromosomal Sex"%> + <%= f.select :sex, options_for_select(["XX", "XY", "other", "rather not say"], :selected => @user.sex) %> +
+
+ <%= f.label :yearofbirth, "Year of Birth"%> + <%= f.select :yearofbirth, options_for_select(((1900..2011).to_a << "rather not say").reverse, :selected => @user.yearofbirth) %> +
<%= f.fields_for :user_phenotypes do |p| %>
diff --git a/db/migrate/20110926172905_add_sex_age_columns_to_user.rb b/db/migrate/20110926172905_add_sex_age_columns_to_user.rb new file mode 100644 index 0000000..7e46212 --- /dev/null +++ b/db/migrate/20110926172905_add_sex_age_columns_to_user.rb @@ -0,0 +1,11 @@ +class AddSexAgeColumnsToUser < ActiveRecord::Migration + def self.up + add_column :users, :sex, :string, :default => "rather not say" + add_column :users, :yearofbirth, :string, :default => "rather not say" + end + + def self.down + remove_column :users, :sex + remove_column :users, :yearofbirth + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 9e3d986..94b9fac 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110926092220) do +ActiveRecord::Schema.define(:version => 20110926172905) do create_table "achievements", :force => true do |t| t.text "award" @@ -30,18 +30,18 @@ ActiveRecord::Schema.define(:version => 20110926092220) do end create_table "homepages", :force => true do |t| - t.string "url" - t.string "description" + t.text "url" + t.text "description" t.datetime "created_at" t.datetime "updated_at" t.integer "user_id" end create_table "mendeley_papers", :force => true do |t| - t.string "first_author" - t.string "title" - t.string "mendeley_url" - t.string "doi" + t.text "first_author" + t.text "title" + t.text "mendeley_url" + t.text "doi" t.integer "pub_year" t.string "uuid" t.boolean "open_access" @@ -52,7 +52,7 @@ ActiveRecord::Schema.define(:version => 20110926092220) do end create_table "messages", :force => true do |t| - t.string "subject" + t.text "subject" t.integer "user_id" t.text "body" t.boolean "sent" @@ -64,8 +64,8 @@ ActiveRecord::Schema.define(:version => 20110926092220) do end create_table "phenotype_comments", :force => true do |t| - t.string "comment_text" - t.string "subject" + t.text "comment_text" + t.text "subject" t.integer "user_id" t.integer "phenotype_id" t.integer "reply_to_id" @@ -83,9 +83,9 @@ ActiveRecord::Schema.define(:version => 20110926092220) do end create_table "plos_papers", :force => true do |t| - t.string "first_author" - t.string "title" - t.string "doi" + t.text "first_author" + t.text "title" + t.text "doi" t.datetime "pub_date" t.datetime "created_at" t.datetime "updated_at" @@ -94,8 +94,8 @@ ActiveRecord::Schema.define(:version => 20110926092220) do end create_table "snp_comments", :force => true do |t| - t.string "comment_text" - t.string "subject" + t.text "comment_text" + t.text "subject" t.integer "user_id" t.integer "snp_id" t.datetime "created_at" @@ -105,7 +105,7 @@ ActiveRecord::Schema.define(:version => 20110926092220) do create_table "snpedia_papers", :force => true do |t| t.string "url" - t.string "summary" + t.text "summary" t.datetime "created_at" t.datetime "updated_at" t.integer "snp_id" @@ -119,15 +119,9 @@ ActiveRecord::Schema.define(:version => 20110926092220) do t.string "allele_frequency" t.integer "ranking" t.integer "number_of_users", :default => 0 -<<<<<<< HEAD - t.datetime "mendeley_updated", :default => '2011-08-22 15:25:47' - t.datetime "plos_updated", :default => '2011-08-22 15:25:47' - t.datetime "snpedia_updated", :default => '2011-08-22 15:25:47' -======= - t.datetime "mendeley_updated", :default => '2011-08-13 15:18:53' - t.datetime "plos_updated", :default => '2011-08-13 15:18:53' - t.datetime "snpedia_updated", :default => '2011-08-13 15:18:53' ->>>>>>> baa3387dcbb11ce042acb224478742b6f726d077 + t.datetime "mendeley_updated", :default => '2011-08-22 23:08:27' + t.datetime "plos_updated", :default => '2011-08-22 23:08:27' + t.datetime "snpedia_updated", :default => '2011-08-22 23:08:27' t.datetime "created_at" t.datetime "updated_at" end @@ -181,6 +175,8 @@ ActiveRecord::Schema.define(:version => 20110926092220) do t.boolean "help_one", :default => false t.boolean "help_two", :default => false t.boolean "help_three", :default => false + t.string "sex", :default => "rather not say" + t.string "yearofbirth", :default => "rather not say" end add_index "users", ["email"], :name => "index_users_on_email", :unique => true