コード例 #1
0
def test_filtered_to_jsonstat(sample_cube):
	spec = sample_cube.specification
	dimension = spec['dimensions'][0]
	category = dimension['categories'][0]
	filt = {dimension['id']: category['id']}
	filtered = sample_cube.filter(**filt)
	js = jsonstat.to_jsonstat(filtered)
	assert jsonstat.to_cube(js['dataset']) == filtered
コード例 #2
0
ファイル: test_jsonstat.py プロジェクト: jell0720/pydatacube
def test_filtered_to_jsonstat(sample_cube):
    spec = sample_cube.specification
    dimension = spec['dimensions'][0]
    category = dimension['categories'][0]
    filt = {dimension['id']: category['id']}
    filtered = sample_cube.filter(**filt)
    js = jsonstat.to_jsonstat(filtered)
    assert jsonstat.to_cube(js['dataset']) == filtered
コード例 #3
0
from pydatacube import jsonstat
import json
import urllib2
JSONSTAT_URL = "http://json-stat.org/samples/order.json"
DATASET = 'order'
data = json.load(urllib2.urlopen(JSONSTAT_URL))
dataset = data[DATASET]

# Convert to a pydatacube cube
cube = jsonstat.to_cube(dataset)
# Convert back to jsonstat
js = jsonstat.to_jsonstat(cube, dataset_name=DATASET)

# Verify that there's nothing fishy
js_again = jsonstat.to_jsonstat(jsonstat.to_cube(js[DATASET]), dataset_name=DATASET)
assert json.dumps(js) == json.dumps(js_again)

# And pretty print
print json.dumps(js, indent=4)
コード例 #4
0
from pydatacube import jsonstat
import json
import urllib2

JSONSTAT_URL = "http://json-stat.org/samples/order.json"
DATASET = 'order'
data = json.load(urllib2.urlopen(JSONSTAT_URL))
dataset = data[DATASET]

# Convert to a pydatacube cube
cube = jsonstat.to_cube(dataset)
# Convert back to jsonstat
js = jsonstat.to_jsonstat(cube, dataset_name=DATASET)

# Verify that there's nothing fishy
js_again = jsonstat.to_jsonstat(jsonstat.to_cube(js[DATASET]),
                                dataset_name=DATASET)
assert json.dumps(js) == json.dumps(js_again)

# And pretty print
print json.dumps(js, indent=4)