Пример #1
0
def treemap(settings=''):
    (years, ctrlist) = ([], '')
    showpanel = 'yes'
    config = configuration()
    if config['error']:
        return config['error'] 

    (historical, handle, handles, thisyear) = ('', '', [], '')
    if request.args.get('face'):
        facehandle = request.args.get('face')
        if facehandle not in handles:
            handles.append(facehandle)
	    handle = facehandle

    if request.args.get('handle'):
        handledataset = request.args.get('handle')
        try:
            (pids, pidslist) = pidfrompanel(handledataset)
	    handle = pids[0]
            handles.append(handle)
        except:
            handles.append(handledataset)
	    handle = handledataset
            nopanel = 'yes'
    if request.args.get('historical'):
        historical = request.args.get('historical')
    if request.args.get('year'):
        thisyear = request.args.get('year')
    if request.args.get('hist'):
        historical = request.args.get('hist')
    if request.args.get('ctrlist'):
	ctrlist = request.args.get('ctrlist')
        if ctrlist == config['ctrlist']:
	    ctrlist = ''

    mainlink = '&handle=' + str(handle)
    try:
        (title, units, years) = dpemetadata(config, handle)
    except:
        (title, units, years) = ('Panel Data', '', [])

    if historical:
	mainlink = str(mainlink) + '&historical=on'
    if thisyear:
	mainlink = str(mainlink) + '&year=' + str(thisyear)
    if ctrlist:
	mainlink = str(mainlink) + '&ctrlist=' + str(ctrlist)

    links = graphlinks(mainlink)
    apitreemap = config['apiroot'] + "/api/treemap?action=showyears&handle=" + str(handles[0]) + "&ctrlist=" + str(ctrlist)
    years = load_api_data(apitreemap, 1)
    total = len(years)
    lastyear = years[-1]

    resp = make_response(render_template('treemap.html', handle=handle, chartlib=links['chartlib'], barlib=links['barlib'], panellib=links['panellib'], treemaplib=links['treemaplib'], q=handle, showpanel=showpanel, historical=historical, title=title, thisyear=thisyear, years=years, total=total, lastyear=lastyear, ctrlist=ctrlist))
    return resp
Пример #2
0
def graphlib(settings=''):
    showpanel = 'yes'
    try:
        if request.args.get('print'):
            showpanel = ''
    except:
        showpanel = 'yes'
    f = request.args
    handle = ''
    for q in f:
        value = f[q]
        if value:
            handle = str(handle) + '&' + str(q) + '=' + str(f[q])

    links = graphlinks(handle)

    resp = make_response(render_template('graphlib.html', handle=handle, chartlib=links['chartlib'], barlib=links['barlib'], panellib=links['panellib'], treemaplib=links['treemaplib'], q=handle, showpanel=showpanel))
    return resp
Пример #3
0
def panel(settings=''):
    showpanel = ''
    handle = ''
    handler = ''
    config = configuration()
    if config['error']:
        return config['error']

    f = request.args
    for q in f:
	value = f[q]
	if value:
	    handle = str(handle) + '&' + str(q) + '=' + str(f[q])
    # Default countris
    try:
        if not f['yearmin']:
	    handle = str(handle) + '&yearmin=1500&yearmax=2013'
    except:
	handle = str(handle) + '&yearmin=1500&yearmax=2013'
    try:
        if not f['ctrlist']:
	    handle = str(handle) + '&ctrlist=' + config['ctrlist'] 
    except:
	handle = str(handle) + '&ctrlist=' + config['ctrlist']
    try:
	if f['print']:
	    showpanel = ''
    except:
	showpanel = 'yes'

    try:
        (title, units, years) = dpemetadata(config, handle)
    except:
	(title, units, years) = ('Panel Data', '', [])
    links = graphlinks(handle)

    resp = make_response(render_template('panel.html', handle=handle, chartlib=links['chartlib'], barlib=links['barlib'], panellib=links['panellib'], treemaplib=links['treemaplib'], q=handle, showpanel=showpanel, title=title))
    return resp
Пример #4
0
def chartlib():
    (thismapurl, apilink, ctrlist, title, units, switch, hist) = ('', '', '', 'Title', 'Units', 'modern', '')
    handleface = []
    config = configuration()
    ctrlist = config['ctrlist']
    if config['error']:
        return config['error']

    urlmatch = re.search(r'(.+)\&face', request.url)
    try:
        if urlmatch.group(0):
            thismapurl = urlmatch.group(1)
    except:
        thismapurl = request.url
    if 'sandbox' not in thismapurl:
        thismapurl = thismapurl.replace('http://', 'https://')

    handles = []
    showpanel = 'yes'
    try:
        if request.args.get('print'):
            showpanel = ''
    except:
        showpanel = 'yes'
    f = request.args
    handle = ''
    for q in f:
        value = f[q]
        if value:
            handle = str(handle) + '&' + str(q) + '=' + str(f[q])

    if request.args.get('ctrlist'):
        ctrlist = request.args.get('ctrlist')
    if request.args.get('hist'):
	switch = 'historical'
	hist = request.args.get('hist')
    if request.args.get('handle'):
        handledataset = request.args.get('handle')
        try:
            (pids, pidslist) = pidfrompanel(handledataset)
	    handles.append(pids[0])
        except:
	    handles.append(handledataset)
            nopanel = 'yes'
	if pids[0]:
	    apilink = "/api/tabledata?handle=" + str(pids[0])
	    if ctrlist:
	        apilink = apilink + '&ctrlist=' + ctrlist
	    if request.args.get('hist'):
		apilink = apilink + '&hist=' + hist

    if request.args.get('face'):
        handles = []
        handleface = request.args.get('face')
        handles.append(handleface)
        if handleface:
	    apilink = "/api/tabledata?handle=" + str(handleface)
            if ctrlist:
                apilink = apilink + '&ctrlist=' + ctrlist
            if request.args.get('hist'):
                apilink = apilink + '&hist=' + hist
	    
        try:
            pids.remove(handleface)
        except:
            nothing = 1

    if set(pids) == set(handles):
	pids[:] = []
    links = graphlinks('&face=' + str(handles[0]) + '&hist=' + hist)
    (geocoder, geolist, oecd2webmapper, modern, historical) = request_geocoder(config, '')
    # vty hist
    (origdata, maindata, metadata) = request_datasets(config, switch, modern, historical, handles, geolist)
    try:
	title = metadata[handles[0]]['title']
	units = metadata[handles[0]]['units']
    except:
	skip = 0

    handledict = {}
    if handles:
        handle = handles[0]

    if pids:
	try:
	    if handles[1]:
	        pids.remove(handles[0])
	except:
	    skip = 1
        hquery = formdatasetquery(pids,'')
        d = readdatasets('datasets', json.loads(hquery))
        for x in d:
            thishandle = x['handle']
	    if thishandle != handle:
                handledict[thishandle] = x['title']

    resp = make_response(render_template('chartlib.html', thismapurl=thismapurl, indicators=handledict, apilink=apilink, title=title, units=units, showpanel=showpanel, handle=handle, chartlib=links['chartlib'], barlib=links['barlib'], panellib=links['panellib'], treemaplib=links['treemaplib']))
    return resp