gdshowsdb 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rvmrc +4 -0
- data/.travis.yml +4 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +106 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +4 -0
- data/data/gdshowsdb/1965.yaml +78 -0
- data/data/gdshowsdb/1966.yaml +780 -0
- data/data/gdshowsdb/1967.yaml +857 -0
- data/data/gdshowsdb/1968.yaml +1252 -0
- data/data/gdshowsdb/1969.yaml +1799 -0
- data/data/gdshowsdb/1970.yaml +3547 -0
- data/data/gdshowsdb/1971.yaml +1396 -0
- data/data/gdshowsdb/1972.yaml +6849 -0
- data/data/gdshowsdb/1973.yaml +6229 -0
- data/data/gdshowsdb/1974.yaml +3516 -0
- data/data/gdshowsdb/1975.yaml +207 -0
- data/data/gdshowsdb/1976.yaml +3226 -0
- data/data/gdshowsdb/1977.yaml +4469 -0
- data/data/gdshowsdb/1978.yaml +5681 -0
- data/data/gdshowsdb/1979.yaml +5487 -0
- data/data/gdshowsdb/1980.yaml +7133 -0
- data/data/gdshowsdb/1981.yaml +6347 -0
- data/data/gdshowsdb/1982.yaml +4475 -0
- data/data/gdshowsdb/1983.yaml +4561 -0
- data/data/gdshowsdb/1984.yaml +4431 -0
- data/data/gdshowsdb/1985.yaml +4810 -0
- data/data/gdshowsdb/1986.yaml +3029 -0
- data/data/gdshowsdb/1987.yaml +5958 -0
- data/data/gdshowsdb/1988.yaml +5398 -0
- data/data/gdshowsdb/1989.yaml +4979 -0
- data/data/gdshowsdb/1990.yaml +4941 -0
- data/data/gdshowsdb/1991.yaml +5269 -0
- data/data/gdshowsdb/1992.yaml +3576 -0
- data/data/gdshowsdb/1993.yaml +5178 -0
- data/data/gdshowsdb/1994.yaml +5206 -0
- data/data/gdshowsdb/1995.yaml +2931 -0
- data/data/gdshowsdb/shows-debug.yaml +138 -0
- data/data/gdshowsdb/song_refs.yaml +411 -0
- data/gdshowsdb.gemspec +23 -0
- data/lib/gdshowsdb/db/migrations/001_create_song_ref_table.rb +15 -0
- data/lib/gdshowsdb/db/migrations/002_import_song_refs.rb +14 -0
- data/lib/gdshowsdb/db/migrations/003_create_show_table.rb +22 -0
- data/lib/gdshowsdb/db/migrations/004_create_show_set_table.rb +15 -0
- data/lib/gdshowsdb/db/migrations/005_create_song_table.rb +18 -0
- data/lib/gdshowsdb/db/migrations/006_create_song_occurences_table.rb +17 -0
- data/lib/gdshowsdb/db/migrations/008_add_count_to_song_ref_table.rb +11 -0
- data/lib/gdshowsdb/db/migrations/009_import_shows.rb +45 -0
- data/lib/gdshowsdb/diff.rb +36 -0
- data/lib/gdshowsdb/generators/gdshowsdatabase_generator.rb +17 -0
- data/lib/gdshowsdb/generators/gdshowsdatabase_upgrade_generator.rb +49 -0
- data/lib/gdshowsdb/models/extensions/uuid.rb +9 -0
- data/lib/gdshowsdb/models/show.rb +58 -0
- data/lib/gdshowsdb/models/show_set.rb +40 -0
- data/lib/gdshowsdb/models/song.rb +72 -0
- data/lib/gdshowsdb/models/song_occurence.rb +9 -0
- data/lib/gdshowsdb/models/song_ref.rb +32 -0
- data/lib/gdshowsdb/set_db_extractor.rb +19 -0
- data/lib/gdshowsdb/set_diff.rb +10 -0
- data/lib/gdshowsdb/set_yaml_parser.rb +29 -0
- data/lib/gdshowsdb/show_db_extractor.rb +19 -0
- data/lib/gdshowsdb/show_diff.rb +12 -0
- data/lib/gdshowsdb/show_yaml_parser.rb +20 -0
- data/lib/gdshowsdb/song_db_extractor.rb +21 -0
- data/lib/gdshowsdb/song_diff.rb +10 -0
- data/lib/gdshowsdb/song_ref_db_extractror.rb +18 -0
- data/lib/gdshowsdb/song_ref_diff.rb +12 -0
- data/lib/gdshowsdb/song_ref_yaml_parser.rb +19 -0
- data/lib/gdshowsdb/song_yaml_parser.rb +25 -0
- data/lib/gdshowsdb/templates/update_migration.rb.erb +53 -0
- data/lib/gdshowsdb/version.rb +3 -0
- data/lib/gdshowsdb.rb +45 -0
- data/sample.rb +29 -0
- data/spec/gdshowsdb/diff_spec.rb +69 -0
- data/spec/gdshowsdb/models/show_set_spec.rb +29 -0
- data/spec/gdshowsdb/models/show_spec.rb +13 -0
- data/spec/gdshowsdb/models/song_spec.rb +72 -0
- data/spec/gdshowsdb/set_db_extractor_spec.rb +37 -0
- data/spec/gdshowsdb/set_yaml_parser_spec.rb +74 -0
- data/spec/gdshowsdb/show_db_extractor_spec.rb +25 -0
- data/spec/gdshowsdb/show_yaml_parser_spec.rb +42 -0
- data/spec/gdshowsdb/song_db_extractor_spec.rb +47 -0
- data/spec/gdshowsdb/song_ref_db_extractor_spec.rb +20 -0
- data/spec/gdshowsdb/song_ref_yaml_parser_spec.rb +19 -0
- data/spec/gdshowsdb/song_yaml_parser_spec.rb +93 -0
- data/spec/spec_helper.rb +15 -0
- metadata +186 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'securerandom'
|
|
3
|
+
require 'gdshowsdb'
|
|
4
|
+
|
|
5
|
+
class ImportShows < ActiveRecord::Migration
|
|
6
|
+
include Gdshowsdb
|
|
7
|
+
|
|
8
|
+
def up
|
|
9
|
+
(1965..1995).each do |year|
|
|
10
|
+
create_shows(year)
|
|
11
|
+
create_sets(year)
|
|
12
|
+
create_songs(year)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def down
|
|
17
|
+
Song.delete_all
|
|
18
|
+
ShowSet.delete_all
|
|
19
|
+
Show.delete_all
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def create_shows(year)
|
|
25
|
+
show_yaml_parser = ShowYAMLParser.from_yaml(year)
|
|
26
|
+
show_yaml_parser.parse.each do |show_yaml|
|
|
27
|
+
show = Show.create(show_yaml)
|
|
28
|
+
puts "Created #{show.title}"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create_sets(year)
|
|
33
|
+
set_yaml_parser = SetYAMLParser.from_yaml(year)
|
|
34
|
+
set_yaml_parser.parse.each do |set_yaml|
|
|
35
|
+
ShowSet.create_from(set_yaml)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def create_songs(year)
|
|
40
|
+
song_yaml_parser = SongYAMLParser.from_yaml(year)
|
|
41
|
+
song_yaml_parser.parse.each do |song_yaml|
|
|
42
|
+
Song.create_from(song_yaml)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class Diff
|
|
3
|
+
def initialize(from_yaml, from_db)
|
|
4
|
+
@from_yaml = from_yaml
|
|
5
|
+
@yaml_uuids = extract_uuids(@from_yaml)
|
|
6
|
+
@from_db = from_db
|
|
7
|
+
@db_uuids = extract_uuids(@from_db)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def added
|
|
11
|
+
(@from_yaml - @from_db).reject do |item|
|
|
12
|
+
@db_uuids.member?(item[:uuid])
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def removed
|
|
17
|
+
(@from_db - @from_yaml).reject do |item|
|
|
18
|
+
@yaml_uuids.member?(item[:uuid])
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def updated
|
|
23
|
+
(@from_yaml - @from_db).select do |item|
|
|
24
|
+
@yaml_uuids.member?(item[:uuid]) && @db_uuids.member?(item[:uuid])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def extract_uuids(hashes)
|
|
31
|
+
hashes.map do |hash|
|
|
32
|
+
hash[:uuid]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class GdshowsdatabaseGenerator < Rails::Generators::Base
|
|
2
|
+
include Rails::Generators::Migration
|
|
3
|
+
|
|
4
|
+
@@migrations_dir = File.expand_path('../../db/migrations', __FILE__)
|
|
5
|
+
source_root @@migrations_dir
|
|
6
|
+
|
|
7
|
+
def self.next_migration_number(path)
|
|
8
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create_migration_files
|
|
12
|
+
Dir.entries(@@migrations_dir).each do |file|
|
|
13
|
+
sleep 1 #gross
|
|
14
|
+
migration_template(file, "db/migrate/#{file.sub(/\d\d\d_/, '')}") unless File.directory?(file)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
class GdshowsdatabaseUpgradeGenerator < Rails::Generators::Base
|
|
4
|
+
include Rails::Generators::Migration
|
|
5
|
+
|
|
6
|
+
@@migrations_dir = File.expand_path('../../templates', __FILE__)
|
|
7
|
+
source_root @@migrations_dir
|
|
8
|
+
|
|
9
|
+
def self.next_migration_number(path)
|
|
10
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create_update_migration_file
|
|
14
|
+
song_ref_diff = Gdshowsdb::SongRefDiff.new
|
|
15
|
+
@added_song_refs = song_ref_diff.added
|
|
16
|
+
@updated_song_refs = song_ref_diff.updated
|
|
17
|
+
@removed_song_refs = song_ref_diff.removed
|
|
18
|
+
|
|
19
|
+
@added_shows = []
|
|
20
|
+
@updated_shows = []
|
|
21
|
+
@removed_shows = []
|
|
22
|
+
@added_sets = []
|
|
23
|
+
@updated_sets = []
|
|
24
|
+
@removed_sets = []
|
|
25
|
+
@added_songs = []
|
|
26
|
+
@updated_songs = []
|
|
27
|
+
@removed_songs = []
|
|
28
|
+
(1965..1995).each do |year|
|
|
29
|
+
show_diff = Gdshowsdb::ShowDiff.new(year)
|
|
30
|
+
@added_shows.concat(show_diff.added)
|
|
31
|
+
@updated_shows.concat(show_diff.updated)
|
|
32
|
+
@removed_shows.concat(show_diff.removed)
|
|
33
|
+
|
|
34
|
+
set_diff = Gdshowsdb::SetDiff.new(year)
|
|
35
|
+
@added_sets.concat(set_diff.added)
|
|
36
|
+
@updated_sets.concat(set_diff.updated)
|
|
37
|
+
@removed_sets.concat(set_diff.removed)
|
|
38
|
+
|
|
39
|
+
song_diff = Gdshowsdb::SongDiff.new(year)
|
|
40
|
+
@added_songs.concat(song_diff.added)
|
|
41
|
+
@updated_songs.concat(song_diff.updated)
|
|
42
|
+
@removed_songs.concat(song_diff.removed)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
file = @@migrations_dir + "/update_migration.rb.erb"
|
|
46
|
+
migration_template(file, "db/migrate/update_gdshowsdb_data.rb")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'protected_attributes'
|
|
2
|
+
|
|
3
|
+
class Show < ActiveRecord::Base
|
|
4
|
+
include Extensions::UUID
|
|
5
|
+
|
|
6
|
+
has_many :show_sets, :foreign_key => :show_uuid, :primary_key => :uuid
|
|
7
|
+
has_many :song_occurences, :foreign_key => :show_uuid, :primary_key => :uuid
|
|
8
|
+
has_many :song_refs, :through => :song_occurences, :foreign_key => :show_uuid
|
|
9
|
+
|
|
10
|
+
attr_accessible :uuid, :year, :month, :day, :venue, :city, :state, :country, :position
|
|
11
|
+
|
|
12
|
+
def self.create_from(spec)
|
|
13
|
+
Show.create(spec)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.update_from(spec)
|
|
17
|
+
Show.update(spec[:uuid], spec)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.remove_from(spec)
|
|
21
|
+
Show.find_by_uuid(spec[:uuid]).delete
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.parse_date(readable_date)
|
|
25
|
+
parsed = readable_date.split('/')
|
|
26
|
+
date_hash = {year: parsed[0].to_i, month: parsed[1].to_i, day: parsed[2].to_i}
|
|
27
|
+
if(parsed.length == 4)
|
|
28
|
+
date_hash[:position] = parsed[3].to_i
|
|
29
|
+
end
|
|
30
|
+
date_hash
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def date_string(separator = "/")
|
|
34
|
+
"#{year}#{separator}#{pad month}#{separator}#{pad day}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def date_identifier
|
|
38
|
+
if(position)
|
|
39
|
+
date_string + "/#{position}"
|
|
40
|
+
else
|
|
41
|
+
date_string
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def title
|
|
46
|
+
"#{date_string} #{venue}, #{city}, #{state}, #{country}"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def to_s
|
|
50
|
+
title
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def pad(int)
|
|
56
|
+
"%02d" % int
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class ShowSet < ActiveRecord::Base
|
|
2
|
+
include Extensions::UUID
|
|
3
|
+
|
|
4
|
+
has_many :songs, :foreign_key => :show_set_uuid, :primary_key => :uuid
|
|
5
|
+
belongs_to :show, :foreign_key => :show_uuid, :primary_key => :uuid
|
|
6
|
+
accepts_nested_attributes_for :songs
|
|
7
|
+
|
|
8
|
+
attr_accessible :uuid, :show_uuid, :position, :encore
|
|
9
|
+
|
|
10
|
+
def self.create_from(spec)
|
|
11
|
+
ShowSet.create(spec) do |show_set|
|
|
12
|
+
show_set.show = Show.find_by_uuid(spec[:show_uuid])
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.update_from(spec)
|
|
17
|
+
ShowSet.update(spec[:uuid], spec) do |show_set|
|
|
18
|
+
show_set.show = Show.find_by_uuid(spec[:show_uuid])
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.remove_from(spec)
|
|
23
|
+
ShowSet.find_by_uuid(spec[:uuid]).delete
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.find_all_by_year(year)
|
|
27
|
+
ShowSet.joins(:show).where('shows.year = ?', year)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.encore?(sets, set)
|
|
31
|
+
return false unless sets
|
|
32
|
+
last = (sets.size - 1) == sets.index(set)
|
|
33
|
+
song_size = set[:songs].size
|
|
34
|
+
song_size < 3 && last
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def encore?
|
|
38
|
+
encore
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
class Song < ActiveRecord::Base
|
|
2
|
+
include Extensions::UUID
|
|
3
|
+
|
|
4
|
+
belongs_to :show_set, :foreign_key => :show_set_uuid, :primary_key => :uuid
|
|
5
|
+
belongs_to :song_ref, :foreign_key => :song_ref_uuid, :primary_key => :uuid
|
|
6
|
+
|
|
7
|
+
attr_accessible :uuid, :song_ref_uuid, :show_set_uuid, :show_set, :position, :segued
|
|
8
|
+
|
|
9
|
+
def self.create_from(spec)
|
|
10
|
+
Song.create(remove_name(spec)) do |song|
|
|
11
|
+
song.show_set = ShowSet.find_by_uuid(spec[:show_set_uuid])
|
|
12
|
+
end
|
|
13
|
+
create_song_relationships(spec)
|
|
14
|
+
Song.find_by_uuid(spec[:uuid])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.create_song_relationships(spec)
|
|
18
|
+
song_ref = SongRef.find_by_name(spec[:name])
|
|
19
|
+
song_ref.songs << Song.find_by_uuid(spec[:uuid])
|
|
20
|
+
|
|
21
|
+
song_ref.song_occurences.create(uuid: SecureRandom.uuid, position: spec[:position]) do |occurence|
|
|
22
|
+
occurence.show = ShowSet.find_by_uuid(spec[:show_set_uuid]).show
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.update_from(spec)
|
|
27
|
+
read_song = Song.find_by_uuid(spec[:uuid])
|
|
28
|
+
read_song.show_set = ShowSet.find_by_uuid(spec[:show_set_uuid])
|
|
29
|
+
read_song.update(remove_name(spec))
|
|
30
|
+
Song.find_by_uuid(spec[:uuid])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.update_song_relationships(spec)
|
|
34
|
+
remove_song_relationships(spec)
|
|
35
|
+
create_song_relationships(spec)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.remove_from(spec)
|
|
39
|
+
remove_song_relationships(spec)
|
|
40
|
+
Song.find_by_uuid(spec[:uuid]).delete
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.remove_song_relationships(spec)
|
|
44
|
+
song_ref = SongRef.find_by_name(spec[:name])
|
|
45
|
+
song_ref.songs.delete(Song.find_by_uuid(spec[:uuid]))
|
|
46
|
+
show_set = ShowSet.find_by_uuid(spec[:show_set_uuid])
|
|
47
|
+
|
|
48
|
+
if show_set.nil?
|
|
49
|
+
puts "%%%%%%%%%%%%%%%%%%%%%"
|
|
50
|
+
puts spec.inspect
|
|
51
|
+
puts spec[:show_set_uuid]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
show = ShowSet.find_by_uuid(spec[:show_set_uuid]).show
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
song_ref.song_occurences.where('show_uuid = ? and song_ref_uuid = ?', show.uuid, song_ref.uuid).each do | occurence|
|
|
59
|
+
song_ref.song_occurences.delete(occurence)
|
|
60
|
+
occurence.delete
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.find_all_by_year(year)
|
|
65
|
+
Song.joins(:show_set => [:show]).where('shows.year = ?', year)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
def self.remove_name(spec)
|
|
70
|
+
spec.reject {|k,v| k == :name }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class SongOccurence < ActiveRecord::Base
|
|
2
|
+
include Extensions::UUID
|
|
3
|
+
|
|
4
|
+
belongs_to :show, :foreign_key => :show_uuid, :primary_key => :uuid
|
|
5
|
+
belongs_to :song_ref, :foreign_key => :song_ref_uuid, :primary_key => :uuid, :counter_cache => true
|
|
6
|
+
accepts_nested_attributes_for :show
|
|
7
|
+
|
|
8
|
+
attr_accessible :position, :uuid, :show
|
|
9
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'friendly_id'
|
|
2
|
+
|
|
3
|
+
class SongRef < ActiveRecord::Base
|
|
4
|
+
extend FriendlyId
|
|
5
|
+
include Extensions::UUID
|
|
6
|
+
|
|
7
|
+
friendly_id :slug
|
|
8
|
+
|
|
9
|
+
has_many :songs, :foreign_key => :song_ref_uuid, :primary_key => :uuid
|
|
10
|
+
has_many :song_occurences, :foreign_key => :song_ref_uuid, :primary_key => :uuid
|
|
11
|
+
has_many :shows, :through => :song_occurences, :foreign_key => :song_ref_uuid
|
|
12
|
+
|
|
13
|
+
accepts_nested_attributes_for :song_occurences
|
|
14
|
+
|
|
15
|
+
attr_accessible :uuid, :name, :slug
|
|
16
|
+
|
|
17
|
+
def self.create_from(spec)
|
|
18
|
+
SongRef.create(
|
|
19
|
+
uuid: spec[:uuid],
|
|
20
|
+
name: spec[:name],
|
|
21
|
+
slug: spec[:name].parameterize.underscore
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.update_from(spec)
|
|
26
|
+
SongRef.update(spec[:uuid], spec)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.remove_from(spec)
|
|
30
|
+
SongRef.find_by_uuid(spec[:uuid]).delete
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class SetDBExtractor
|
|
3
|
+
def self.from_db(year)
|
|
4
|
+
SetDBExtractor.new(ShowSet.find_all_by_year(year))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize(show_sets)
|
|
8
|
+
@show_sets = show_sets
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def extract
|
|
12
|
+
@show_sets.map do |show_set|
|
|
13
|
+
hash = show_set.attributes.convert_to_sym
|
|
14
|
+
hash[:show_uuid] = show_set.show.uuid
|
|
15
|
+
hash
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class SetYAMLParser
|
|
3
|
+
def self.from_yaml(year)
|
|
4
|
+
SetYAMLParser.new(Gdshowsdb.load_yaml_for_year(year))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize(show_list)
|
|
8
|
+
@show_list = show_list
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def parse
|
|
12
|
+
parsed_sets = []
|
|
13
|
+
|
|
14
|
+
@show_list.each do |show_date, show|
|
|
15
|
+
sets = show[:sets]
|
|
16
|
+
if sets && !sets.empty?
|
|
17
|
+
sets.each_with_index do |set, i|
|
|
18
|
+
parsed_sets.push(
|
|
19
|
+
{uuid: set[:uuid], show_uuid: show[:uuid], position: i, encore: ShowSet.encore?(sets, set)}
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
parsed_sets
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class ShowDBExtractor
|
|
3
|
+
def self.from_db(year)
|
|
4
|
+
ShowDBExtractor.new(Show.find_all_by_year(year))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize(shows)
|
|
8
|
+
@shows = shows
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def extract
|
|
12
|
+
@shows.map do |show|
|
|
13
|
+
show.attributes.convert_to_sym.reject do |k,v|
|
|
14
|
+
k == :position and show.position == nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
module Gdshowsdb
|
|
4
|
+
class ShowDiff < Gdshowsdb::Diff
|
|
5
|
+
def initialize(year)
|
|
6
|
+
show_yaml_parser = ShowYAMLParser.from_yaml(year)
|
|
7
|
+
show_db_extractor = ShowDBExtractor.from_db(year)
|
|
8
|
+
|
|
9
|
+
super(show_yaml_parser.parse, show_db_extractor.extract)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class ShowYAMLParser
|
|
3
|
+
def self.from_yaml(year)
|
|
4
|
+
ShowYAMLParser.new(Gdshowsdb.load_yaml_for_year(year))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize(shows)
|
|
8
|
+
@shows = shows
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def parse
|
|
12
|
+
parsed = []
|
|
13
|
+
@shows.each do |key, value|
|
|
14
|
+
date_info = Show.parse_date(key)
|
|
15
|
+
parsed.push(date_info.merge({uuid: value[:uuid], venue: value[:venue], city: value[:city], state: value[:state], country: value[:country]}))
|
|
16
|
+
end
|
|
17
|
+
parsed
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class SongDBExtractor
|
|
3
|
+
def self.from_db(year)
|
|
4
|
+
SongDBExtractor.new(Song.find_all_by_year(year))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize(songs)
|
|
8
|
+
@songs = songs
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def extract
|
|
12
|
+
@songs.map do |song|
|
|
13
|
+
song_map = song.attributes.convert_to_sym
|
|
14
|
+
song_map[:name] = song.song_ref.name if song.song_ref
|
|
15
|
+
song_map.reject {|k,v| k == :song_ref_uuid }
|
|
16
|
+
end.reject do |song_map|
|
|
17
|
+
song_map[:name].nil?
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class SongRefDBExtractor
|
|
3
|
+
def self.from_db
|
|
4
|
+
raw_db = SongRef.find(:all, order: :name)
|
|
5
|
+
Gdshowsdb::SongRefDBExtractor.new(raw_db)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def initialize(song_ref_list)
|
|
9
|
+
@song_ref_list = song_ref_list
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def extract
|
|
13
|
+
@song_ref_list.map do |song_ref|
|
|
14
|
+
song_ref.attributes.convert_to_sym.reject {|k,v| k == :slug || k == :song_occurences_count }
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
module Gdshowsdb
|
|
4
|
+
class SongRefDiff < Gdshowsdb::Diff
|
|
5
|
+
def initialize
|
|
6
|
+
song_ref_yaml_parser = SongRefYAMLParser.from_yaml
|
|
7
|
+
song_ref_db_extractor = SongRefDBExtractor.from_db
|
|
8
|
+
|
|
9
|
+
super(song_ref_yaml_parser.parse, song_ref_db_extractor.extract)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class SongRefYAMLParser
|
|
3
|
+
def self.from_yaml
|
|
4
|
+
SongRefYAMLParser.new(Gdshowsdb.load_yaml('song_refs.yaml'))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize(song_ref_list)
|
|
8
|
+
@song_ref_list = song_ref_list
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def parse
|
|
12
|
+
@song_ref_list.map do |song_ref|
|
|
13
|
+
key = song_ref.keys.first
|
|
14
|
+
value = song_ref[key]
|
|
15
|
+
{ uuid: value, name: key }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Gdshowsdb
|
|
2
|
+
class SongYAMLParser
|
|
3
|
+
def self.from_yaml(year)
|
|
4
|
+
SongYAMLParser.new(Gdshowsdb.load_yaml_for_year(year))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize(shows)
|
|
8
|
+
@shows = shows
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def parse
|
|
12
|
+
parsed = []
|
|
13
|
+
@shows.each do |key, value|
|
|
14
|
+
sets = value[:sets]
|
|
15
|
+
sets.each do |set|
|
|
16
|
+
songs = set[:songs]
|
|
17
|
+
songs.each_with_index do |song, i|
|
|
18
|
+
parsed << song.merge({position: i, show_set_uuid: set[:uuid]})
|
|
19
|
+
end if songs
|
|
20
|
+
end if sets
|
|
21
|
+
end
|
|
22
|
+
parsed
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class UpdateGdshowsdbData < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
# added song_refs <% @added_song_refs.each do |song_ref_spec| %>
|
|
4
|
+
SongRef.create_from(<%= song_ref_spec.inspect %>)
|
|
5
|
+
<% end %>
|
|
6
|
+
|
|
7
|
+
# added shows <% @added_shows.each do |show_spec| %>
|
|
8
|
+
Show.create_from(<%= show_spec.inspect %>)
|
|
9
|
+
<% end %>
|
|
10
|
+
|
|
11
|
+
# added sets <% @added_sets.each do |set_spec| %>
|
|
12
|
+
ShowSet.create_from(<%= set_spec.inspect %>)
|
|
13
|
+
<% end %>
|
|
14
|
+
|
|
15
|
+
# added songs <% @added_songs.each do |set_spec| %>
|
|
16
|
+
Song.create_from(<%= set_spec.inspect %>)
|
|
17
|
+
<% end %>
|
|
18
|
+
|
|
19
|
+
# updated song_refs <% @updated_song_refs.each do |song_ref_spec| %>
|
|
20
|
+
SongRef.update_from(<%= song_ref_spec.inspect %>)
|
|
21
|
+
<% end %>
|
|
22
|
+
|
|
23
|
+
# updated songs <% @updated_songs.each do |song_spec| %>
|
|
24
|
+
Song.update_from(<%= song_spec.inspect %>)
|
|
25
|
+
<% end %>
|
|
26
|
+
|
|
27
|
+
# updated sets <% @updated_sets.each do |set_spec| %>
|
|
28
|
+
ShowSet.update_from(<%= set_spec.inspect %>)
|
|
29
|
+
<% end %>
|
|
30
|
+
|
|
31
|
+
# updated shows <% @updated_shows.each do |show_spec| %>
|
|
32
|
+
Show.update_from(<%= show_spec.inspect %>)
|
|
33
|
+
<% end %>
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# removed songs <% @removed_songs.each do |song_spec| %>
|
|
37
|
+
Song.remove_from(<%= song_spec.inspect %>)
|
|
38
|
+
<% end %>
|
|
39
|
+
|
|
40
|
+
# removed sets <% @removed_sets.each do |set_spec| %>
|
|
41
|
+
ShowSet.remove_from(<%= set_spec.inspect %>)
|
|
42
|
+
<% end %>
|
|
43
|
+
|
|
44
|
+
# removed shows <% @removed_shows.each do |show_spec| %>
|
|
45
|
+
Show.remove_from(<%= show_spec.inspect %>)
|
|
46
|
+
<% end %>
|
|
47
|
+
|
|
48
|
+
# removed song_refs <% @removed_song_refs.each do |song_ref_spec| %>
|
|
49
|
+
SongRef.remove_from(<%= song_ref_spec.inspect %>)
|
|
50
|
+
<% end %>
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|