Created
April 9, 2014 11:29
-
-
Save zverok/10257649 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Twitter 364 3617 274 | |
vk.com 123 1959 150 | |
livejournal.com 0 30 1 | |
facebook.com 2 18 1 | |
diary.ru 0 10 0 | |
IRC.LV - Блоги 0 2 0 | |
Juick 0 2 0 | |
24open.ru 0 1 0 | |
Blogger.com 0 1 0 | |
other 0 9 0 | |
negative 364 123 0 2 0 0 0 0 0 0 | |
neutral 3617 1959 30 18 10 2 2 1 1 9 | |
positive 274 150 1 1 0 0 0 0 0 0 |
This file contains hidden or 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
# encoding: utf-8 | |
require 'rubygems' | |
require 'json' | |
json = %Q{ | |
{"label":["2014-01-28T00:00:00+02:00","2014-02-03T00:00:00+02:00"],"series":[{"type":"complex","title":"Twitter,negative","components":[{"type":"platform","title":"Twitter"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"Twitter,neutral","components":[{"type":"platform","title":"Twitter"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"Twitter,positive","components":[{"type":"platform","title":"Twitter"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"vk.com,negative","components":[{"type":"platform","title":"vk.com"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"vk.com,neutral","components":[{"type":"platform","title":"vk.com"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"vk.com,positive","components":[{"type":"platform","title":"vk.com"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"livejournal.com,negative","components":[{"type":"platform","title":"livejournal.com"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"livejournal.com,neutral","components":[{"type":"platform","title":"livejournal.com"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"livejournal.com,positive","components":[{"type":"platform","title":"livejournal.com"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"facebook.com,negative","components":[{"type":"platform","title":"facebook.com"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"facebook.com,neutral","components":[{"type":"platform","title":"facebook.com"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"facebook.com,positive","components":[{"type":"platform","title":"facebook.com"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"diary.ru,negative","components":[{"type":"platform","title":"diary.ru"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"diary.ru,neutral","components":[{"type":"platform","title":"diary.ru"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"diary.ru,positive","components":[{"type":"platform","title":"diary.ru"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"IRC.LV - Блоги,negative","components":[{"type":"platform","title":"IRC.LV - Блоги"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"IRC.LV - Блоги,neutral","components":[{"type":"platform","title":"IRC.LV - Блоги"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"IRC.LV - Блоги,positive","components":[{"type":"platform","title":"IRC.LV - Блоги"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"Juick,negative","components":[{"type":"platform","title":"Juick"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"Juick,neutral","components":[{"type":"platform","title":"Juick"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"Juick,positive","components":[{"type":"platform","title":"Juick"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"24open.ru,negative","components":[{"type":"platform","title":"24open.ru"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"24open.ru,neutral","components":[{"type":"platform","title":"24open.ru"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"24open.ru,positive","components":[{"type":"platform","title":"24open.ru"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"Blogger.com,negative","components":[{"type":"platform","title":"Blogger.com"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"Blogger.com,neutral","components":[{"type":"platform","title":"Blogger.com"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"Blogger.com,positive","components":[{"type":"platform","title":"Blogger.com"},{"type":"tonality","title":"positive"}]},{"type":"complex","title":"other,negative","components":[{"type":"platform","title":"other"},{"type":"tonality","title":"negative"}]},{"type":"complex","title":"other,neutral","components":[{"type":"platform","title":"other"},{"type":"tonality","title":"neutral"}]},{"type":"complex","title":"other,positive","components":[{"type":"platform","title":"other"},{"type":"tonality","title":"positive"}]}],"current":[364,3617,274,123,1959,150,0,30,1,2,18,1,0,10,0,0,2,0,0,2,0,0,1,0,0,1,0,0,9,0],"prev":[274,2557,211,67,2554,142,7,197,2,1,120,3,2,85,1,0,1,0,0,4,0,0,0,0,1,6,0,2,147,10],"change":[90,1060,63,56,-595,8,-7,-167,-1,1,-102,-2,-2,-75,-1,0,1,0,0,-2,0,0,1,0,-1,-5,0,-2,-138,-10],"change_pct":[0.3284671532846715,0.41454829878764177,0.2985781990521327,0.835820895522388,-0.23296789350039154,0.056338028169014086,-1.0,-0.8477157360406091,-0.5,1.0,-0.85,-0.6666666666666666,-1.0,-0.8823529411764706,-1.0,0,1.0,0,0,-0.5,0,0,1,0,-1.0,-0.8333333333333334,0,-1.0,-0.9387755102040817,-1.0]} | |
} | |
data = JSON.parse(json) | |
def to_table(data, row_type) | |
data['series'].zip(data['current']). | |
group_by{|serie, num| serie['components'].detect{|c| c['type'] == row_type}['title']}. | |
map{|row_serie, row| [row_serie, row.map(&:last)].flatten} | |
end | |
def print_table(t) | |
puts t.map{|row| row.join("\t")}.join("\n") | |
end | |
print_table to_table(data, 'platform') | |
puts | |
puts | |
print_table to_table(data, 'tonality') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment