Last active
February 24, 2016 13:37
-
-
Save havran/46b92dcdf2d64bfef252 to your computer and use it in GitHub Desktop.
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
{ | |
"head": [ | |
{ | |
"CoType": "CoType", | |
"objects": "objects", | |
"objects_avg_quality": "objects_avg_quality" | |
} | |
], | |
"rows": [ | |
{ | |
"CoType": "2D_MUSEUM", | |
"objects": 162.0, | |
"objects_avg_quality": 0.382777777902874 | |
}, | |
{ | |
"CoType": "3D_S_DEVICE", | |
"objects": 17.0, | |
"objects_avg_quality": 0.410000006065649 | |
}, | |
{ | |
"CoType": "3D_S_DRESS", | |
"objects": 17.0, | |
"objects_avg_quality": 0.291764703743598 | |
}, | |
{ | |
"CoType": "3D_S_MUSEUM", | |
"objects": 225.0, | |
"objects_avg_quality": 0.305511112146907 | |
}, | |
{ | |
"CoType": "OTHER", | |
"objects": 28.0, | |
"objects_avg_quality": 0.150000005960464 | |
}, | |
{ | |
"CoType": "OTHER_NATURAL_HERITAGE", | |
"objects": 165.0, | |
"objects_avg_quality": 0.300242426630222 | |
}, | |
{ | |
"CoType": "TEXT_PERIODICAL", | |
"objects": 1.0, | |
"objects_avg_quality": 0.600000023841858 | |
}, | |
{ | |
"sum_avg": "sum_avg", | |
"objects": 615.0, | |
"objects_avg_quality": 0.3486137223273674 | |
} | |
] | |
} |
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
{ | |
"head": { | |
"col0": "CoType", | |
"col1": "2D_MUSEUM", | |
"col2": "3D_S_DEVICE", | |
"col3": "3D_S_DRESS", | |
"col4": "3D_S_MUSEUM", | |
"col5": "OTHER", | |
"col6": "OTHER_NATURAL_HERITAGE", | |
"col7": "TEXT_PERIODICAL", | |
"col8": "sum_avg" | |
}, | |
"rows": [ | |
{ | |
"col0": "objects", | |
"col1": 162.0, | |
"col2": 17.0, | |
"col3": 17.0, | |
"col4": 225.0, | |
"col5": 28.0, | |
"col6": 165.0, | |
"col7": 1.0, | |
"col8": 615.0 | |
}, | |
{ | |
"col0": "objects_avg_quality", | |
"col1": 0.382777777902874, | |
"col2": 0.410000006065649, | |
"col3": 0.291764703743598, | |
"col4": 0.305511112146907, | |
"col5": 0.150000005960464, | |
"col6": 0.300242426630222, | |
"col7": 0.600000023841858, | |
"col8": 0.3486137223273674 | |
} | |
] | |
} |
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
def transpose(table_data) | |
data = [] | |
data = table_data[:head] + table_data[:rows] | |
col = 0 | |
data_transposed = [] | |
data.each do |h| | |
row = [] | |
h.each do |k,v| | |
row.push(["col#{col}", v]) | |
end | |
data_transposed.push(row) | |
col = col + 1 | |
end | |
table_transposed = data_transposed.transpose.map(&:to_h) | |
{ | |
head: table_transposed.shift, | |
rows: table_transposed | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment