Ejemplo n.º 1
0
def getCountryQueries():
    result = []
    sets = (
        QueryStats.objects.values("geoinfo").exclude(geoinfo=u"").annotate(Count("geoinfo")).order_by("-geoinfo__count")
    )
    for key in sets:
        result.append([key["geoinfo"], key["geoinfo__count"], getcountry_name(key["geoinfo"])])
    return result
Ejemplo n.º 2
0
def getCountryQueries():
    result = []
    sets = QueryStats.objects.values('geoinfo').exclude(geoinfo=u'').annotate(
        Count('geoinfo')).order_by('-geoinfo__count')
    for key in sets:
        result.append([
            key['geoinfo'], key['geoinfo__count'],
            getcountry_name(key['geoinfo'])
        ])
    return result
Ejemplo n.º 3
0
def getCountryActions(action):
    result = []
    sets = None
    if (action != None):
        sets = LRStats.objects.values('geoinfo').exclude(geoinfo=u'').filter(action=action).annotate(Count('action')).order_by('-action__count')
    else:
        sets = LRStats.objects.values('geoinfo').annotate(Count('action')).order_by('-action__count')
    
    for key in sets:
        result.append([key['geoinfo'], key['action__count'], getcountry_name(key['geoinfo'])])
    return result
Ejemplo n.º 4
0
def getCountryActions(action):
    result = []
    sets = None
    if (action != None):
        sets = LRStats.objects.values('geoinfo').exclude(geoinfo=u'').filter(action=action).annotate(Count('action')).order_by('-action__count')
    else:
        sets = LRStats.objects.values('geoinfo').annotate(Count('action')).order_by('-action__count')
    
    for key in sets:
        result.append([key['geoinfo'], key['action__count'], getcountry_name(key['geoinfo'])])
    return result
Ejemplo n.º 5
0
def getCountryActions(action):
    result = []
    sets = None
    if action != None:
        sets = (
            LRStats.objects.values("geoinfo")
            .exclude(geoinfo=u"")
            .filter(action=action)
            .annotate(Count("action"))
            .order_by("-action__count")
        )
    else:
        sets = LRStats.objects.values("geoinfo").annotate(Count("action")).order_by("-action__count")

    for key in sets:
        result.append([key["geoinfo"], key["action__count"], getcountry_name(key["geoinfo"])])
    return result
Ejemplo n.º 6
0
def topstats (request):
    """ viewing statistics about the top LR and latest queries. """    
    topdata = []
    geovisits = []
    visitstitle = "Unknown"
    view = request.GET.get('view', 'topviewed')
    last = request.GET.get('last', '')
    limit = int(request.GET.get('limit', '10'))
    offset = int(request.GET.get('offset', '0'))    
    since = None
    if (last == "day"):
        since = date.today() + relativedelta(days = -1)
    elif (last == "week"):
        since = date.today() + relativedelta(days = -7)
    elif (last == "month"):
        since = date.today() + relativedelta(months = -1)
    elif (last == "year"):
        since = date.today() + relativedelta(years = -1)
        
    countrycode = request.GET.get('country', '')
    countryname = ""
    if (len(countrycode) > 0):
        countryname = getcountry_name(countrycode)
    if view == "topviewed":
        geovisits = getCountryActions(VIEW_STAT)
        visitstitle = "resource visits"
        data = getLRTop(VIEW_STAT, limit+1, countrycode, since, offset)
        for item in data:
            try:
                res_info =  resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info,""])
            except: 
                LOGGER.debug("Warning! The object "+item['lrid']+ " has not been found.")               
    elif (view == "latestupdated"):
        geovisits = getCountryActions(UPDATE_STAT)
        visitstitle = "resource updates"
        data = getLRLast(UPDATE_STAT, limit+1, countrycode, offset)
        for item in data:
            try:
                res_info =  resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info, pretty_timeago(item['lasttime'])])
            except: 
                LOGGER.debug("Warning! The object "+item['lrid']+ " has not been found.")
    elif (view == "topdownloaded"):
        geovisits = getCountryActions(DOWNLOAD_STAT)
        visitstitle = "download requests"
        data = getLRTop(DOWNLOAD_STAT, limit+1, countrycode, since, offset)
        for item in data:
            try:
                res_info =  resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info,""])
            except: 
                LOGGER.debug("Warning! The object "+item['lrid']+ " has not been found.")
    elif view == "topqueries":
        geovisits = getCountryQueries()
        visitstitle = "queries"
        data = getTopQueries(limit+1, countrycode, since, offset)
        for item in data:
            url = "q=" + item['query']
            query = urllib.unquote(item['query'])
            facets = ""
            if (item['facets'] != ""):
                facetlist = eval(item['facets'])
                for face in facetlist:
                    url += "&selected_facets=" + face
                    facets += ", " + face.replace("Filter_exact:",": ")
                facets = facets.replace(", ", "", 1)     
            topdata.append([query, facets, "", item['query_count'], url])         
    elif view == "latestqueries":
        geovisits = getCountryQueries()
        visitstitle = "queries"
        data = getLastQuery(limit+1, countrycode, offset)
        for item in data:
            url = "q=" + item['query']
            query = urllib.unquote(item['query'])
            facets = ""
            if (item['facets'] != ""):
                facetlist = eval(item['facets'])
                for face in facetlist:
                    url += "&selected_facets=" + face
                    facets += ", " + face.replace("Filter_exact:",": ")
                facets = facets.replace(", ", "", 1) 
            topdata.append([query, facets, pretty_timeago(item['lasttime']), item['found'], url])       
    has_next = False
    if len(topdata) > limit:
        topdata = topdata[:limit]
        has_next = True
    return render_to_response('stats/topstats.html',
        {'user': request.user, 
        'topdata': topdata, 
        'view': view,
        'geovisits': geovisits,
        'countrycode': countrycode,
        'countryname': countryname,
        'visitstitle': visitstitle,
        'last' : last,
        'offset': offset,
        'has_next': has_next,
        'myres': isOwner(request.user.username)},
        context_instance=RequestContext(request))
