VRFS-3936 mobile jtx json formating

This commit is contained in:
Jonathan Kolyer 2017-05-26 12:42:18 -07:00
parent f07465f372
commit f04e0b0c8c
2 changed files with 59 additions and 60 deletions

View File

@ -31,7 +31,7 @@ gem 'pg_migrate', '0.1.14'
#gem 'paypal-sdk-rest'
gem 'paypal-sdk-merchant-jk', '1.118.1'
gem 'kickbox'
gem 'oj', '2.10.2'
gem 'oj' # '2.10.2'
gem 'builder'
gem 'jquery-rails'
gem 'jquery-ui-rails', '4.2.1'
@ -95,7 +95,7 @@ gem 'resque_mailer'
gem 'netaddr'
gem 'quiet_assets', :group => :development
gem 'bugsnag'
gem 'multi_json', '1.9.0'
gem 'multi_json' #, '1.9.0'
gem 'rest-client'
gem 'iso-639'
gem 'language_list'
@ -153,7 +153,7 @@ group :development, :test do
gem 'test-unit'
# gem 'teaspoon'
# gem 'teaspoon-jasmine'
# gem 'puma'
gem 'puma'
gem 'byebug'
end
group :unix do
@ -189,7 +189,7 @@ group :test, :cucumber do
gem 'poltergeist'
gem 'resque_spec'
gem 'timecop'
#gem 'thin'
# gem 'thin'
end

View File

@ -18,43 +18,40 @@ namespace :mobile do
end
jtx_json = {
jtx_data: [],
jtx_indices: {
alphanum: {
A: [],
B: [],
C: [],
D: [],
E: [],
F: [],
G: [],
H: [],
I: [],
J: [],
K: [],
L: [],
M: [],
N: [],
O: [],
P: [],
Q: [],
R: [],
S: [],
T: [],
U: [],
V: [],
W: [],
X: [],
Y: [],
Z: [],
'#': [],
},
artist: {},
}
jtx_data_map: {},
artist_sections: {
},
alphanum_sections: {
'#': [],
A: [],
B: [],
C: [],
D: [],
E: [],
F: [],
G: [],
H: [],
I: [],
J: [],
K: [],
L: [],
M: [],
N: [],
O: [],
P: [],
Q: [],
R: [],
S: [],
T: [],
U: [],
V: [],
W: [],
X: [],
Y: [],
Z: [],
},
}
indices = jtx_json[:jtx_indices]
CSV.foreach(tmp_fname) do |row|
jtartist = row[0]
jtname = row[1]
@ -73,45 +70,47 @@ namespace :mobile do
plan_code: jt.plan_code,
year: jt.year
}
# jtx_json[:jtx_data] << jtdata
jtx_json[:jtx_data_map][jt.id] = jtdata
first_char = jtartist[0].upcase
if (1..9) === first_char.to_i || '0' == first_char
indices[:alphanum][:'#'] << jtdata
jtx_json[:alphanum_sections][:'#'] << jt.id
else
aa = indices[:alphanum][first_char.to_sym]
indices[:alphanum][first_char.to_sym] = aa = [] unless aa
aa << jtdata
jtx_json[:alphanum_sections][first_char.to_sym] << jt.id
end
idx_artist = indices[:artist][jtartist]
idx_artist = jtx_json[:artist_sections][jtartist]
unless idx_artist
idx_artist = []
indices[:artist][jtartist] = idx_artist
jtx_json[:artist_sections][jtartist] = idx_artist
end
idx_artist << jtdata
idx_artist << jt.id
end
alphanum = indices[:alphanum]
songs = []
alphanum.keys.sort.each do |key|
songs << { key: key, data: alphanum[key] }
new_sections = {}
jtx_json[:alphanum_sections].each do |key, val|
new_key = "#{key} (#{val.count})"
new_sections[new_key] = val
end
jtx_json[:alphanum_sections] = new_sections
jtx_json[:alphanum_section_idx] = new_sections.keys.collect do |key|
{ title: key, data: [] }
end
indices[:alphanum] = songs
artists = indices[:artist]
artists_new = []
artists.keys.sort.each do |key|
artists_new << { key: key, data: artists[key] }
new_sections = {}
jtx_json[:artist_sections].each do |key, val|
new_key = "#{key} (#{val.count})"
new_sections[new_key] = val
end
jtx_json[:artist_sections] = new_sections
jtx_json[:artist_section_idx] = new_sections.keys.collect do |key|
{ title: key, data: [] }
end
indices[:artist] = artists_new
File.open("#{Rails.root}/tmp/jtx_indices.json", 'w') do |ff|
ff.write jtx_json.to_json
end
# puts jtx_json.to_json
end # task
end # namespace