Skip to content

Commit

Permalink
Merge c5cca3f into 8c2f0d5
Browse files Browse the repository at this point in the history
  • Loading branch information
petr-muller committed Mar 2, 2018
2 parents 8c2f0d5 + c5cca3f commit 296b2fa
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 17 deletions.
8 changes: 8 additions & 0 deletions helpers/fast-setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[aliases]
test=pytest

[tool:pytest]
addopts = --cov=vtes --cov-report=term --cov-report=html

[mypy]
ignore_missing_imports = True
15 changes: 15 additions & 0 deletions helpers/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

ft() {
cat helpers/fast-setup.cfg > setup.cfg
python setup.py test
}

st() {
cat helpers/strict-setup.cfg > setup.cfg
python setup.py test
}

cov() {
ft && firefox htmlcov/index.html
}
8 changes: 8 additions & 0 deletions helpers/strict-setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[aliases]
test=pytest

[tool:pytest]
addopts = --pylint --pylint-rcfile=.pylintrc --mypy --cov=vtes --cov-report=xml --cov-report=term --cov-report=html

[mypy]
ignore_missing_imports = True
7 changes: 7 additions & 0 deletions tests/functional/features/stats.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ Scenario: General timeline statistics
And I submit the command
Then command finishes successfully
And player rankings are listed

Scenario: Game Win Ratio
Given I logged some games
When I invoke vtes stats
And I submit the command
Then command finishes successfully
And stats contain game win ratio for each player
33 changes: 18 additions & 15 deletions tests/functional/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@ def vtes_stats(vtes_command):
@then('player rankings are listed')
def listed_player_rankings(vtes_command):
output = vtes_command.completed.stdout.split("\n")
assert output[0] == "Player GW VP Games"
assert output[1] == "------------- ---- ---- -------"
assert output[2] == "Afri 1 6 5"
assert output[3] == "bluedevil 1 4 2"
assert "Narpas 1 3 1" in output[4:6]
assert "sor_garcya 1 3 1" in output[4:6]
assert output[6] == "XZealot 0 3 3"
assert output[7] == "Cooper 0 2 3"
assert output[8] == "Nebojsa 0 2 2"
assert output[9] == "preston 0 1 1"
assert output[10] == "ShaneS_A tier 0 0 2"
assert "Zerato 0 0 1" in output[11:15]
assert "Felipe 0 0 1" in output[11:15]
assert "gNat 0 0 1" in output[11:15]
assert "Blooded 0 0 1" in output[11:15]
assert output[0].startswith("Player GW VP Games")
assert output[1].startswith("------------- ---- ---- -------")
assert output[2].startswith("Afri 1 6 5")
assert output[3].startswith("bluedevil 1 4 2")
assert output[6].startswith("XZealot 0 3 3")
assert output[7].startswith("Cooper 0 2 3")
assert output[8].startswith("Nebojsa 0 2 2")
assert output[9].startswith("preston 0 1 1")
assert output[10].startswith("ShaneS_A tier 0 0 2")
assert output[15] == ""
assert output[16] == "Overall statistics: 5 games with 13 players"

@then('stats contain game win ratio for each player')
def game_win_ratios(vtes_command):
output = vtes_command.completed.stdout.split("\n")
assert output[0] == "Player GW VP Games GW Ratio"
assert output[2] == "Afri 1 6 5 20%"
assert output[3] == "bluedevil 1 4 2 50%"
assert "sor_garcya 1 3 1 100%" in output[4:6]
assert output[10] == "ShaneS_A tier 0 0 2 0%"
14 changes: 14 additions & 0 deletions tests/unit/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_rankings():
assert ranking.wins == 0
assert ranking.points == 0
assert ranking.games == 0
assert ranking.gw_ratio is None
assert str(ranking) == "player GW=0 VP=0 games=0"
assert repr(ranking) == "player GW=0 VP=0 games=0"

Expand All @@ -50,6 +51,7 @@ def test_rankings():
assert ranking.wins == 1
assert ranking.points == 2.5
assert ranking.games == 3
assert ranking.gw_ratio == 33
assert ranking != ranking_same
assert ranking == ranking

Expand All @@ -70,3 +72,15 @@ def test_store_rankings():
assert rankings[3] == Ranking("3", 0, 1, 1)
for loser in ("4", "5", "C", "D", "E"):
assert Ranking(loser, 0, 0, 1) in rankings

def test_gw_ratio():
assert Ranking("aaa", 0, 0, 0).gw_ratio is None
assert Ranking("aaa", 1, 4, 1).gw_ratio == 100
assert Ranking("aaa", 1, 4, 2).gw_ratio == 50
assert Ranking("aaa", 1, 4, 3).gw_ratio == 33
assert Ranking("aaa", 2, 4, 3).gw_ratio == 67

ranking = Ranking("aaa", 0, 0, 0)
ranking.games = 3
ranking.wins = 2
assert ranking.gw_ratio == 67
2 changes: 1 addition & 1 deletion vtes/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def stats_command(journal_path: pathlib.Path) -> None:
store = load_store(journal_file)

rankings = store.rankings()
print(tabulate(rankings, headers=('Player', 'GW', 'VP', 'Games')))
print(tabulate(rankings, headers=('Player', 'GW', 'VP', 'Games', "GW Ratio")))
print("")
print(f"Overall statistics: {len(store)} games with {len(rankings)} players")

Expand Down
7 changes: 6 additions & 1 deletion vtes/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ def __repr__(self):
return f"{self.player} GW={self.wins} VP={self.points} games={self.games}"

def __iter__(self):
yield from (self.player, self.wins, self.points, self.games)
yield from (self.player, self.wins, self.points, self.games, f"{self.gw_ratio}%")

@property
def gw_ratio(self) -> int:
"""Return a percentage (0-100) of games the player won"""
return round(float(self.wins)/float(self.games)*100) if self.games else None

class GameStore:
"""Implements a journal of games"""
Expand Down

0 comments on commit 296b2fa

Please sign in to comment.