Skip to content

Commit

Permalink
999999999_521850.py (#43): --methodus-fonti=sdmx-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Jul 29, 2022
1 parent 09541e0 commit 2e4a187
Showing 1 changed file with 87 additions and 8 deletions.
95 changes: 87 additions & 8 deletions officina/999999999/0/999999999_521850.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# OPTIONS: ---
#
# REQUIREMENTS: - python3
# - pip install xlrd
# - pip install pandasdmx
# BUGS: ---
# NOTES: ---
# AUTHORS: Emerson Rocha <rocha[at]ieee.org>
Expand Down Expand Up @@ -48,15 +50,21 @@

import requests

# try:
# from openpyxl import (
# load_workbook
# )
# except ModuleNotFoundError:
# # Error handling
# pass

try:
from openpyxl import (
load_workbook
)
import xlrd
except ModuleNotFoundError:
# Error handling
pass
try:
import xlrd
import pandasdmx as sdmx
except ModuleNotFoundError:
# Error handling
pass
Expand Down Expand Up @@ -104,6 +112,8 @@
{0} --methodus-fonti=worldbank --methodus=SP.POP.TOTL \
--objectivum-formato=hxltm
{0} --methodus-fonti=sdmx-tests
------------------------------------------------------------------------------
EXEMPLŌRUM GRATIĀ
------------------------------------------------------------------------------
Expand Down Expand Up @@ -188,6 +198,7 @@ def make_args(self):
# https://data.unhcr.org/en/geoservices/
'unwpf', # https://geonode.wfp.org/
'worldbank', # https://data.worldbank.org/
'sdmx-tests',
],
# required=True
default='undata'
Expand Down Expand Up @@ -310,6 +321,74 @@ def execute_cli(self, pyargs, stdin=STDIN, stdout=sys.stdout,
ds_worldbank.imprimere()
return self.EXIT_OK

if pyargs.methodus_fonti == 'sdmx-tests':

sdmx_wb = sdmx.Request('WB')
cat_response = sdmx_wb.categoryscheme()
print(cat_response)

print('WB all categories list')
print(sdmx.to_pandas(cat_response.category_scheme.WITS_Data))

print('')
print('')
print('')
print('WB_WDI')

sdmx_wb_wdi = sdmx.Request('WB_WDI')
cat_response = sdmx_wb_wdi.categoryscheme()
print(cat_response)

return True

estat = sdmx.Request('ESTAT')
metadata = estat.datastructure('DSD_une_rt_a')
print(metadata)

for cl in 'CL_AGE', 'CL_UNIT':
print(sdmx.to_pandas(metadata.codelist[cl]))
resp = estat.data(
'une_rt_a',
key={'GEO': 'EL+ES+IE'},
params={'startPeriod': '2007'},
)
data = resp.to_pandas(
datetime={'dim': 'TIME_PERIOD', 'freq': 'FREQ'}).xs(
'Y15-74', level='AGE', axis=1, drop_level=False)
print(data.columns.names)
print(data.columns.levels)

print(data.loc[:, ('Y15-74', 'PC_ACT', 'T')])

print('')
print('')
print('')
print('UNSD')

unsd = sdmx.Request('UNSD')
print(unsd)
# unsd = Request('UNSD')
cat_response = unsd.categoryscheme()
print(cat_response)
# https://pandasdmx.readthedocs.io/en/v1.0/howto.html#use-category-schemes-to-explore-data
print('UNSD all categories list')
print(sdmx.to_pandas(cat_response.category_scheme.UNdata_Categories))
# # print(cat_response.write().categoryscheme)
# # dsd_id = unsd.categoryscheme().dataflow.NA_MAIN.structure.id
# # dsd_response = unsd.datastructure(resource_id = dsd_id)
# print('')
# print('')
# print('')
# print('UNICEF')

# unicef = sdmx.Request('UNICEF')
# print(unicef)

# @see https://pandasdmx.readthedocs.io/en/v1.0/example.html
# @see https://pandasdmx.readthedocs.io/en/v1.0/walkthrough.html
print('TODO')
return self.EXIT_OK

print('Unknow option.')
return self.EXIT_ERROR

Expand Down Expand Up @@ -382,7 +461,7 @@ def praeparatio(self):

# pip install pandasdmx[cache]

import pandasdmx as sdmx
# import pandasdmx as sdmx
estat = sdmx.Request('ESTAT')
metadata = estat.datastructure('DSD_une_rt_a')
print(metadata)
Expand All @@ -393,10 +472,10 @@ def praeparatio(self):
'une_rt_a',
key={'GEO': 'EL+ES+IE'},
params={'startPeriod': '2007'},
)
)
data = resp.to_pandas(
datetime={'dim': 'TIME_PERIOD', 'freq': 'FREQ'}).xs('Y15-74', level='AGE',
axis=1, drop_level=False)
datetime={'dim': 'TIME_PERIOD', 'freq': 'FREQ'}).xs(
'Y15-74', level='AGE', axis=1, drop_level=False)
print(data.columns.names)
print(data.columns.levels)

Expand Down

0 comments on commit 2e4a187

Please sign in to comment.