Ejemplo n.º 7
0
def topstats(request):
    """ viewing statistics about the top LR and latest queries. """
    topdata = []
    geovisits = []
    visitstitle = "Unknown"
    view = request.GET.get('view', 'topviewed')
    last = request.GET.get('last', '')
    limit = int(request.GET.get('limit', '10'))
    offset = int(request.GET.get('offset', '0'))
    since = None
    if (last == "day"):
        since = date.today() + relativedelta(days=-1)
    elif (last == "week"):
        since = date.today() + relativedelta(days=-7)
    elif (last == "month"):
        since = date.today() + relativedelta(months=-1)
    elif (last == "year"):
        since = date.today() + relativedelta(years=-1)

    countrycode = request.GET.get('country', '')
    countryname = ""
    if (len(countrycode) > 0):
        countryname = getcountry_name(countrycode)
    if view == "topviewed":
        geovisits = getCountryActions(VIEW_STAT)
        visitstitle = "resource visits"
        data = getLRTop(VIEW_STAT, limit + 1, countrycode, since, offset)
        for item in data:
            try:
                res_info = resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info, ""])
            except:
                LOGGER.debug("Warning! The object " + item['lrid'] + " has not been found.")
    elif (view == "latestupdated"):
        geovisits = getCountryActions(UPDATE_STAT)
        visitstitle = "resource updates"
        data = getLRLast(UPDATE_STAT, limit + 1, countrycode, offset)
        for item in data:
            try:
                res_info = resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info, pretty_timeago(item['lasttime'])])
            except:
                LOGGER.debug("Warning! The object " + item['lrid'] + " has not been found.")
    elif (view == "topdownloaded"):
        geovisits = getCountryActions(DOWNLOAD_STAT)
        visitstitle = "download requests"
        data = getLRTop(DOWNLOAD_STAT, limit + 1, countrycode, since, offset)
        for item in data:
            try:
                res_info = resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info, ""])
            except:
                LOGGER.debug("Warning! The object " + item['lrid'] + " has not been found.")
    elif view == "topqueries":
        geovisits = getCountryQueries()
        visitstitle = "queries"
        data = getTopQueries(limit + 1, countrycode, since, offset)
        for item in data:
            url = "q=" + item['query']
            query = urllib.unquote(item['query'])
            facets = ""
            if (item['facets'] != ""):
                facetlist = eval(item['facets'])
                for face in facetlist:
                    url += "&selected_facets=" + face
                    facets += ", " + face.replace("Filter_exact:", ": ")
                facets = facets.replace(", ", "", 1)
            topdata.append([query, facets, "", item['query_count'], url])
    elif view == "latestqueries":
        geovisits = getCountryQueries()
        visitstitle = "queries"
        data = getLastQuery(limit + 1, countrycode, offset)
        for item in data:
            url = "q=" + item['query']
            query = urllib.unquote(item['query'])
            facets = ""
            if (item['facets'] != ""):
                facetlist = eval(item['facets'])
                for face in facetlist:
                    url += "&selected_facets=" + face
                    facets += ", " + face.replace("Filter_exact:", ": ")
                facets = facets.replace(", ", "", 1)
            topdata.append([query, facets, pretty_timeago(item['lasttime']), item['found'], url])
    has_next = False
    if len(topdata) > limit:
        topdata = topdata[:limit]
        has_next = True
    return render_to_response('stats/topstats.html',
                              {'user': request.user,
                               'topdata': topdata,
                               'view': view,
                               'geovisits': geovisits,
                               'countrycode': countrycode,
                               'countryname': countryname,
                               'visitstitle': visitstitle,
                               'last': last,
                               'offset': offset,
                               'has_next': has_next,
                               'myres': isOwner(request.user.username)},
                              context_instance=RequestContext(request))
Ejemplo n.º 8
0
def getCountryQueries():
    result = []
    sets = QueryStats.objects.values('geoinfo').exclude(geoinfo=u'').annotate(Count('geoinfo')).order_by('-geoinfo__count')
    for key in sets:
        result.append([key['geoinfo'], key['geoinfo__count'], getcountry_name(key['geoinfo'])])
    return result