Exemple #1
0
def totalstatistics(settings=''):
    config = configuration()
    if config['error']:
        return config['error']

    handles = []

    if request.args.get('handle'):
        handledataset = request.args.get('handle')
        (dataset, revid, cliopid, clearpid) = findpid(handledataset)
        handles.append(dataset)

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

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

    html = ''
    for dataset in handles:
        jsonapi = config['apiroot'] + "/collabs/static/data/" + str(dataset) + ".json"
        data = createdata(jsonapi)
        d = data.describe()
        show = d.transpose()
        stats = show.to_html()
        html = html = stats + '<br>'

    return html
Exemple #2
0
#!/usr/bin/python

import os
import sys

sys.path.append(
    os.path.abspath(os.path.join(os.path.dirname(__file__), '../modules')))
import pandas as pd
from statistics import createdata

jsonapi = "http://clearance.sandbox.socialhistoryservices.org/collabs/static/data/dataframe27_0.json"
data = createdata(jsonapi)
d = data.describe()
show = d.transpose()
print show.to_html()
#!/usr/bin/python

import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../modules')))
import pandas as pd
from statistics import createdata

jsonapi = "http://clearance.sandbox.socialhistoryservices.org/collabs/static/data/dataframe27_0.json"
data = createdata(jsonapi)
d = data.describe()
show = d.transpose()
print show.to_html()
Exemple #4
0
def dashboard(settings=''):
    activepage = 'Dashboard'
    config = configuration()
    if config['error']:
        return config['error']

    apiroot = config['apiroot']
    dataverseroot = config['dataverseroot']
    key = config['key']
    tabnum = '' 
    ctrnum = 0
    if not tabnum:
	tabnum = 3 # tabs with maps is default
    logscale = ''

    if config['perl']:
	perlbin = config['perl'] + ' '
    else:
        perlbin = "/usr/bin/perl "
    path = config['path']

    # Default parameters
    (datatitle, validate, topic, citation, cliopid, stats, fileid, clearpid) = ('', '', '', '', '', '', '', '')
    (handle, fromyear, toyear) = ('', 1500, 2012)
    (selectedcountries, selectedindicators) = ('', '')

    # Variables from dashboard
    varproject = request.args.get('project')
    varbase = request.args.get('base')
    dataset = request.args.get('dataset')
    # Log scales switch
    if request.args.get('logscale'):
        logscale = 1

    if request.args.get('pid'):
	dataset = request.args.get('pid')
    if dataset:
	(handle, revid, cliopid, clearpid) = findpid(dataset)

    action = request.args.get('action')
    year = request.args.get('year')
    hist = request.args.get('hist')
    if request.args.get('yearmin'):
        fromyear = request.args.get('yearmin')
    if request.args.get('yearmax'):
        toyear = request.args.get('yearmax')
    if request.args.get('y[min]'):
        fromyear = request.args.get('y[min]')
    if request.args.get('y[max]'):
        toyear = request.args.get('y[max]')
    # Select countries
    customcountrycodes = ''
    f = request.args
    for key in f.keys():
        if key == 'loc':
            for value in sorted(f.getlist(key)):
                customcountrycodes = str(customcountrycodes) + str(value) + ','
		ctrnum = ctrnum + 1
    if customcountrycodes:
        customcountrycodes = customcountrycodes[:-1]

    # Requests from Drupal
    fromdrupal = 0
    for key in f.keys():
        if is_location(key):
            for value in sorted(f.getlist(key)):
                customcountrycodes = str(customcountrycodes) + str(value) + ','
		fromdrupal = 1

    if fromdrupal:
        if customcountrycodes:
            customcountrycodes = customcountrycodes[:-1]

    template = "dashboard.html"

    # Load topics and locations
     
    api1 = apiroot + "/collabs/static/data/dataframe100_0.json"
    branch = config['branch']
    indicatorlist = load_alltopics(api1, branch)
    api2 = apiroot + "/collabs/static/data/dataframe94_0.json"
    locations = load_locations(api2)
    api3 = apiroot + "/collabs/static/data/historical.json"
    historical = load_historical(api3)
    if hist:
	locations = historical

    try:
        (dataversemeta, pid, fileid, cliopid) = load_metadata(dataset)
        for item in dataversemeta:
            citation = 'Suggested citation: ' + str(item['citation'])
            datatitle = str(item['name'])
            topic = item['topic']
    except:
        title = dataset

    if action == 'chart':
	template = 'chart.html'
    if action == 'map':
	template = 'worldmap.html'
    if action == 'validate':
	validate = 'yes'
	template = 'validate.html'
	template = 'simplechart.html'
    if action == 'geocoder':
	template = 'geocoder.html'
    if action == 'visualize':
	template = 'navigation.html'
	# DEB
 	jsonapi = apiroot + "/collabs/static/data/" + str(pid) + ".json"
	data = createdata(jsonapi)
	d = data.describe()
	show = d.transpose()
	stats = show.to_html()

    benforddata = ''
    datasetfile = ''
 
    try:
        benforddata = benford(dataset, year, '') 
    except:
	donothing = 1

    valtitle = ''
    if validate:
	# VALIDATION
	return 'Dataset not updated'
	cmd = path + "/../../bin/import.py -d '" + dataverseroot + "' -H '" + dataset + "'"
        p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
        maincontent = p.communicate()[0]
	valtitle = maincontent
	return 'Dataset updated'

    if benforddata:
	title = benforddata
	datasetfile = benforddata
    else:
	# Clio dataset
	try:
            cmd = perlbin + path + "/../../bin/api2data.pl " + dataset
            p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
            maincontent = p.communicate()[0]
            title = "World Data Strikes, 1927-2009"
            datasetfile = maincontent
	except:
	    donothing = 1

    datasetfile = valtitle
    if datatitle:
	title = datatitle
    if customcountrycodes:
	selectedcountries = customcountrycodes
    if dataset:
	selectedindicators = "\"" + dataset + "\""
    cliopids = cliopid

    # Choose tab
    if ctrnum <= 10:
	if ctrnum > 0:
	    tabnum = 0

    resp = make_response(render_template(template, active=activepage, pages=pages, title=title, datasetfile=datasetfile, dataset=dataset, stats=stats, topic=topic, citation=citation, cliopid=cliopid, indicatorlist=indicatorlist, locations=locations, fromyear=fromyear, toyear=toyear, customcountrycodes=customcountrycodes, handle=handle, selectedcountries=selectedcountries, selectedindicators=selectedindicators, cliopids=cliopids, logscale=logscale, tabnum=tabnum))
    return resp