|
| 1 | +require 'csv' |
| 2 | + |
| 3 | +namespace :batches_info do |
| 4 | + desc "Update batches information" |
| 5 | + task :import, [:csv_file] => :environment do |task, args| |
| 6 | + path = args[:csv_file] || abort("Usage: $> rake batches_info:import[path/to/file.csv] RAILS_ENV={env}") |
| 7 | + |
| 8 | + CSV.foreach(path, headers: true) do |row| |
| 9 | + batch = Batch.find_by(batch_number: row['virus_batch_number']) |
| 10 | + if batch |
| 11 | + batch.virus_shortname = row["virus_shortname"] |
| 12 | + batch.target_organism_name = row["target_organism_name"] |
| 13 | + batch.target_organism_taxonomy_id = row["target_organism_taxonomy_id"] |
| 14 | + batch.isolate_name = row["isolate_name"] |
| 15 | + batch.gisaid_id = row["gisaid_id"] |
| 16 | + batch.nucleotide_db_id = row["nucleotide_db_id"] |
| 17 | + batch.pango_lineage = row["pango_lineage"] |
| 18 | + batch.who_label = row["who_label"] |
| 19 | + batch.gisaid_clade = row["gisaid_clade"] |
| 20 | + batch.virus_sample_source = row["virus_sample_source"] |
| 21 | + batch.virus_sample_source_url = row["virus_sample_source_url"] |
| 22 | + batch.virus_source = row["virus_source"] |
| 23 | + batch.virus_location = row["virus_location"] |
| 24 | + batch.virus_sample_type = row["virus_sample_type"] |
| 25 | + batch.virus_sample_formulation = row["virus_sample_formulation"] |
| 26 | + batch.virus_sample_concentration = row["virus_sample_concentration"] |
| 27 | + batch.virus_sample_concentration_unit = row["virus_sample_concentration_unit"] |
| 28 | + batch.reference_gene = row["virus_sample_concentration_reference_gene"] |
| 29 | + batch.virus_sample_genome_equivalents = row["virus_sample_genome_equivalents"] |
| 30 | + batch.virus_sample_genome_equivalents_unit = row["virus_sample_genome_equivalents_unit"] |
| 31 | + batch.virus_sample_genome_equivalents_reference_gene = row["virus_sample_genome_equivalents_reference_gene"] |
| 32 | + batch.virus_preinactivation_tcid50 = row["virus_preinactivation_tcid50"] |
| 33 | + batch.virus_preinactivation_tcid50_unit = row["virus_preinactivation_tcid50_unit"] |
| 34 | + batch.virus_sample_grow_cell_line = row["virus_sample_grow_cell_line"] |
| 35 | + |
| 36 | + batch.save |
| 37 | + end |
| 38 | + end |
| 39 | + end |
| 40 | +end |
0 commit comments