From 20fdcc5b31744a32156bdded88be342d04146b55 Mon Sep 17 00:00:00 2001 From: Joakim Strandberg Date: Thu, 5 May 2016 09:18:35 +0200 Subject: [PATCH] More statistics features for Fatlink (#423) * Fixed a bug with links not registering correctly when undocked. Also removed some typos. * Adding functionality to view individual members stats as an admin, to see ships flown, and paps created, if any. Also correcting a incorrectly sorted table, and a faulty link. --- alliance_auth/urls.py | 8 ++- corputils/views.py | 8 +-- fleetactivitytracking/views.py | 45 ++++++++++-- stock/templates/registered/corputils.html | 13 ++++ .../registered/corputilssearchview.html | 20 +++++- .../fatlinkpersonalmonthlystatisticsview.html | 69 +++++++++++++++++++ .../fatlinkpersonalstatisticsview.html | 12 ++-- stock/templates/registered/fatlinkview.html | 2 +- 8 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 stock/templates/registered/fatlinkpersonalmonthlystatisticsview.html diff --git a/alliance_auth/urls.py b/alliance_auth/urls.py index 9e6c5d7a..cb21e06a 100755 --- a/alliance_auth/urls.py +++ b/alliance_auth/urls.py @@ -241,8 +241,12 @@ urlpatterns = patterns('', url(r'^fat/$', 'fleetactivitytracking.views.fatlink_view', name='auth_fatlink_view'), url(r'^fat/statistics/$', 'fleetactivitytracking.views.fatlink_statistics_view', name='auth_fatlink_view_statistics'), url(r'^fat/statistics/(?P[0-9]+)/(?P[0-9]+)/$', 'fleetactivitytracking.views.fatlink_statistics_view', name='auth_fatlink_view_statistics_month'), - url(r'^fat/user/statistics/$', 'fleetactivitytracking.views.fatlink_personal_statistics_view'), - url(r'^fat/user/statistics/(?P[0-9]+)/$', 'fleetactivitytracking.views.fatlink_personal_statistics_view', name='auth_fatlink_view_personal_statistics'), + url(r'^fat/user/statistics/$', 'fleetactivitytracking.views.fatlink_personal_statistics_view', name='auth_fatlink_view_personal_statistics'), + url(r'^fat/user/statistics/(?P[0-9]+)/$', 'fleetactivitytracking.views.fatlink_personal_statistics_view', name='auth_fatlink_view_personal_statistics_year'), + url(r'^fat/user/statistics/(?P[0-9]+)/(?P[0-9]+)/$', 'fleetactivitytracking.views.fatlink_monthly_personal_statistics_view', + name='auth_fatlink_view_personal_statistics_month'), + url(r'^fat/user/(?P[0-9]+)/statistics/(?P[0-9]+)/(?P[0-9]+)/$', 'fleetactivitytracking.views.fatlink_monthly_personal_statistics_view', + name='auth_fatlink_view_user_statistics_month'), url(r'^fat/create/$', 'fleetactivitytracking.views.create_fatlink_view', name='auth_create_fatlink_view'), url(r'^fat/modify/$', 'fleetactivitytracking.views.modify_fatlink_view', name='auth_modify_fatlink_view'), url(r'^fat/modify/(?P[a-zA-Z0-9_-]+)/([a-z0-9_-]+)$', diff --git a/corputils/views.py b/corputils/views.py index 2affe638..5038a961 100644 --- a/corputils/views.py +++ b/corputils/views.py @@ -245,22 +245,22 @@ def corputils_search(request, corpid=settings.CORP_ID): char = EveCharacter.objects.get(character_name=member_data["name"]) user = char.user mainid = int(AuthServicesInfoManager.get_auth_service_info(user=user).main_char_id) - mainname = EveCharacter.objects.get(character_id=mainid).character_name + main = EveCharacter.objects.get(character_id=mainid) api_registered = True apiinfo = EveApiKeyPair.objects.get(api_id=char.api_id) except EveCharacter.DoesNotExist: api_registered = False char = None - mainname = "" + main = "" apiinfo = None - searchresults.append(SearchResult(name=member_data["name"], id=memberid, main=mainname, api_registered=api_registered, + searchresults.append(SearchResult(name=member_data["name"], id=memberid, main=main, api_registered=api_registered, character=char, apiinfo=apiinfo)) logger.info("Found %s members for user %s matching search string %s" % (len(searchresults), request.user, searchstring)) - context = {'corp': corp, 'results': searchresults, 'search_form': CorputilsSearchForm()} + context = {'corp': corp, 'results': searchresults, 'search_form': CorputilsSearchForm(), "year":datetime.datetime.now().year, "month":datetime.datetime.now().month} return render_to_response('registered/corputilssearchview.html', context, context_instance=RequestContext(request)) diff --git a/fleetactivitytracking/views.py b/fleetactivitytracking/views.py index 1935965b..919c45f8 100644 --- a/fleetactivitytracking/views.py +++ b/fleetactivitytracking/views.py @@ -114,21 +114,23 @@ def fatlink_statistics_view(request, year=datetime.date.today().year, month=date @login_required -def fatlink_personal_statistics_view(request, year=datetime.date.today().year): +def fatlink_personal_statistics_view(request, year=datetime.date.today().year, main_name=None): year = int(year) + logger.debug("Personal statistics view for year %i called by %s" % (year, request.user)) + user = request.user logger.debug("fatlink_personal_statistics_view called by user %s" % request.user) personal_fats = Fat.objects.filter(user=user).order_by('id') - - - monthlystats = {datetime.date(year, month, 1).strftime("%h"):0 for month in range(1,13)} + monthlystats = [0 for month in range(1,13)] for fat in personal_fats: fatdate = fat.fatlink.fatdatetime if fatdate.year == year: - monthlystats[fatdate.strftime("%h")] += 1 + monthlystats[fatdate.month-1] += 1 + + monthlystats = [(i+1, datetime.date(year, i+1, 1).strftime("%h"), monthlystats[i]) for i in range(12)] if datetime.datetime.now() > datetime.datetime(year+1, 1, 1): context = {'user':user, 'monthlystats': monthlystats, 'year':year, 'previous_year':year-1, 'next_year':year+1} @@ -138,6 +140,38 @@ def fatlink_personal_statistics_view(request, year=datetime.date.today().year): return render_to_response('registered/fatlinkpersonalstatisticsview.html', context, context_instance=RequestContext(request)) +@login_required +def fatlink_monthly_personal_statistics_view(request, year, month, char_id=None): + year = int(year) + month = int(month) + start_of_month = datetime.datetime(year, month, 1) + start_of_next_month = first_day_of_next_month(year, month) + start_of_previous_month = first_day_of_previous_month(year, month) + + if check_if_user_has_permission(request.user, 'fleetactivitytracking_statistics') and char_id: + user = EveCharacter.objects.get(character_id=char_id).user + else: + user = request.user + logger.debug("Personal monthly statistics view for user %s called by %s" % (user, request.user)) + + personal_fats = Fat.objects.filter(user=user).filter(fatlink__fatdatetime__gte = start_of_month).filter(fatlink__fatdatetime__lt = start_of_next_month) + + ship_statistics = dict() + n_fats = 0 + for fat in personal_fats: + ship_statistics[fat.shiptype] = ship_statistics.setdefault(fat.shiptype, 0) + 1 + n_fats += 1 + context = {'user': user, 'shipStats':sorted(ship_statistics.items()), 'month':start_of_month.strftime("%h"), + 'year':year, 'n_fats': n_fats, 'char_id': char_id, 'previous_month': start_of_previous_month, + 'next_month': start_of_next_month} + + created_fats = Fatlink.objects.filter(creator=user).filter(fatdatetime__gte = start_of_month).filter(fatdatetime__lt = start_of_next_month) + context["created_fats"] = created_fats + context["n_created_fats"] = len(created_fats) + + return render_to_response('registered/fatlinkpersonalmonthlystatisticsview.html', context, context_instance=RequestContext(request)) + + @login_required def click_fatlink_view(request, hash, fatname): # Take IG-header data and register the fatlink if not existing already. @@ -201,6 +235,7 @@ def create_fatlink_view(request): fatlink.name = slugify(form.cleaned_data["fatname"]) fatlink.fleet = form.cleaned_data["fleet"] fatlink.duration = form.cleaned_data["duration"] + fatlink.fatdatetime = timezone.now() fatlink.creator = request.user fatlink.hash = ''.join(random.choice(string.ascii_letters+string.digits) for i in range(10)) try: diff --git a/stock/templates/registered/corputils.html b/stock/templates/registered/corputils.html index 68c6eeb8..81cadfdc 100644 --- a/stock/templates/registered/corputils.html +++ b/stock/templates/registered/corputils.html @@ -107,7 +107,12 @@ Main corporation Character list Fats + {% if perms.auth.fleetactivitytracking_statistics %} + Killboard + Fleet statistics + {% else %} Killboard + {% endif %} API JackKnife {% for maincharname, player in characters_with_api %} @@ -142,6 +147,14 @@

Killboard

{% endfor %} + {% if perms.auth.fleetactivitytracking %} + + + + + + {% endif %} {% for apiinfo in player.apilist %}

diff --git a/stock/templates/registered/corputilssearchview.html b/stock/templates/registered/corputilssearchview.html index 97547a2a..bfb214cc 100644 --- a/stock/templates/registered/corputilssearchview.html +++ b/stock/templates/registered/corputilssearchview.html @@ -37,7 +37,12 @@ Character Main character + {% if perms.auth.fleetactivitytracking%} + Killboard + Fleet statistics + {% else %} Killboard + {% endif %} API JackKnife {% for result in results %} @@ -48,7 +53,7 @@ {{ result.name }} {% if result.api_registered%} - {{ result.main }} + {{ result.main.character_name }} {% else %} No API registered! {% endif %} @@ -57,6 +62,19 @@

Killboard

+ {% if perms.auth.fleetactivitytracking %} + {% if result.main %} + + + + + + {% else %} + + {% endif %} + {% endif %} + {% if result.api_registered %} +

Participation data statistics for {{ month }}, {{ year }} + {% if char_id %} + + {% endif %} +

+

{{ user }} has collected {{ n_fats }} links this month.

+ + + + + + {% for ship, n_fats in shipStats %} + + + + + {% endfor %} +
ShipTimes used
{{ ship }}{{ n_fats }}
+ {% if created_fats %} +

{{ user }} has created {{ n_created_fats }} links this month.

+ + + + + + + + + + {% for link in created_fats %} + + + + + + + + + {% endfor %} + +
NameCreatorFleetEve TimeDurationEdit
{{ link.name }}{{ link.creator.username }}{{ link.fleet }}{{ link.fatdatetime }}{{ link.duration }} + + + +
+ {% endif %} + + + + + +{% endblock content %} diff --git a/stock/templates/registered/fatlinkpersonalstatisticsview.html b/stock/templates/registered/fatlinkpersonalstatisticsview.html index 7995ab7a..7137f254 100644 --- a/stock/templates/registered/fatlinkpersonalstatisticsview.html +++ b/stock/templates/registered/fatlinkpersonalstatisticsview.html @@ -9,11 +9,11 @@

Participation data statistics for {{ year }}
- + {% if next_year %} - + {% endif %} @@ -24,9 +24,13 @@ Month Fats - {% for month, n_fats in monthlystats.items %} + {% for monthnr, month, n_fats in monthlystats %} - {{ month }} + + + {{ month }} + + {{ n_fats }} {% endfor %} diff --git a/stock/templates/registered/fatlinkview.html b/stock/templates/registered/fatlinkview.html index 28cd2c59..a8bcd63d 100644 --- a/stock/templates/registered/fatlinkview.html +++ b/stock/templates/registered/fatlinkview.html @@ -15,7 +15,7 @@

- +