Esempio n. 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
Esempio n. 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
Esempio n. 3
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