Exemple #1
0
def advanced_statistics():
    (yearmin, yearmax, ctrlist) = (1500, 2020, '')
    config = configuration()
    handles = []

    if request.args.get('handle'):
        handledataset = request.args.get('handle')
	handledataset = handledataset.replace(" ", '')

    if request.args.get('dataset'):
        dataset = request.args.get('dataset')
        handles.append(dataset)

    if request.args.get('yearmin'):
        yearmin = request.args.get('yearmin')
    if request.args.get('yearmax'):
        yearmax = request.args.get('yearmax')
    if request.args.get('ctrlist'):
        ctrlist = request.args.get('ctrlist')

    modern = moderncodes(config['modernnames'], config['apiroot'])
    jsonapi = config['apiroot'] + '/api/datasets?handle=' + str(handledataset)

    (panel, cleanedpanel, names) = loadpanel(jsonapi, yearmin, yearmax, ctrlist)
    (header, data, countries, handles, vhandles) = advpanel2dict(cleanedpanel)

    ctrlimit = 200
    #result = panel2csv(header, data, thisyear, countries, handles, vhandles, ctrlimit, modern)
    #maindataframe = data2statistics(handles, cleanedpanel)
    #showhtml = statistics_tojson(maindataframe, modern)
    data = handle2statistics(handles, cleanedpanel)
    showhtml = statistics2table(data)
    return showhtml
Exemple #2
0
def advanced_statistics():
    (yearmin, yearmax, ctrlist) = (1500, 2020, '')
    config = configuration()
    handles = []

    if request.args.get('handle'):
        handledataset = request.args.get('handle')
        handledataset = handledataset.replace(" ", '')

    if request.args.get('dataset'):
        dataset = request.args.get('dataset')
        handles.append(dataset)

    if request.args.get('yearmin'):
        yearmin = request.args.get('yearmin')
    if request.args.get('yearmax'):
        yearmax = request.args.get('yearmax')
    if request.args.get('ctrlist'):
        ctrlist = request.args.get('ctrlist')

    modern = moderncodes(config['modernnames'], config['apiroot'])
    jsonapi = config['apiroot'] + '/api/datasets?handle=' + str(handledataset)

    (panel, cleanedpanel, names) = loadpanel(jsonapi, yearmin, yearmax,
                                             ctrlist)
    (header, data, countries, handles, vhandles) = advpanel2dict(cleanedpanel)

    ctrlimit = 200
    #result = panel2csv(header, data, thisyear, countries, handles, vhandles, ctrlimit, modern)
    #maindataframe = data2statistics(handles, cleanedpanel)
    #showhtml = statistics_tojson(maindataframe, modern)
    data = handle2statistics(handles, cleanedpanel)
    showhtml = statistics2table(data)
    return showhtml
def advanced_statistics():
    handle = 'Panel[%27hdl%3A10622/4X6NCK%27%2C%20%27hdl%3A10622/I0YK5M%27%2C%20%27hdl%3A10622/ZWRBOY%27]'
    handle = "Panel['hdl:10622/4X6NCK', 'hdl:10622/F16UDU', 'hdl:10622/I0YK5M']"
    handle = handle.replace(" ", '')
    print handle
    yearmin = '1990'
    yearmax = '2010'
    ctrlist = ''
    ctrlist = '250,276'
    config = configuration()
    modern = moderncodes(config['modernnames'], config['apiroot'])
    jsonapi = config['apiroot'] + '/api/datasets?handle=' + str(handle)

    (panel, cleanedpanel) = loadpanel(jsonapi, yearmin, yearmax, ctrlist)
    (header, data, countries, handles, vhandles) = advpanel2dict(cleanedpanel)           
    
    ctrlimit = 200
    #result = panel2csv(header, data, thisyear, countries, handles, vhandles, ctrlimit, modern)
    maindataframe = data2statistics(handles, cleanedpanel)
    showhtml = statistics_tojson(maindataframe, modern)
    return showhtml
def advanced_statistics():
    handle = 'Panel[%27hdl%3A10622/4X6NCK%27%2C%20%27hdl%3A10622/I0YK5M%27%2C%20%27hdl%3A10622/ZWRBOY%27]'
    handle = "Panel['hdl:10622/4X6NCK', 'hdl:10622/F16UDU', 'hdl:10622/I0YK5M']"
    handle = handle.replace(" ", '')
    print handle
    yearmin = '1990'
    yearmax = '2010'
    ctrlist = ''
    ctrlist = '250,276'
    config = configuration()
    modern = moderncodes(config['modernnames'], config['apiroot'])
    jsonapi = config['apiroot'] + '/api/datasets?handle=' + str(handle)

    (panel, cleanedpanel) = loadpanel(jsonapi, yearmin, yearmax, ctrlist)
    (header, data, countries, handles, vhandles) = advpanel2dict(cleanedpanel)

    ctrlimit = 200
    #result = panel2csv(header, data, thisyear, countries, handles, vhandles, ctrlimit, modern)
    maindataframe = data2statistics(handles, cleanedpanel)
    showhtml = statistics_tojson(maindataframe, modern)
    return showhtml
Exemple #5
0
            cdata = []
        
        cdata.append(i)
        countries[code] = cdata
        rcodes[code] = i
        i = i +1

    panelout = {}
    header = 'Country,'
    for handle in handles:
        header = header + str(handle) + ','
    header = header + str('Year')
    
    return (header, data, countries, handles, vhandles) 
        
panel = test_stats()
if panel:
    totalpanel = pd.concat(panel)
    cleanedpanel = totalpanel.dropna(axis=1, how='any')
    cleanedpanel = totalpanel

