def dataapi(): (datafilter, handles) = ({}, []) datafilter['ctrlist'] = '' logscale = '' config = configuration() customyear = '' fromyear = '1500' toyear = '2012' categoriesMax = 6 countriesNum = 200 geocoder = '' (special, getrange, colormap, pallette, customcountrycodes, switch) = ('', '', '', '', '', 'modern') if request.args.get('special'): special = request.args.get('special') if request.args.get('logscale'): logscale = request.args.get('logscale') if request.args.get('year'): customyear = request.args.get('year') datafilter['startyear'] = customyear datafilter['endyear'] = customyear if request.args.get('catmax'): categoriesMax = int(request.args.get('catmax')) if request.args.get('getrange'): getrange = request.args.get('getrange') if request.args.get('colors'): pallette = request.args.get('colors') if request.args.get('colormap'): colormap = request.args.get('colormap') if request.args.get('geocoder'): switch = request.args.get('geocoder') if switch == 'on': switch = 'modern' if request.args.get('handle'): handlestring = request.args.get('handle') ishandle = re.search(r'(hdl:\d+\/\w+)', handlestring) if ishandle: handle = ishandle.group(1) handle = handle.replace("'", "") else: handle = handlestring handles.append(handle) if request.args.get('ctrlist'): customcountrycodes = '' tmpcustomcountrycodes = request.args.get('ctrlist') c = tmpcustomcountrycodes.split(',') for ids in sorted(c): if ids: customcountrycodes = str(customcountrycodes) + str(ids) + ',' customcountrycodes = customcountrycodes[:-1] datafilter['ctrlist'] = tmpcustomcountrycodes hist = {} config = configuration() try: if len(customcountrycodes): countriesNum = len(customcountrycodes.split(',')) if countriesNum < categoriesMax: if countriesNum >= 1: categoriesMax = countriesNum except: nothing = 1 # Old version of panel data #(header, panelcells, codes, x1, x2, x3, x4, originalvalues) = data2panel(handles, customcountrycodes, fromyear, toyear, customyear, hist, logscale) panelcells = [] # New version is fast if config: (geocoder, geolist, oecd2webmapper, modern, historical) = request_geocoder(config, '') (subsets, panel) = ({}, []) try: (origdata, maindata, metadata) = request_datasets(config, switch, modern, historical, handles, geolist) for handle in handles: (datasubset, ctrlist) = datasetfilter(maindata[handle], datafilter) if not datasubset.empty: datasubset = datasubset.dropna(how='all') panel.append(datasubset) subsets[handle] = datasubset except: subsets[handles[0]] = get_iishvisitors_frame(int(customyear)) (panelcells, originalvalues) = dataset2panel(config, subsets[handles[0]], modern, logscale) #(header, panelcells, codes, x1, x2, x3, x4, originalvalues) = data2panel(handles, customcountrycodes, fromyear, toyear, customyear, hist, logscale) #modern = moderncodes(config['modernnames'], config['apiroot']) #jsondata = data2json(modern, codes, panelcells) #data = json.dumps(jsondata, ensure_ascii=False, sort_keys=True, indent=4) # SCALES if switch: if switch == 'historical': geocoder = historical else: geocoder = modern #geocoder = '' (defaultcolor, colors) = getcolors(categoriesMax, pallette, colormap) (catlimit, ranges, dataset) = getscales(config, panelcells, colors, categoriesMax, geocoder, originalvalues, switch, logscale) if getrange: (showrange, tmprange) = combinerange(ranges) webscale = webscales(showrange, colors, defaultcolor) data = json.dumps(webscale, ensure_ascii=False, sort_keys=True, indent=4) return Response(data, mimetype='application/json') else: data = json.dumps(dataset, ensure_ascii=False, sort_keys=True, indent=4) return Response(data, mimetype='application/json')
fromyear = '1500' toyear = '2000' customcountrycodes = '380,250,276,804,174,108,232,528,756' logflag = '' hist = {} DEBUG = 0 config = configuration() if fromyear: historical = 0 if historical: api = config['apiroot'] + "/collabs/static/data/historical.json" (regions, countries, ctr2reg) = histo(api) hist = countries (header, panelcells, codes, x1, x2, x3, x4) = data2panel(handles, customcountrycodes, fromyear, toyear, customyear, hist, logflag) categoriesMax = 5 (defaultcolor, colors) = getcolors(categoriesMax, 'greyscale') (catlimit, ranges, dataset) = getscales(panelcells, colors, categoriesMax) modern = moderncodes(config['modernnames'], config['apiroot']) jsondata = data2json(modern, codes, panelcells) result = json.dumps(dataset, ensure_ascii=False, sort_keys=True, indent=4) (showrange, tmprange) = combinerange(ranges) print 'Ranges: ' + str(tmprange) print 'Dataframe:\n' + str(result)