Ejemplo n.º 1
0
def test_to_jsonstat_and_back(sample_cube):
    cube = sample_cube
    # Make sure we end up with same cube after converting
    # the generated jsonstat back to a cube
    js = jsonstat.to_jsonstat_dataset(cube)
    cube2 = jsonstat.to_cube(js)
    assert cube._data == cube2._data
def test_to_jsonstat_and_back(sample_cube):
	cube = sample_cube
	# Make sure we end up with same cube after converting
	# the generated jsonstat back to a cube
	js = jsonstat.to_jsonstat_dataset(cube)
	cube2 = jsonstat.to_cube(js)
	assert cube._data == cube2._data
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
Ejemplo n.º 4
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
def test_to_cube(jsonstat_sample_dataset):
	cube = jsonstat.to_cube(jsonstat_sample_dataset)
def sample_cube():
	dataset = jsonstat_sample_dataset()
	return jsonstat.to_cube(dataset)
Ejemplo n.º 7
0
def test_to_cube(jsonstat_sample_dataset):
    cube = jsonstat.to_cube(jsonstat_sample_dataset)
Ejemplo n.º 8
0
def sample_cube():
    dataset = jsonstat_sample_dataset()
    return jsonstat.to_cube(dataset)
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)
Ejemplo n.º 10
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)
import json
import urllib2
from pydatacube import jsonstat

# Load jsonstat example data and pick a dataset
# in it
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)
# Do some filtering
subcube = cube.filter(A=("1", "2"), C="4")
# And pretty printing
print cube.metadata['label']
for row in subcube:
	print("\t".join(map(str, row)))
Ejemplo n.º 12
0
import json
import urllib2
from pydatacube import jsonstat

# Load jsonstat example data and pick a dataset
# in it
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)
# Do some filtering
subcube = cube.filter(A=("1", "2"), C="4")
# And pretty printing
print cube.metadata['label']
for row in subcube:
    print("\t".join(map(str, row)))