Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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"
                        )
Exemplo n.º 3
0
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"
                        )