-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
242 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -22,3 +22,7 @@ Style/FrozenStringLiteralComment: | |
|
||
Metrics/LineLength: | ||
Max: 100 | ||
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- 'spec/**/*.rb' |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# frozen_string_literal: true | ||
|
||
class ZipGenotypingFiles | ||
include Sidekiq::Worker | ||
sidekiq_options queue: :zipgenotyping, retry: 5, unique: true | ||
|
||
def perform(phenotype_id, variation, target_address) | ||
@phenotype = Phenotype.find(phenotype_id) | ||
@variation = variation | ||
@target_address = target_address | ||
@time = Time.current.to_s.tr(':', '_') | ||
|
||
if genotypes.empty? | ||
send_no_results | ||
else | ||
zip_genotypes | ||
send_results | ||
end | ||
end | ||
|
||
def zip_genotypes | ||
return if File.exist?(zip_file_path) | ||
|
||
Zip::File.open(zip_file_path, Zip::File::CREATE) do |zipfile| | ||
genotypes.each do |genotype| | ||
zipfile.add( | ||
zipped_file_name(genotype), | ||
Rails.root.join('public', 'data', genotype.fs_filename) | ||
) | ||
end | ||
end | ||
File.chmod(0o777, zip_file_path) | ||
end | ||
|
||
def send_results | ||
UserMailer.genotyping_results( | ||
target_address, | ||
zip_file_path.to_s, | ||
phenotype.characteristic, | ||
variation | ||
).deliver_later | ||
end | ||
|
||
def zipped_file_name(genotype) | ||
"user#{genotype.user_id}_file#{genotype.id}_yearofbirth" \ | ||
"#{genotype.user.yearofbirth}_sex#{genotype.user.sex}.#{genotype.filetype}.txt" | ||
end | ||
|
||
def send_no_results | ||
UserMailer.no_genotyping_results( | ||
target_address, | ||
phenotype.characteristic, | ||
variation | ||
).deliver_later | ||
end | ||
|
||
private | ||
|
||
attr_reader :phenotype, :variation, :target_address, :time | ||
|
||
def genotypes | ||
@genotypes ||= user_phenotypes.includes(:user).flat_map do |user_phenotype| | ||
user_phenotype.user.genotypes | ||
end | ||
end | ||
|
||
def user_phenotypes | ||
UserPhenotype | ||
.where(phenotype_id: phenotype.id) | ||
.search(variation) | ||
end | ||
|
||
def zip_file_path | ||
@zip_file_path ||= Rails.root.join( | ||
'public', | ||
'data', | ||
'zip', | ||
"#{phenotype.id}.#{time.to_s.tr(' ', '_')}.zip" | ||
) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
FactoryBot.define do | ||
factory :achievement do | ||
award 'Foooooooo' | ||
award { 'Foooooooo' } | ||
end | ||
end |
This file contains 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
FactoryBot.define do | ||
factory :fitbit_activity do | ||
steps 100 | ||
floors 1 | ||
steps { 100 } | ||
floors { 1 } | ||
end | ||
end |
This file contains 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
FactoryBot.define do | ||
factory :fitbit_body do | ||
weight '100' | ||
bmi '200' | ||
weight { '100' } | ||
bmi { '200' } | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
FactoryBot.define do | ||
factory :plos_paper do | ||
title 'A PLOS Paper' | ||
title { 'A PLOS Paper' } | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
factory :user_phenotype do | ||
association :user | ||
association :phenotype | ||
variation 'pink' | ||
variation { 'pink' } | ||
end | ||
end |
This file contains 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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
FactoryBot.define do | ||
factory :user_picture_phenotype do | ||
variation 'pink' | ||
variation { 'pink' } | ||
end | ||
end |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.