Esempio n. 1
0
def test(uri, filename):
    json_string = jsonstat.download(uri, filename)

    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    print("*** multiple datasets info")
    print(collection)

    oecd = collection.dataset('oecd')
    print("\n*** dataset {} info".format(oecd.name))
    print(oecd)

    for d in oecd.dimensions():
        print("\n*** info for dimensions '{}'".format(d.did))
        print(d)

    print("\n*** value oecd(area:IT,year:2012): {}".format(oecd.data(area='IT', year='2012')))

    print("\ngenerate all vec")
    oecd.generate_all_vec(area='CA')

    df = oecd.to_data_frame('year', content='id', blocked_dims={'area': 'CA'})
    print(df)

    table = oecd.to_table()
Esempio n. 2
0
def test(uri, filename):
    json_string = jsonstat.download(uri, filename)

    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    print("*** multiple datasets info")
    print(collection)

    oecd = collection.dataset('oecd')
    print("\n*** dataset {} info".format(oecd.name))
    print(oecd)

    for d in oecd.dimensions():
        print("\n*** info for dimensions '{}'".format(d.did))
        print(d)

    print("\n*** value oecd(area:IT,year:2012): {}".format(oecd.data(area='IT', year='2012')))

    print("\ngenerate all vec")
    oecd.generate_all_vec(area='CA')

    df = oecd.to_data_frame('year', content='id', blocked_dims={'area': 'CA'})
    print(df)

    table = oecd.to_table()
Esempio n. 3
0
def validate(args):
    for arg in args:
        if arg.startswith("http"):
            print("download '{}'".format(arg))
            contents = jsonstat.download(arg)
        else:
            print("reading '{}'".format(arg))
            contents = open(arg).read()
        click.echo("validate '{}'".format(arg))
        jsonstat.validate(contents)
Esempio n. 4
0
def validate(args):
    for arg in args:
        if arg.startswith("http"):
            print("download '{}'".format(arg))
            contents = jsonstat.download(arg)
        else:
            print("reading '{}'".format(arg))
            contents = open(arg).read()
        click.echo("validate '{}'".format(arg))
        jsonstat.validate(contents)
Esempio n. 5
0
    def test_parsing_NQQ25(self):
        base_uri = 'http://www.cso.ie/StatbankServices/StatbankServices.svc/jsonservice/responseinstance/'
        uri = base_uri + "NQQ25"
        filename = "cso_ie-NQQ25.json"

        json_string = jsonstat.download(uri, os.path.join(self.fixture_dir, filename))
        collection = jsonstat.JsonStatCollection()
        collection.from_string(json_string)

        # extract dataset contained into collection
        ds = collection.dataset(0)
        self.assertIsNotNone(ds.dimension('Sector'))

        data = ds.data(0)
        self.assertEqual(19960, data.value)
Esempio n. 6
0
def test_parsing_NQQ25():
    base_uri = 'http://www.cso.ie/StatbankServices/StatbankServices.svc/jsonservice/responseinstance/'
    uri = base_uri + "NQQ25"
    filename = "cso_ie-NQQ25.json"

    json_string = jsonstat.download(uri, os.path.join(fixture_dir, filename))
    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    # extract dataset contained into collection
    ds = collection.dataset(0)
    assert ds.dimension('Sector') is not None

    data = ds.data(0)
    assert 19960 == data.value
Esempio n. 7
0
    def test_parsing_CIA01(self):
        base_uri = 'http://www.cso.ie/StatbankServices/StatbankServices.svc/jsonservice/responseinstance/'
        uri = base_uri + "CIA01"
        filename = "cso_ie-CIA01.json"

        json_string = jsonstat.download(uri, os.path.join(self.fixture_dir, filename))
        collection = jsonstat.JsonStatCollection()
        collection.from_string(json_string)

        # extract dataset contained into collection
        ds = collection.dataset(0)
        # print(ds)
        self.assertIsNotNone(ds.dimension('County and Region'))

        data = ds.data(0)
        self.assertEqual(41692, data.value)
Esempio n. 8
0
def test_parsing_CIA01():
    base_uri = 'http://www.cso.ie/StatbankServices/StatbankServices.svc/jsonservice/responseinstance/'
    uri = base_uri + "CIA01"
    filename = "cso_ie-CIA01.json"

    json_string = jsonstat.download(uri, os.path.join(fixture_dir, filename))
    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    # extract dataset contained into collection
    ds = collection.dataset(0)
    # print(ds)
    assert ds.dimension('County and Region') is not None

    data = ds.data(0)
    assert 41692 == data.value
Esempio n. 9
0
    def test_one_dimension(self):
        uri = 'http://data.ssb.no/api/v0/dataset/29843.json?lang=en'

        filename = "29843.json"
        json_string = jsonstat.download(uri, os.path.join(self.fixture_dir, filename))
        collection = jsonstat.JsonStatCollection()
        collection.from_string(json_string)

        # extract dataset contained into collection
        ds = collection.dataset(0)
        # ds.info()
        # ds.dimension('PKoder').info()

        # v = ds.value(PKoder="Basic chemicals", Tid="2013M07")
        # self.assertEqual(112.2, v)

        data = ds.data(PKoder="P1111", Tid="2013M07")
        self.assertEqual(112.2, data.value)
