Skip to content
This repository was archived by the owner on Jan 13, 2019. It is now read-only.

Commit

Permalink
More statistics features for Fatlink (allianceauth#423)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Ydmir authored and orbitroom committed May 5, 2016
1 parent dbc9b58 commit 20fdcc5
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 17 deletions.
8 changes: 6 additions & 2 deletions alliance_auth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,12 @@
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<year>[0-9]+)/(?P<month>[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<year>[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<year>[0-9]+)/$', 'fleetactivitytracking.views.fatlink_personal_statistics_view', name='auth_fatlink_view_personal_statistics_year'),
url(r'^fat/user/statistics/(?P<year>[0-9]+)/(?P<month>[0-9]+)/$', 'fleetactivitytracking.views.fatlink_monthly_personal_statistics_view',
name='auth_fatlink_view_personal_statistics_month'),
url(r'^fat/user/(?P<char_id>[0-9]+)/statistics/(?P<year>[0-9]+)/(?P<month>[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<hash>[a-zA-Z0-9_-]+)/([a-z0-9_-]+)$',
Expand Down
8 changes: 4 additions & 4 deletions corputils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
45 changes: 40 additions & 5 deletions fleetactivitytracking/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions stock/templates/registered/corputils.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ <h4 class="">{{ corp.corporation_name }}</h4>
<th class="col-md-2">Main corporation</th>
<th class="col-md-2">Character list</th>
<th class="col-md-1">Fats</th>
{% if perms.auth.fleetactivitytracking_statistics %}
<th class="col-md-1">Killboard</th>
<th class="col-md-2">Fleet statistics</th>
{% else %}
<th class="col-md-3">Killboard</th>
{% endif %}
<th class="col-md-2">API JackKnife</th>
</tr>
{% for maincharname, player in characters_with_api %}
Expand Down Expand Up @@ -142,6 +147,14 @@ <h4 class="">{{ corp.corporation_name }}</h4>
<p><a href="https://zkillboard.com/character/{{ char.character_id }}/" class="label label-danger" target="_blank">Killboard</a></p>
{% endfor %}
</td>
{% if perms.auth.fleetactivitytracking %}
<td>
<a href="{% url 'auth_fatlink_view_user_statistics_month' player.main.character_id this_month|date:"Y" this_month|date:"m" %}">
<button type="button" class="btn btn-primary">Statistics
</button>
</a>
</td>
{% endif %}
<td>
{% for apiinfo in player.apilist %}
<p>
Expand Down
20 changes: 19 additions & 1 deletion stock/templates/registered/corputilssearchview.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ <h2 class="text-center"><a href="{% url 'auth_corputils' %}{{ corp.corporation_i
<th class="col-md-1"></th>
<th class="col-md-2">Character</th>
<th class="col-md-2">Main character</th>
{% if perms.auth.fleetactivitytracking%}
<th class="col-md-2">Killboard</th>
<th class="col-md-2">Fleet statistics</th>
{% else %}
<th class="col-md-5">Killboard</th>
{% endif %}
<th class="col-md-2">API JackKnife</th>
</tr>
{% for result in results %}
Expand All @@ -48,7 +53,7 @@ <h2 class="text-center"><a href="{% url 'auth_corputils' %}{{ corp.corporation_i
<td>{{ result.name }}</td>
<td>
{% if result.api_registered%}
{{ result.main }}
{{ result.main.character_name }}
{% else %}
<span class="label label-danger">No API registered!</span>
{% endif %}
Expand All @@ -57,6 +62,19 @@ <h2 class="text-center"><a href="{% url 'auth_corputils' %}{{ corp.corporation_i
<p><a href="https://zkillboard.com/character/{{ result.char.character_id }}/" class="label label-danger" target="_blank">Killboard</a></p>
</td>

{% if perms.auth.fleetactivitytracking %}
{% if result.main %}
<td>
<a href="{% url 'auth_fatlink_view_user_statistics_month' result.main.character_id year month%}">
<button type="button" class="btn btn-primary">Statistics
</button>
</a>
</td>
{% else %}
<td></td>
{% endif %}
{% endif %}

<td>
{% if result.api_registered %}
<a href="{{ JACK_KNIFE_URL }}?usid={{ result.apiinfo.api_id }}&apik={{ result.apiinfo.api_key }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends "public/base.html" %}
{% load bootstrap %}
{% load staticfiles %}

{% block title %}Alliance Auth{% endblock %}
{% block page_title %}Personal fatlink statistics{% endblock page_title %}

{% block content %}
<div class="col-lg-12">
<h1 class="page-header text-center">Participation data statistics for {{ month }}, {{ year }}
{% if char_id %}
<div class="text-right">
<a href="{% url 'auth_fatlink_view_user_statistics_month' char_id previous_month|date:"Y" previous_month|date:"m" %}">
<button type="button" class="btn btn-info">Previous month</button>
</a>
<a href="{% url 'auth_fatlink_view_user_statistics_month' char_id next_month|date:"Y" next_month|date:"m" %}">
<button type="button" class="btn btn-info">Next month</button>
</a>
</div>
{% endif %}
</h1>
<h2>{{ user }} has collected {{ n_fats }} links this month.</h2>
<table class="table table-responsive table-bordered">
<tr>
<th class="col-md-2 text-center">Ship</th>
<th class="col-md-2 text-center">Times used</th>
</tr>
{% for ship, n_fats in shipStats %}
<tr>
<td class="text-center">{{ ship }}</td>
<td class="text-center">{{ n_fats }}</td>
</tr>
{% endfor %}
</table>
{% if created_fats %}
<h2>{{ user }} has created {{ n_created_fats }} links this month.</h2>
<table class="table table-bordered">
<tr>
<th class="text-center">Name</th>
<th class="text-center">Creator</th>
<th class="text-center">Fleet</th>
<th class="text-center">Eve Time</th>
<th class="text-center">Duration</th>
<th class="text-center">Edit</th>
</tr>
{% for link in created_fats %}
<tr>
<td class="text-center"><a href="{% url 'auth_click_fatlink_view' %}{{ link.hash }}/{{ link.name }}">{{ link.name }}</a></td>
<td class="text-center">{{ link.creator.username }}</td>
<td class="text-center">{{ link.fleet }}</td>
<td class="text-center">{{ link.fatdatetime }}</td>
<td class="text-center">{{ link.duration }}</td>
<td class="text-center">
<a href="{% url 'auth_modify_fatlink_view' %}{{ link.hash }}/{{ link.name }}">
<button type="button" class="btn btn-info"><span
class="glyphicon glyphicon-edit"></span></button>
</a>
</td>
</tr>
{% endfor %}

</table>
{% endif %}
</div>


<script src="/static/js/dateformat.js"></script>

{% endblock content %}
12 changes: 8 additions & 4 deletions stock/templates/registered/fatlinkpersonalstatisticsview.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<div class="col-lg-12">
<h1 class="page-header text-center">Participation data statistics for {{ year }}
<div class="text-right">
<a href="{% url 'auth_fatlink_view_personal_statistics' previous_year %}">
<a href="{% url 'auth_fatlink_view_personal_statistics_year' previous_year %}">
<button type="button" class="btn btn-info">Previous year</button>
</a>
{% if next_year %}
<a href="{% url 'auth_fatlink_view_personal_statistics' next_year %}">
<a href="{% url 'auth_fatlink_view_personal_statistics_year' next_year %}">
<button type="button" class="btn btn-info">Next year</button>
</a>
{% endif %}
Expand All @@ -24,9 +24,13 @@ <h1 class="page-header text-center">Participation data statistics for {{ year }}
<th class="col-md-2 text-center">Month</th>
<th class="col-md-2 text-center">Fats</th>
</tr>
{% for month, n_fats in monthlystats.items %}
{% for monthnr, month, n_fats in monthlystats %}
<tr>
<td class="text-center">{{ month }}</td>
<td class="text-center">
<a href="{% url 'auth_fatlink_view_personal_statistics_month' year monthnr %}">
{{ month }}
</a>
</td>
<td class="text-center">{{ n_fats }}</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion stock/templates/registered/fatlinkview.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h4><b>Most recent clicked fatlinks</b>
</h4>
</th>
<th class="col-md-1">
<a href="{% url 'auth_fatlink_view_statistics' %}">
<a href="{% url 'auth_fatlink_view_personal_statistics' %}">
<button type="button" class="btn btn-info">Personal statistics</button>
</a>
</th>
Expand Down

0 comments on commit 20fdcc5

Please sign in to comment.