-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ra, dec, apmag and abmag to Star
- Loading branch information
1 parent
605e51e
commit ba53e5e
Showing
7 changed files
with
119,671 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AddHygFieldsForStars < ActiveRecord::Migration[5.2] | ||
def change | ||
# Star's apparent visual magnitude | ||
add_column :stars, :apparent_magnitude, :decimal, precision: 4, scale: 2 | ||
|
||
# Star's absolute visual magnitude | ||
add_column :stars, :absolute_magnitude, :decimal, precision: 6, scale: 3 | ||
|
||
# Stars's right ascension | ||
add_column :stars, :right_ascension, :decimal, precision: 9, scale: 6 | ||
|
||
# Star's declination | ||
add_column :stars, :declination, :decimal, precision: 10, scale: 6 | ||
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
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'csv' | ||
require 'active_support' | ||
require 'activerecord-import' | ||
|
||
namespace :import do | ||
desc 'Import HYG Database stars' | ||
task hyg: :environment do | ||
log = Logger.new(STDOUT).tap { STDOUT.sync = true } | ||
start_time = Time.zone.now | ||
|
||
Star.destroy_all | ||
|
||
filename = File.join(Rails.root, 'db', 'seeds', 'hygdata_v3.csv') | ||
|
||
stars = [] | ||
CSV.open(filename, headers: true, converters: :numeric).first(500).each do |row| | ||
data = row.to_hash | ||
stars << Star.new( | ||
apparent_magnitude: data['mag'], | ||
absolute_magnitude: data['absmag'], | ||
right_ascension: data['ra'], | ||
declination: data['dec'] | ||
) | ||
end | ||
Star.import(stars) | ||
|
||
end_time = Time.zone.now | ||
time_spend = (end_time - start_time).to_i | ||
log.info "Executed in: #{time_spend} #{'second'.pluralize(time_spend)}." | ||
end | ||
end |