Esempio n. 10
0
def test_one_dimension():
    uri = 'http://data.ssb.no/api/v0/dataset/29843.json?lang=en'

    filename = "29843.json"
    json_string = jsonstat.download(uri, os.path.join(fixture_dir, "www.ssb.no", filename))
    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    # extract dataset contained into collection
    ds = collection.dataset(0)
    # ds.info()
    # ds.dimension('PKoder').info()

    # v = ds.value(PKoder="Basic chemicals", Tid="2013M07")
    # self.assertEqual(112.2, v)

    data = ds.data(PKoder="P1111", Tid="2013M07")
    assert 112.2 == data.value
Esempio n. 11
0
    def test_one_dimension(self):
        uri = self.base_uri + 'nama_gdp_c?precision=1&geo=IT&unit=EUR_HAB&indic_na=B1GM'

        filename = "eurostat-name_gpd_c-geo_IT.json"
        json_string = jsonstat.download(uri, os.path.join(self.fixture_dir, filename))

        # extract collection
        collection = jsonstat.JsonStatCollection()
        collection.from_string(json_string)

        # extract dataset contained into collection
        ds = collection.dataset('nama_gdp_c')
        """:type: jsonstat.JsonStatDataset"""
        self.assertEqual(69, len(ds))

        time = ds.dimension('time')
        self.assertEqual(69, len(time))

        # show some values
        data = ds.data(geo="IT", time="2011")
        self.assertEqual(26000, data.value)
Esempio n. 12
0
def test(uri, filename):
    json_string = jsonstat.download(uri, filename)
    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    print("*** multiple datasets info")
    print(collection)
    oecd = collection.dataset(0)

    print("\n*** dataset '{}' info".format(oecd.name))
    print(oecd)
    for d in oecd.dimensions():
        print("\n*** info for dimensions '{}'".format(d.did))
        print(d)

    print("\n*** value oecd(area:IT,year:2012): {}".format(oecd.data(area="IT", year="2012")))

    print("\ngenerate all vec")
    oecd.generate_all_vec(area="CA")
    df = oecd.to_data_frame("year", content="id", blocked_dims={"area": "CA"})
    print(df)
Esempio n. 13
0
def test_one_dimension():
    uri = base_uri + 'nama_gdp_c?precision=1&geo=IT&unit=EUR_HAB&indic_na=B1GM'

    filename = "eurostat-name_gpd_c-geo_IT.json"
    json_string = jsonstat.download(uri, os.path.join(fixture_dir, filename))

    # extract collection
    collection = jsonstat.JsonStatCollection()
    collection.from_string(json_string)

    # extract dataset contained into collection
    ds = collection.dataset('nama_gdp_c')
    """:type: jsonstat.JsonStatDataset"""
    assert 69 == len(ds)

    time = ds.dimension('time')
    assert 69 == len(time)

    # show some values
    data = ds.data(geo="IT", time="2011")
    assert 26000 == data.value
def llegir_indicador_world_bank(indicador):
    # Consultem via API la web del Banc Mundial.
    # La funció retorna un Panda DataFrame amb les columnes "ISO3","year","<indicador>"

    filename = os.getcwd() + "/" + indicador + ".jsonstat"
    url = "https://api.worldbank.org/v2/country/all/indicator/" + indicador + "?format=jsonstat"

    if os.path.isfile(filename):
        jstat = jsonstat.from_file(filename)
    else:
        jstat = jsonstat.from_string(jsonstat.download(url, filename))

    df = jstat.dataset(0).to_data_frame(content='id')

    df.drop(columns="series", inplace=True)
    df.rename(columns={"country": "ISO3", "Value": indicador}, inplace=True)

    # Assimilem les dades de 2018 a l'any 2019 a l'espera de la seva publicació
    j = 0
    for i in (df.loc[df.year == '2019']).index:
        df.at[i, indicador] = (df.loc[df.year == '2018', indicador]).values[j]
        j += 1

    return df
Esempio n. 15
0
@author: P.Jakobsen

From https://jsonstatpy.readthedocs.io/en/latest/notebooks/eurostat.html
"""


from __future__ import print_function
import os
import pandas as pd
import jsonstat

import matplotlib as plt

url_1 = 'http://ec.europa.eu/eurostat/wdds/rest/data/v1.1/json/en/nama_gdp_c?precision=1&geo=IT&unit=EUR_HAB&indic_na=B1GM'
file_name_1 = "eurostat-environmental-tax.json"

url_1="http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/nama_10_gdp?geo=EU28&precision=1&na_item=B1GQ&unit=CP_MEUR&time=2010&time=2011"
#url_1="http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/nama_gdp_c?precision=1&geo=IT&unit=EUR_HAB&indic_na=B1GM'"
file_path_1 = "data/"+file_name_1
if os.path.exists(file_path_1):
    print("using already donwloaded file {}".format(file_path_1))
else:
    print("download file")
    jsonstat.download(url_1, file_name_1)
    file_path_1 = file_name_1
collection_1 = jsonstat.from_file(file_path_1)
collection_1

nama_gdp_c_1 = collection_1.dataset('nama_gdp_c')
nama_gdp_c_1