thisyear = 2010
config = configuration()
modern = moderncodes(config['modernnames'], config['apiroot'])
(header, data, countries, handles, vhandles) = panel2dict(cleanedpanel)           
ctrlimit = 200
result = panel2csv(header, data, thisyear, countries, handles, vhandles, ctrlimit, modern)
maindataframe = data2statistics(handles, cleanedpanel)
showhtml = statistics_tojson(maindataframe, modern)
print showhtml
        cdata.append(i)
        countries[code] = cdata
        rcodes[code] = i
        i = i + 1

    panelout = {}
    header = "Country,"
    for handle in handles:
        header = header + str(handle) + ","
    header = header + str("Year")

    return (header, data, countries, handles, vhandles)


panel = test_stats()
if panel:
    totalpanel = pd.concat(panel)
    cleanedpanel = totalpanel.dropna(axis=1, how="any")
    cleanedpanel = totalpanel

thisyear = 2010
config = configuration()
modern = moderncodes(config["modernnames"], config["apiroot"])
(header, data, countries, handles, vhandles) = panel2dict(cleanedpanel)
ctrlimit = 200
result = panel2csv(header, data, thisyear, countries, handles, vhandles, ctrlimit, modern)
maindataframe = data2statistics(handles, cleanedpanel)
showhtml = statistics_tojson(maindataframe, modern)
print showhtml
from paneldata import paneldatafilter, panel2dict, panel2csv
from tabulardata import moderncodes

config = configuration()
jsonapi = config['apiroot'] + "/api/datasets?handle=Panel[%27hdl%3A10622/4X6NCK%27%2C%20%27hdl%3A10622/F16UDU%27%2C%20%27hdl%3A10622/ZWRBOY]"
#hdl%3A10622/GDAO0N]"
yearmin = '1500'
yearmax = '2015'
x = ''
ctrlist = '380,250,52,850'
ctrlist = ''
result = ''
thisyear = 2010
ctrlimit = 10

modern = moderncodes(config['modernnames'], config['apiroot'])
dataframe = load_api_data(jsonapi, '')

if dataframe:
    allcodes = {}
    panel = []

    for dataitem in dataframe: 
        handle = dataitem['handle']        
        (dataset, codes) = paneldatafilter(dataitem['data'], int(yearmin), int(yearmax), ctrlist, handle)    
        if not dataset.empty:                
            panel.append(dataset)
        
    if panel:
        totalpanel = pd.concat(panel)
        cleanedpanel = totalpanel.dropna(axis=1, how='any')
Exemple #8
0
def statistics(settings=''):
    datafilter = {}
    (yearmin, yearmax, ctrlist, histo) = ('1500', '2020', '', '')
    datafilter['startyear'] = yearmin
    datafilter['endyear'] = yearmax
    datafilter['ctrlist'] = ''
    config = configuration()
    if config['error']:
        return config['error']

    handles = []

    if request.args.get('handle'):
        handledataset = request.args.get('handle')
        handledataset = handledataset.replace(" ", '')
	panelcheck = re.search(r'Panel', handledataset)
	if not panelcheck:
	    handles.append(handledataset)
            handledataset = "Panel[" + handledataset + "]"
	else:
	    (handles, pidslist) = pidfrompanel(handledataset)

    if request.args.get('dataset'):
        dataset = request.args.get('dataset')
        handles.append(dataset)

    if request.args.get('hist'):
	histo = 'on'
    if request.args.get('yearmin'):
        yearmin = request.args.get('yearmin')
	datafilter['startyear'] = yearmin
    if request.args.get('yearmax'):
        yearmax = request.args.get('yearmax')
	datafilter['endyear'] = yearmax
    if request.args.get('ctrlist'):
        ctrlist = request.args.get('ctrlist')
	datafilter['ctrlist'] = ctrlist	

    old = ''
    (names, cleanedpanel) = ({}, [])
    for handle in handles:
        names[handle] = str(handle)

    if old:
        modern = moderncodes(config['modernnames'], config['apiroot'])
        jsonapi = config['apiroot'] + '/api/datasets?handle=' + str(handledataset)

        (panel, cleanedpanel, names) = loadpanel(jsonapi, yearmin, yearmax, ctrlist)
    else:
	if histo:
	    switch = 'historical'
	    loadgeo = 'geocoder'
	else:
            switch = 'modern'
	    loadgeo = ''

	geolist = {}
	(geocoder, geolist, oecd2webmapper, modern, historical) = request_geocoder(config, loadgeo)
        (origdata, maindata, metadata) = request_datasets(config, switch, modern, historical, handles, geolist)
        (subsets, panel) = ({}, [])
	for handle in handles:
            (datasubset, ctrlist) = datasetfilter(maindata[handle], datafilter)
            #datasubset['handle'] = handle
	    meta = metadata[handle]
	    names[handle] = meta['title'] 
	    # Try to remove years columns
	    try:
	        if np.nan in datasubset.index:
	            datasubset = datasubset.drop(np.nan, axis=0)
                if str(np.nan) in datasubset.columns:
                    datasubset = datasubset.drop(np.nan, axis=1)
	    except:
		skip = 'yes'
	    # Try to remove index columns
	    try:
                if config['webmapperoecd'] in datasubset.index:
                    datasubset = datasubset.drop(config['webmapperoecd'], axis=0)
	    except:
		skip = 'yes'

            if not datasubset.empty:
		datasubset['handle'] = handle
                panel.append(datasubset)
    
            subsets[handle] = datasubset
	cleanedpanel = pd.concat(panel)

    #(header, data, countries, handles, vhandles) = advpanel2dict(cleanedpanel)
    #data = advpanel2dict(cleanedpanel)
    #return data.to_html()

    ctrlimit = 200
    data = handle2statistics(handles, cleanedpanel, names)
    showhtml = statistics2table(data)
    return showhtml