2016-02-12 23:52:43 +08:00
module FirstTimeDataGenerator
# Create data for tutorial for new users
def seed_demo_data user
@user = user
# First organization that this user created
# should contain the "intro" project
2016-07-21 19:11:15 +08:00
if cookies [ :repeat_tutorial_org_id ]
org = Organization . find ( cookies [ :repeat_tutorial_org_id ] )
cookies . delete :repeat_tutorial_org_id
else
org = user
. organizations
. where ( created_by : user )
. order ( created_at : :asc )
. first
end
2016-02-12 23:52:43 +08:00
# If private private organization does not exist,
# there was something wrong with user creation.
# Do nothing
return unless org
# Create sample types
SampleType . create (
name : " Potato leaves " ,
organization : org
)
SampleType . create (
name : " Tea leaves " ,
organization : org
)
SampleType . create (
name : " Potato bug " ,
organization : org
)
SampleGroup . create (
name : " Fodder " ,
organization : org ,
2016-10-13 16:00:36 +08:00
color : Constants :: TAG_COLORS [ 1 ]
2016-02-12 23:52:43 +08:00
)
SampleGroup . create (
name : " Nutrient " ,
organization : org ,
2016-10-13 16:00:36 +08:00
color : Constants :: TAG_COLORS [ 0 ]
2016-02-12 23:52:43 +08:00
)
SampleGroup . create (
name : " Seed " ,
organization : org ,
2016-10-13 16:00:36 +08:00
color : Constants :: TAG_COLORS [ 2 ]
2016-02-12 23:52:43 +08:00
)
samples = [ ]
# Generate random sample names start
# and put it on the beginning of 5 samples
sample_name = ( 0 ... 3 ) . map { 65 . + ( rand ( 26 ) ) . chr } . join << '/'
for i in 1 .. 5
samples << Sample . create (
name : sample_name + i . to_s ,
organization : org ,
user : user ,
sample_type : rand < 0 . 8 ? pluck_random ( org . sample_types ) : nil ,
sample_group : rand < 0 . 8 ? pluck_random ( org . sample_groups ) : nil
)
end
sample_name = ( 0 ... 3 ) . map { 65 . + ( rand ( 26 ) ) . chr } . join << '/'
for i in 1 .. 5
samples << Sample . create (
name : sample_name + i . to_s ,
organization : org ,
user : user ,
sample_type : rand < 0 . 8 ? pluck_random ( org . sample_types ) : nil ,
sample_group : rand < 0 . 8 ? pluck_random ( org . sample_groups ) : nil
)
end
2016-07-21 19:11:15 +08:00
name = " Demo project - qPCR "
2016-07-25 21:15:34 +08:00
exp_name = " My first experiment "
2016-07-21 19:11:15 +08:00
# If there is an existing demo project, archive and rename it
if org . projects . where ( name : name ) . present?
old = org . projects . where ( name : " Demo project - qPCR " ) [ 0 ]
# old.archive! user
i = 1
while org . projects . where ( name : name = " Demo project - qPCR ( #{ i } ) " ) . present?
i += 1
end
end
2016-02-12 23:52:43 +08:00
project = Project . create (
2016-07-21 19:11:15 +08:00
visibility : 0 ,
name : name ,
2016-02-12 23:52:43 +08:00
due_date : nil ,
organization : org ,
created_by : user ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( 1 . week . ago ) ,
2016-02-12 23:52:43 +08:00
last_modified_by : user ,
2016-07-25 21:15:34 +08:00
archived : false
)
experiment = Experiment . create (
name : exp_name ,
description : " This is my very first experiment " ,
project : project ,
created_by : user ,
created_at : project . created_at + 5 . minutes ,
last_modified_by : user
2016-02-12 23:52:43 +08:00
)
# Automatically assign project author onto project
UserProject . create (
user : user ,
project : project ,
role : 0 ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( 1 . week . ago )
2016-02-12 23:52:43 +08:00
)
# Activity for creating project
Activity . create (
type_of : :create_project ,
user : user ,
project : project ,
message : I18n . t (
" activities.create_project " ,
user : user . full_name ,
project : project . name
) ,
created_at : project . created_at
)
# Add a comment
2016-08-30 14:19:35 +08:00
generate_project_comment (
project ,
user ,
" I've created a demo project "
2016-02-12 23:52:43 +08:00
)
# Create a module group
my_module_group = MyModuleGroup . create (
name : " Potato qPCR workflow " ,
2016-07-25 21:15:34 +08:00
experiment : experiment
2016-02-12 23:52:43 +08:00
)
# Create project modules
my_modules = [ ]
my_module_names = [
" Experiment design " ,
" Sampling biological material " ,
" RNA isolation " ,
" RNA quality & quantity - BIOANALYSER " ,
" Reverse transcription " ,
" qPCR " ,
" Data quality control " ,
" Data analysis - ddCq "
]
qpcr_module_description = " PCR is a method where an enzyme
( thermostable DNA polymerase , originally isolated in 1960 s
from bacterium Thermus aquaticus , growing in hot lakes of
Yellowstone park , USA ) amplifies a short specific part of
the template DNA ( amplicon ) in cycles . In every cycle the
number of short specific sections of DNA is doubled , leading
to an exponential amplification of targets . More on how
conventional PCR works can be found here . "
my_module_names . each_with_index do | name , i |
my_module = MyModule . create (
name : name ,
created_by : user ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( 6 . days . ago ) ,
2016-02-12 23:52:43 +08:00
due_date : Time . now + ( 2 * i + 1 ) . weeks ,
description : i == 5 ? qpcr_module_description : nil ,
2016-08-11 22:24:44 +08:00
x : ( i < 4 ? i % 4 : 7 - i ) * 32 ,
y : ( i / 4 ) * 16 ,
2016-08-18 14:33:08 +08:00
experiment : experiment ,
2016-02-12 23:52:43 +08:00
workflow_order : i ,
my_module_group : my_module_group
)
my_modules << my_module
# Add connections between current and previous module
if i > 0
Connection . create (
input_id : my_module . id ,
output_id : my_modules [ i - 1 ] . id
)
end
# Create module activity
Activity . create (
type_of : :create_module ,
user : user ,
project : project ,
my_module : my_module ,
message : I18n . t (
" activities.create_module " ,
user : user . full_name ,
module : my_module . name
) ,
created_at : my_module . created_at
)
UserMyModule . create (
user : user ,
my_module : my_module ,
assigned_by : user ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( my_module . created_at , 2 . minutes )
2016-02-12 23:52:43 +08:00
)
Activity . create (
type_of : :assign_user_to_module ,
user : user ,
project : project ,
my_module : my_module ,
message : I18n . t (
" activities.assign_user_to_module " ,
assigned_user : user . full_name ,
module : my_module . name ,
assigned_by_user : user . full_name
) ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( my_module . created_at , 2 . minutes )
2016-02-12 23:52:43 +08:00
)
end
# Create an archived module
archived_module = MyModule . create (
name : " Data analysis - Pfaffl method " ,
created_by : user ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( 6 . days . ago ) ,
2016-02-12 23:52:43 +08:00
due_date : Time . now + 1 . week ,
description : nil ,
x : - 1 ,
y : - 1 ,
2016-07-25 21:15:34 +08:00
experiment : experiment ,
2016-02-12 23:52:43 +08:00
workflow_order : - 1 ,
my_module_group : nil ,
archived : true ,
2016-07-21 19:11:15 +08:00
archived_on : generate_random_time ( 3 . days . ago ) ,
2016-02-12 23:52:43 +08:00
archived_by : user
)
# Activity for creating archived module
Activity . create (
type_of : :create_module ,
user : user ,
project : project ,
my_module : archived_module ,
message : I18n . t (
" activities.create_module " ,
user : user . full_name ,
module : archived_module . name
) ,
created_at : archived_module . created_at
)
# Activity for archiving archived module
Activity . create (
type_of : :archive_module ,
user : user ,
project : project ,
my_module : archived_module ,
message : I18n . t (
" activities.archive_module " ,
user : user . full_name ,
module : archived_module . name
) ,
created_at : archived_module . archived_on
)
# Assign new user to archived module
UserMyModule . create (
user : user ,
my_module : archived_module ,
assigned_by : user ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( archived_module . created_at , 2 . minutes )
2016-02-12 23:52:43 +08:00
)
Activity . create (
type_of : :assign_user_to_module ,
user : user ,
project : project ,
my_module : archived_module ,
message : I18n . t (
" activities.assign_user_to_module " ,
assigned_user : user . full_name ,
module : archived_module . name ,
assigned_by_user : user . full_name
) ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( archived_module . created_at , 2 . minutes )
2016-02-12 23:52:43 +08:00
)
# Assign 4 samples to modules
samples_to_assign = [ ]
taken_sample_ids = [ ]
for _ in 1 .. 4
begin
sample = samples . sample
end while sample . id . in? taken_sample_ids
taken_sample_ids << sample . id
samples_to_assign << sample
end
my_modules [ 1 ] . get_downstream_modules . each do | mm |
samples_to_assign . each do | s |
SampleMyModule . create (
sample : s ,
my_module : mm
)
end
end
# Add comments to modules
2016-08-30 14:19:35 +08:00
generate_module_comment (
my_modules [ 0 ] ,
user ,
'We should have a meeting to discuss sampling parametrs soon.'
2016-02-12 23:52:43 +08:00
)
2016-08-30 14:19:35 +08:00
generate_module_comment (
my_modules [ 0 ] ,
user ,
'I agree.'
2016-02-12 23:52:43 +08:00
)
2016-08-30 14:19:35 +08:00
generate_module_comment (
my_modules [ 1 ] ,
user ,
'The samples have arrived.'
2016-02-12 23:52:43 +08:00
)
2016-08-30 14:19:35 +08:00
generate_module_comment (
my_modules [ 2 ] ,
user ,
'Due date has been postponed for a day.'
2016-02-12 23:52:43 +08:00
)
2016-08-30 14:19:35 +08:00
generate_module_comment (
my_modules [ 4 ] ,
user ,
'Please show Steve the RT procedure.'
2016-02-12 23:52:43 +08:00
)
2016-08-30 14:19:35 +08:00
generate_module_comment (
my_modules [ 5 ] ,
user ,
'The results must be very definitive.'
2016-02-12 23:52:43 +08:00
)
2016-08-30 14:19:35 +08:00
generate_module_comment (
my_modules [ 7 ] ,
user ,
'The due date here is flexible.'
2016-02-12 23:52:43 +08:00
)
2016-07-21 19:11:15 +08:00
# Create tags and add them to module
drylab_tag = Tag . create (
name : " Drylab " ,
2016-10-13 16:00:36 +08:00
color : Constants :: TAG_COLORS [ 8 ] ,
2016-07-21 19:11:15 +08:00
project : project ,
created_by : user ,
last_modified_by : user
)
wetlab_tag = Tag . create (
name : " Wetlab " ,
2016-10-13 16:00:36 +08:00
color : Constants :: TAG_COLORS [ 14 ] ,
2016-07-21 19:11:15 +08:00
project : project ,
created_by : user ,
last_modified_by : user
)
decide_tag = Tag . create (
name : " Decide " ,
2016-10-13 16:00:36 +08:00
color : Constants :: TAG_COLORS [ 5 ] ,
2016-07-21 19:11:15 +08:00
project : project ,
created_by : user ,
last_modified_by : user
)
2016-02-12 23:52:43 +08:00
2016-07-21 19:11:15 +08:00
# Add tags to module
my_modules [ 0 ] . tags << drylab_tag
my_modules [ 1 ] . tags << wetlab_tag
my_modules [ 2 ] . tags << wetlab_tag
my_modules [ 3 ] . tags << wetlab_tag
my_modules [ 4 ] . tags << wetlab_tag
my_modules [ 5 ] . tags << drylab_tag
my_modules [ 6 ] . tags << drylab_tag
my_modules [ 7 ] . tags << drylab_tag
my_modules [ 7 ] . tags << decide_tag
my_modules [ 7 ] . save
# Load table contents yaml file
tab_content = YAML . load_file ( " #{ Rails . root } /app/assets/tutorial_files/tables_content.yaml " )
# Create module content
# ----------------- Module 1 ------------------
2016-02-12 23:52:43 +08:00
module_step_names = [
" Gene expression "
]
module_step_descriptions = [
" Compare response of PVYNTN, cab4 and PR1 genes in mock/virus inoculated potatoes & in time "
]
generate_module_steps ( my_modules [ 0 ] , module_step_names , module_step_descriptions )
2016-07-21 19:11:15 +08:00
# Results
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 0 ] ,
current_user : user ,
result_name : " sF " ,
created_at : generate_random_time ( my_modules [ 0 ] . created_at , 2 . days ) ,
file_name : " samples.txt "
)
temp_result = Result . new (
name : " Experimental design " ,
my_module : my_modules [ 0 ] ,
created_at : generate_random_time ( my_modules [ 0 ] . created_at , 1 . days ) ,
user : user
)
2016-08-30 14:19:35 +08:00
generate_result_comment (
temp_result ,
user ,
'The table shows proposed number of biological replicates.'
2016-07-21 19:11:15 +08:00
)
temp_result . table = Table . new (
created_by : user ,
contents : tab_content [ " module1 " ] [ " experimental_design " ]
)
temp_result . save
# ----------------- Module 2 ------------------
2016-02-12 23:52:43 +08:00
module_step_names = [
" Inoculation of potatoes " ,
" Collection of potatoes " ,
" Store samples "
]
module_step_descriptions = [
" 50% of samples should be mock inoculated while other 50% with PVY NTN virus. " ,
" 50% of PVYNTN inoculated potatos and 50% of Mock inoculated potatos collect 1 day post inocullation while other halph of samples collect 6 days post inoculation. " ,
" Collect samples in 2ml tubes and put them in liquid nitrogen and store at 80°C. "
]
generate_module_steps ( my_modules [ 1 ] , module_step_names , module_step_descriptions )
2016-07-21 19:11:15 +08:00
# Add file to existig step
DelayedUploaderTutorial . delay ( queue : :tutorial ) . add_step_asset (
step : my_modules [ 1 ] . protocol . steps . where ( " position = 0 " ) . take ,
current_user : user ,
file_name : " sample-potatoe.txt "
)
# Results
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 1 ] ,
current_user : user ,
result_name : " PVY-inoculated plant, symptoms " ,
created_at : generate_random_time ( my_modules [ 1 ] . created_at , 1 . days ) ,
file_name : " DSCN0660.JPG "
)
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 1 ] ,
current_user : user ,
result_name : " mock-inoculated plant " ,
created_at : generate_random_time ( my_modules [ 1 ] . created_at , 2 . days ) ,
file_name : " DSCN0354.JPG "
)
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 1 ] ,
current_user : user ,
result_name : " Height of plants at 6dpi " ,
created_at : generate_random_time ( my_modules [ 1 ] . created_at , 3 . days ) ,
file_name : " 6dpi_height.JPG "
)
# Add a text result
temp_result = Result . new (
name : " Number of samples " ,
my_module : my_modules [ 1 ] ,
user : user ,
created_at : generate_random_time ( my_modules [ 1 ] . created_at , 4 . days )
)
temp_text = " There are many biological replicates we harvested for each type of sample (code-names): \n \n "
samples_to_assign . each do | s |
temp_text << " * #{ s . name } \n \n "
end
temp_result . result_text = ResultText . new (
text : temp_text
)
temp_result . save
# Create result activity
Activity . create (
type_of : :add_result ,
project : project ,
my_module : my_modules [ 1 ] ,
user : user ,
created_at : temp_result . created_at ,
message : I18n . t (
" activities.add_text_result " ,
user : user . full_name ,
result : temp_result . name
)
)
# ----------------- Module 3 ------------------
2016-02-12 23:52:43 +08:00
module_step_names = [
" Homogenization of the material " ,
" Isolation of RNA with RNeasy plant mini kit "
]
module_step_descriptions = [
" Use tissue lyser: 1 min on step 3. " ,
nil
]
generate_module_steps ( my_modules [ 2 ] , module_step_names , module_step_descriptions )
2016-07-21 19:11:15 +08:00
# Add file to existig step
DelayedUploaderTutorial . delay ( queue : :tutorial ) . add_step_asset (
step : my_modules [ 2 ] . protocol . steps . where ( " position = 1 " ) . take ,
current_user : user ,
file_name : " RNeasy-Plant-Mini-Kit-EN.pdf "
)
# Results
temp_result = Result . new (
name : " Nanodrop results " ,
my_module : my_modules [ 2 ] ,
created_at : generate_random_time ( my_modules [ 2 ] . created_at , 1 . days ) ,
user : user
)
2016-08-30 14:19:35 +08:00
generate_result_comment (
temp_result ,
user ,
2016-08-30 19:06:49 +08:00
'PVY NTN 6dpi isolation seems to have failed, ' \
'please repeat nanodrop measurement.'
2016-07-21 19:11:15 +08:00
)
temp_result . table = Table . new (
created_by : user ,
contents : tab_content [ " module3 " ] [ " nanodrop " ]
)
temp_result . save
# Create result activity
Activity . create (
type_of : :add_result ,
project : project ,
my_module : my_modules [ 2 ] ,
user : user ,
created_at : temp_result . created_at ,
message : I18n . t (
" activities.add_text_result " ,
user : user . full_name ,
result : temp_result . name
)
)
# Second result
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 2 ] ,
current_user : user ,
result_name : " Agarose gel electrophoresis of totRNA samples " ,
created_at : generate_random_time ( my_modules [ 2 ] . created_at , 3 . days ) ,
file_name : " totRNA_gel.jpg "
)
# ----------------- Module 4 ------------------
2016-02-12 23:52:43 +08:00
module_step_names = [
" Use Nano chip for testing RNA integrity "
]
module_step_descriptions = [
nil
]
generate_module_steps ( my_modules [ 3 ] , module_step_names , module_step_descriptions )
2016-07-21 19:11:15 +08:00
# Add file to existig step
DelayedUploaderTutorial . delay ( queue : :tutorial ) . add_step_asset (
step : my_modules [ 3 ] . protocol . steps . where ( " position = 0 " ) . take ,
current_user : user ,
file_name : " G2938-90034_KitRNA6000Nano_ebook.pdf "
)
# Results
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 3 ] ,
current_user : user ,
result_name : " Result of RNA integrity " ,
created_at : generate_random_time ( my_modules [ 3 ] . created_at , 2 . days ) ,
file_name : " Bioanalyser_result.JPG "
)
# ----------------- Module 5 ------------------
2016-02-12 23:52:43 +08:00
module_step_names = [
" RNA denaturation " ,
" Prepare mastermix for RT " ,
" RT reaction "
]
module_step_descriptions = [
" 1 ug of RNA denature at 80°C for 5 min --> ice " ,
" High Capacity cDNA Reverse Transcription Kit (Applied Biosystems) " ,
" 25°C for 10 min 37°C for 2 h "
]
generate_module_steps ( my_modules [ 4 ] , module_step_names , module_step_descriptions )
2016-07-21 19:11:15 +08:00
module_checklist_items = [
" RT buffer " ,
" dNTP mix " ,
" Random Primers " ,
" RNase inhibitor " ,
" Reverse transcriptase " ,
" Optional: Luciferase mRNA (denatured) " ,
" H2O to 12.5 ul "
]
# Add checklist to step
step = my_modules [ 4 ] . protocol . steps . where ( " position = 1 " ) . take
checklist = Checklist . new (
name : " Mastermix " ,
step : step
)
module_checklist_items . each do | item |
checklist . checklist_items << ChecklistItem . new (
text : item
)
end
checklist . save
# ----------------- Module 6 ------------------
2016-02-12 23:52:43 +08:00
module_step_names = [
" Sample preparation " ,
" Reaction setup " ,
2016-07-21 19:11:15 +08:00
" Use Applied Biosystem 7300 instrument for qPCR " ,
2016-02-12 23:52:43 +08:00
" Setup of the 96 plate "
]
module_step_descriptions = [
nil ,
nil ,
2016-07-21 19:11:15 +08:00
" Use following cycling condtions: " ,
2016-02-12 23:52:43 +08:00
" Template of the 96-well plate "
]
generate_module_steps ( my_modules [ 5 ] , module_step_names , module_step_descriptions )
2016-07-21 19:11:15 +08:00
# Add file to existig steps
DelayedUploaderTutorial . delay ( queue : :tutorial ) . add_step_asset (
step : my_modules [ 5 ] . protocol . steps . where ( " position = 0 " ) . take ,
current_user : user ,
file_name : " sample_preparation.JPG "
)
DelayedUploaderTutorial . delay ( queue : :tutorial ) . add_step_asset (
step : my_modules [ 5 ] . protocol . steps . where ( " position = 1 " ) . take ,
current_user : user ,
file_name : " reaction_setup.JPG "
)
DelayedUploaderTutorial . delay ( queue : :tutorial ) . add_step_asset (
step : my_modules [ 5 ] . protocol . steps . where ( " position = 2 " ) . take ,
current_user : user ,
file_name : " cycling_conditions.JPG "
)
DelayedUploaderTutorial . delay ( queue : :tutorial ) . add_step_asset (
step : my_modules [ 5 ] . protocol . steps . where ( " position = 3 " ) . take ,
current_user : user ,
file_name : " 96plate.doc "
)
# Results
# Add a hard-coded table result
temp_result = Result . new (
name : " Sample distribution on the plate " ,
my_module : my_modules [ 5 ] ,
user : user ,
created_at : generate_random_time ( my_modules [ 5 ] . created_at , 1 . days )
)
temp_result . table = Table . new (
created_by : user ,
contents : tab_content [ " module6 " ] [ " distribution " ] % { sample0 : samples_to_assign [ 0 ] . name ,
sample1 : samples_to_assign [ 1 ] . name ,
sample2 : samples_to_assign [ 2 ] . name ,
sample3 : samples_to_assign [ 3 ] . name }
)
temp_result . save
# Create result activity
Activity . create (
type_of : :add_result ,
project : project ,
my_module : my_modules [ 5 ] ,
user : user ,
created_at : temp_result . created_at ,
message : I18n . t (
" activities.add_table_result " ,
user : user . full_name ,
result : temp_result . name
)
)
# Results
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 5 ] ,
current_user : user ,
result_name : " Mixtures and plate setup " ,
created_at : generate_random_time ( my_modules [ 5 ] . created_at , 2 . days ) ,
file_name : " Mixes_Templats.xls "
)
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 5 ] ,
current_user : user ,
result_name : " Raw data from ABI 7300 " ,
created_at : generate_random_time ( my_modules [ 5 ] . created_at , 3 . days ) ,
file_name : " BootCamp-Experiment-results-20122.sds "
)
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 5 ] ,
current_user : user ,
result_name : " All results - curves " ,
created_at : generate_random_time ( my_modules [ 5 ] . created_at , 4 . days ) ,
file_name : " curves.JPG "
)
# ----------------- Module 7 ------------------
2016-02-12 23:52:43 +08:00
module_step_names = [
" Check negative controls NTC " ,
" Eliminate results that have positive NTCs "
]
module_step_descriptions = [
" They have to be negative when using TaqMan assays. If they are positive when using SYBR assays check also melitng curve where signal comes from. - if it is primer dimer result is negative - If it is specific signal it is positive " ,
" And repeat procedure "
]
generate_module_steps ( my_modules [ 6 ] , module_step_names , module_step_descriptions )
2016-07-21 19:11:15 +08:00
# Add comment to step
step = my_modules [ 6 ] . protocol . steps . where ( " position = 1 " ) . take
step . save
2016-08-30 14:19:35 +08:00
generate_step_comment (
step ,
user ,
'What is the Cq that should be considered as positive result?'
)
2016-07-21 19:11:15 +08:00
# ----------------- Module 8 ------------------
2016-02-12 23:52:43 +08:00
module_step_names = [
" Template for ddCq analysis "
]
module_step_descriptions = [
nil
]
generate_module_steps ( my_modules [ 7 ] , module_step_names , module_step_descriptions )
2016-07-21 19:11:15 +08:00
# Add file to existig step
DelayedUploaderTutorial . delay ( queue : :tutorial ) . add_step_asset (
step : my_modules [ 7 ] . protocol . steps . where ( " position = 0 " ) . take ,
current_user : user ,
2016-09-07 19:04:12 +08:00
file_name : " ddCq-quantification_diagnostics-template.xls "
2016-02-12 23:52:43 +08:00
)
2016-07-21 19:11:15 +08:00
# Add result
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 7 ] ,
current_user : user ,
result_name : " Results of ddCq method " ,
created_at : generate_random_time ( my_modules [ 7 ] . created_at , 1 . days ) ,
file_name : " ddCq-quantification_diagnostics-results.xls "
2016-02-12 23:52:43 +08:00
)
2016-07-21 19:11:15 +08:00
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 7 ] ,
current_user : user ,
result_name : " Dilution curve and efficiency " ,
created_at : generate_random_time ( my_modules [ 7 ] . created_at , 2 . days ) ,
file_name : " dilution_curve-efficiency.JPG "
)
2016-02-12 23:52:43 +08:00
2016-07-21 19:11:15 +08:00
DelayedUploaderTutorial . delay ( queue : :tutorial ) . generate_result_asset (
my_module : my_modules [ 7 ] ,
current_user : user ,
result_name : " Relative quantification results " ,
created_at : generate_random_time ( my_modules [ 7 ] . created_at , 3 . days ) ,
file_name : " result-ddCq.JPG "
2016-02-12 23:52:43 +08:00
)
2016-07-21 19:11:15 +08:00
# Add a text result
2016-02-12 23:52:43 +08:00
temp_result = Result . new (
2016-07-21 19:11:15 +08:00
name : " Markdown remarks " ,
my_module : my_modules [ 7 ] ,
2016-02-12 23:52:43 +08:00
user : user ,
2016-07-21 19:11:15 +08:00
created_at : generate_random_time ( my_modules [ 7 ] . created_at , 4 . days )
2016-02-12 23:52:43 +08:00
)
2016-07-21 19:11:15 +08:00
temp_text = " __Bolded text__ \n \n double Enter to go to new line \n \n - bulletpoint "
temp_result . result_text = ResultText . new (
text : temp_text
2016-02-12 23:52:43 +08:00
)
temp_result . save
# Create result activity
Activity . create (
type_of : :add_result ,
project : project ,
2016-07-21 19:11:15 +08:00
my_module : my_modules [ 7 ] ,
2016-02-12 23:52:43 +08:00
user : user ,
created_at : temp_result . created_at ,
message : I18n . t (
2016-07-21 19:11:15 +08:00
" activities.add_text_result " ,
2016-02-12 23:52:43 +08:00
user : user . full_name ,
result : temp_result . name
)
)
2016-08-25 01:03:58 +08:00
# create thumbnail
experiment . generate_workflow_img
2016-08-30 14:19:35 +08:00
2016-02-12 23:52:43 +08:00
# Lastly, create cookie with according ids
# so tutorial steps can be properly positioned
2016-07-21 19:11:15 +08:00
JSON . generate ( [
2016-02-12 23:52:43 +08:00
organization : org . id ,
project : project . id ,
qpcr_module : my_modules [ 5 ] . id
] )
end
2016-07-21 19:11:15 +08:00
2016-02-12 23:52:43 +08:00
# WARNING: This only works on PostgreSQL
def pluck_random ( scope )
scope . order ( " RANDOM() " ) . first
end
2016-07-21 19:11:15 +08:00
def generate_random_time ( * args )
early = args [ 0 ]
if args . size == 1
rand ( early .. Time . now )
else
late = early + args [ 1 ]
late = Time . now if late > Time . now
rand ( early .. late )
end
end
2016-02-12 23:52:43 +08:00
# Create steps for given module
def generate_module_steps ( my_module , step_names , step_descriptions )
step_names . each_with_index do | name , i |
2016-07-21 19:11:15 +08:00
created_at = generate_random_time ( my_module . created_at , 5 . hours )
2016-02-12 23:52:43 +08:00
completed = rand < = 0 . 3
completed_on = completed ?
2016-07-21 19:11:15 +08:00
generate_random_time ( created_at , 10 . hours ) : nil
2016-02-12 23:52:43 +08:00
step = Step . create (
created_at : created_at ,
name : name ,
description : step_descriptions [ i ] ,
position : i ,
completed : completed ,
user : @user ,
2016-07-21 19:11:15 +08:00
protocol : my_module . protocol ,
2016-02-12 23:52:43 +08:00
completed_on : completed_on
)
# Create activity
Activity . create (
type_of : :create_step ,
2016-07-28 22:40:51 +08:00
project : my_module . experiment . project ,
2016-02-12 23:52:43 +08:00
my_module : my_module ,
user : step . user ,
created_at : created_at ,
message : I18n . t (
" activities.create_step " ,
user : step . user . full_name ,
step : i ,
step_name : step . name
)
)
if completed then
Activity . create (
type_of : :complete_step ,
2016-07-28 22:40:51 +08:00
project : my_module . experiment . project ,
2016-02-12 23:52:43 +08:00
my_module : my_module ,
user : step . user ,
created_at : completed_on ,
message : I18n . t (
" activities.complete_step " ,
user : step . user . full_name ,
step : i + 1 ,
step_name : step . name ,
2016-07-21 19:11:15 +08:00
completed : my_module . protocol . completed_steps . count ,
2016-02-12 23:52:43 +08:00
all : i + 1
)
)
# Also add random comments to completed steps
if rand < 0 . 3
polite_comment = " This looks well. "
elsif rand < 0 . 4
polite_comment = " Seems satisfactory. "
elsif rand < 0 . 4
polite_comment = " Try a bit harder next time. "
end
if polite_comment
2016-07-21 19:11:15 +08:00
commented_on = generate_random_time ( completed_on )
2016-08-30 14:19:35 +08:00
generate_step_comment (
step ,
@user ,
polite_comment ,
commented_on
2016-02-12 23:52:43 +08:00
)
end
end
end
end
2016-08-30 14:19:35 +08:00
def generate_project_comment ( project , user , message , created_at = nil )
created_at || = generate_random_time ( project . created_at , 1 . week )
project . comments << Comment . create (
user : user ,
message : message ,
created_at : created_at
)
Activity . create (
type_of : :add_comment_to_project ,
user : user ,
project : project ,
created_at : created_at ,
message : t ( 'activities.add_comment_to_project' ,
user : user . full_name ,
project : project . name )
)
end
def generate_module_comment ( my_module , user , message , created_at = nil )
created_at || = generate_random_time ( my_module . created_at , 1 . day )
my_module . comments << Comment . create (
user : user ,
message : message ,
created_at : created_at
)
Activity . create (
type_of : :add_comment_to_module ,
user : user ,
project : my_module . experiment . project ,
my_module : my_module ,
created_at : created_at ,
message : t ( 'activities.add_comment_to_module' ,
user : user . full_name ,
module : my_module . name )
)
end
def generate_result_comment ( result , user , message , created_at = nil )
created_at || = generate_random_time ( result . created_at , 1 . days )
result . comments << Comment . new (
user : user ,
message : message ,
created_at : created_at
)
Activity . create (
type_of : :add_comment_to_result ,
user : user ,
project : result . my_module . experiment . project ,
my_module : result . my_module ,
created_at : created_at ,
message : t ( 'activities.add_comment_to_result' ,
user : user . full_name ,
result : result . name )
)
end
def generate_step_comment ( step , user , message , created_at = nil )
created_at || = generate_random_time ( step . created_at , 2 . hours )
step . comments << Comment . new (
user : user ,
message : message ,
created_at : created_at
)
Activity . create (
type_of : :add_comment_to_step ,
user : user ,
project : step . protocol . my_module . experiment . project ,
my_module : step . protocol . my_module ,
created_at : created_at ,
message : t ( 'activities.add_comment_to_step' ,
user : user . full_name ,
step : step . position + 1 ,
step_name : step . name )
)
end
2016-07-21 19:11:15 +08:00
end