def stats_map(request, origin=None, source=None, date=None): stats = None if settings.STATS_SAVE_MEMORY: cache, stats = get_from_cache('default','stats_tilerequests') if settings.STATS_SAVE_FILE and not stats: stats = get_from_file(settings.STATS_REQUEST_FILE, filetype='json') dates = [] if stats: if 'by_date' in stats: dates = stats['by_date'].keys() #print stats['by_date_location'].keys() context_dict = { 'date': date, 'origins': getTileOrigins(), 'sources': getTileSources(), 'dates': dates } try: context_dict['origin'] = TileOrigin.objects.get(name=origin) except: context_dict['origin'] = None try: context_dict['source'] = TileSource.objects.get(name=source) except: context_dict['source'] = None return render_to_response( "cache/stats_map_3.html", RequestContext(request, context_dict))
def sources_json(request): now = datetime.datetime.now() dt = now ####### stats = None if settings.STATS_SAVE_MEMORY: cache, stats = get_from_cache( settings.CACHES['default']['LOCATION'], settings.CACHES['default'], 'default', 'stats_tilerequests', GEVENT_MONKEY_PATCH=settings.TILEJET_GEVENT_MONKEY_PATCH) if settings.STATS_SAVE_FILE and not stats: stats = get_from_file(settings.STATS_REQUEST_FILE, filetype='json') sources = [] #for source in TileSource.objects.all().order_by('name'): for source in getTileSources(): link_geojson = settings.SITEURL+'cache/stats/export/geojson/15/source/'+source['name']+'.geojson' link_proxy_internal = settings.SITEURL+'proxy/?url='+(source['url']).replace("{ext}","png") link_proxy_external = "" if source['type'] in [TYPE_TMS, TYPE_TMS_FLIPPED]: link_proxy_external = settings.SITEURL+'cache/proxy/tms/origin/'+source['origin']+'/source/'+source['name']+'/{z}/{x}/{y}.png' elif source['type'] == TYPE_BING: link_proxy_external = settings.SITEURL+'cache/proxy/bing/origin/'+source['origin']+'/source/'+source['name']+'{u}.png' if stats: sources.append({ 'name': source['name'], 'type': source['type_title'], 'origin': source['origin'], 'url': source['url'], 'requests_all': getValue(stats['by_source'], source['name'],0), 'requests_year': getValue(getValue(stats['by_year_source'],dt.strftime('%Y')),source['name'], 0), 'requests_month': getValue(getValue(stats['by_month_source'],dt.strftime('%Y-%m')),source['name'], 0), 'requests_today': getValue(getValue(stats['by_date_source'],dt.strftime('%Y-%m-%d')),source['name'], 0), 'link_proxy': link_proxy_internal, 'link_id': 'http://www.openstreetmap.org/edit#?background=custom:'+link_proxy_external, 'link_geojson': link_geojson, 'link_geojsonio': 'http://geojson.io/#data=data:text/x-url,'+link_geojson }) else: sources.append({ 'name': source['name'], 'type': source['type_title'], 'origin': source['origin'], 'url': source['url'], 'requests_all': -1, 'requests_year': -1, 'requests_month': -1, 'requests_today': -1, 'link_proxy': link_proxy_internal, 'link_id': 'http://www.openstreetmap.org/edit#?background=custom:'+link_proxy_external, 'link_geojson': link_geojson, 'link_geojsonio': 'http://geojson.io/#data=data:text/x-url,'+link_geojson }) return HttpResponse(json.dumps(sources), content_type="application/json" )
def origins_json(request): now = datetime.datetime.now() dt = now ####### #stats = stats_tilerequest() cache, stats = get_from_cache( settings.CACHES['default']['LOCATION'], settings.CACHES['default'], 'default', 'stats_tilerequests', GEVENT_MONKEY_PATCH=settings.TILEJET_GEVENT_MONKEY_PATCH) origins = [] for origin in TileOrigin.objects.all().order_by('name','type'): link_geojson = settings.SITEURL+'cache/stats/export/geojson/15/origin/'+origin.name+'.geojson' if stats: origins.append({ 'name': origin.name, 'description': origin.description, 'type': origin.type_title(), 'multiple': origin.multiple, 'auto': origin.auto, 'url': origin.url, 'requests_all': getValue(stats['by_origin'], origin.name,0), 'requests_year': getValue(getValue(stats['by_year_origin'],dt.strftime('%Y')),origin.name, 0), 'requests_month': getValue(getValue(stats['by_month_origin'],dt.strftime('%Y-%m')),origin.name, 0), 'requests_today': getValue(getValue(stats['by_date_origin'],dt.strftime('%Y-%m-%d')),origin.name, 0), 'link_geojson': link_geojson, 'link_geojsonio': 'http://geojson.io/#data=data:text/x-url,'+link_geojson }) else: origins.append({ 'name': origin.name, 'description': origin.description, 'type': origin.type_title(), 'multiple': origin.multiple, 'auto': origin.auto, 'url': origin.url, 'requests_all': 0, 'requests_year': 0, 'requests_month': 0, 'requests_today': 0, 'link_geojson': link_geojson, 'link_geojsonio': 'http://geojson.io/#data=data:text/x-url,'+link_geojson }) return HttpResponse(json.dumps(origins), content_type="application/json" )
def stats_tms(request, t=None, stat=None, z=None, x=None, y=None, u=None, ext=None): #==# verbose = True ix = None iy = None iyf = None iz = None if u: iz, ix, iy = quadkey_to_tms(u) elif x and y and z: ix = int(x) iy = int(y) iz = int(z) if t == "regular": ify = flip_y(ix,iy,iz,256,webmercator_bbox) else: ify = iy iy = flip_y(ix,ify,iz,256,webmercator_bbox) #stats = stats_tilerequest() cache, stats = get_from_cache('default','stats_tilerequests') key = z+"/"+x+"/"+y if not stats: return None if not stat: return None image = None if key in stats['global'][stat]: blue = (256.0 * stats['global'][stat][key]) / stats['tile']['max'] image = solidTile(width=256, height=256, b=int(blue), a=128) else: image = blankTile(width=256, height=256) if image: response = HttpResponse(content_type="image/png") image.save(response, "PNG") return response else: return None
def stats_json(request): stats = None if settings.STATS_SAVE_MEMORY: cache, stats = get_from_cache( settings.CACHES['default']['LOCATION'], settings.CACHES['default'], 'default', 'stats_tilerequests', GEVENT_MONKEY_PATCH=settings.TILEJET_GEVENT_MONKEY_PATCH) if settings.STATS_SAVE_FILE and not stats: stats = get_from_file(settings.STATS_REQUEST_FILE, filetype='json') if not stats: stats = {} return HttpResponse(json.dumps(stats), content_type="application/json" )