Skip to content

Commit

Permalink
awp boundaries shown in player detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh4kE committed Oct 4, 2016
1 parent 1f1ec91 commit b4fbdf7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PlayerStatisticsAdmin(admin.ModelAdmin):
class AwpBoundariesAdmin(admin.ModelAdmin):
list_filter = ['name', 'matchday']
list_display = ['name', 'matchday']
fields = ['name', 'matchday', 'keys', 'values']
fields = ['name', 'matchday']
search_fields = ['matchday']


Expand Down
6 changes: 0 additions & 6 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,6 @@ def clear(self):
"""
self.keyvaluepair_set.all().delete()

# def __unicode__(self):
# """Returns a unicode representation of the Dictionary.
#
# """
# return unicode(self.asPyDict())

def as_py_dict(self):
"""Get a python dictionary that represents this Dictionary object.
This object is read-only.
Expand Down
12 changes: 10 additions & 2 deletions core/ofm_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from braces.views import CsrfExemptMixin, JsonRequestResponseMixin
from chartit import DataPool, Chart
from core.models import Player, Contract, PlayerStatistics, Finance, Matchday, Match, MatchStadiumStatistics, \
StadiumStandStatistics
StadiumStandStatistics, AwpBoundaries
from django.contrib.auth.decorators import login_required
from django.core.exceptions import MultipleObjectsReturned
from django.utils.decorators import method_decorator
Expand Down Expand Up @@ -155,15 +155,23 @@ def get(self, request, *args, **kwargs):
player_id = self.request.GET.get('player_id')
player = Player.objects.filter(id=player_id)
data_source = PlayerStatistics.objects.filter(player=player, matchday__season__number=season_number)
awps = [player_stat.awp for player_stat in data_source]

chart_json = {
"series": [{
"name": 'AWP',
"data": [player_stat.awp for player_stat in data_source]
"data": awps
}],
"categories": [player_stat.matchday.number for player_stat in data_source]
}

awp_boundaries = AwpBoundaries.get_from_matchday(Matchday.objects.all()[0])
bound_displayed = False
for strength in awp_boundaries:
if awp_boundaries[strength] >= max(awps) and not bound_displayed:
chart_json['series'].append({'name': 'AWP-Grenze: %s' % strength, 'data': [awp_boundaries[strength]] * len(data_source)})
bound_displayed = True

return self.render_json_response(chart_json)


Expand Down
17 changes: 14 additions & 3 deletions core/tests/unit/test_ofm_player_detail_view.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json

from core.factories.core_factories import MatchdayFactory, PlayerFactory, PlayerStatisticsFactory
from core.models import Contract, AwpBoundaries
from django.core.urlresolvers import reverse
from django.test import TestCase

from core.factories.core_factories import MatchdayFactory, PlayerFactory
from core.models import Contract
from users.models import OFMUser


Expand All @@ -30,10 +29,22 @@ def test_user_cannot_see_other_users_players(self):
self.assertFalse('player' in response.context_data)

def test_player_chart_json(self):

PlayerStatisticsFactory.create(player=self.player, matchday=self.matchday)

awp_boundaries = AwpBoundaries.create_from_matchday(self.matchday)
awp_boundaries[2] = 1000

response = self.client.get(reverse('core:ofm:players_chart_json'), {'player_id': self.player.id})
self.assertEqual(response.status_code, 200)
returned_json_data = json.loads(response.content.decode('utf-8'))
self.assertTrue('series' in returned_json_data)

self.assertEquals('AWP', returned_json_data['series'][0]['name'])
self.assertTrue('data' in returned_json_data['series'][0])

self.assertEquals('AWP-Grenze: 2', returned_json_data['series'][1]['name'])
self.assertTrue('data' in returned_json_data['series'][1])
self.assertEquals([1000], returned_json_data['series'][1]['data'])

self.assertTrue('categories' in returned_json_data)

0 comments on commit b4fbdf7

Please sign in to comment.