Download pool/shard008/JavaScript/0050246_data.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard008/JavaScript/0050246_data.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard008/JavaScript/0050246_data.js
-
curl -L -o 0050246_data.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard008/JavaScript/0050246_data.js
1.26 kB
| import * as d3Fetch from 'd3-fetch' | |
| import { | |
| capitalizeFirstLetter, | |
| getImportExportSuffix | |
| } from '../helpers/helpers' | |
| const countriesLabels = { | |
| usa: 'USA', | |
| hkg: 'Hong Kong', | |
| row: 'Rest of World', | |
| china: "China's global trade surplus" | |
| } | |
| const order = ['usa', 'hkg', 'row'] | |
| async function parseData(url) { | |
| let data = await d3Fetch | |
| .csv(url, d => { | |
| for (var i in d) { | |
| d[i] = +d[i] | |
| } | |
| return d | |
| }) | |
| .then(data => { | |
| const groups = data.columns | |
| .filter(d => d !== 'year') | |
| .map(d => ({ | |
| label: countriesLabels[d.split('_')[0]], | |
| id: d, | |
| group: d.split('_')[0], | |
| type: getType(d), | |
| suffix: getImportExportSuffix(d, true) | |
| })) | |
| const sortedGroups = groups.reduce((acc, curr) => { | |
| acc[curr.type] = acc[curr.type] || [] | |
| acc[curr.type].push(curr) | |
| acc[curr.type].sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id)) | |
| return acc | |
| }, {}) | |
| let dataset = { | |
| values: data, | |
| groups: groups, | |
| sortedGroups: sortedGroups | |
| } | |
| return dataset | |
| }) | |
| return data | |
| } | |
| function getType(group) { | |
| return capitalizeFirstLetter(group.split('_')[1]) | |
| } | |
| export default parseData | |