<< Back to Programming Forum   Search

Posts 1 - 6 of 6   
Get Win% in column: 10/2/2013 20:43:56


ChrisCMU 
Level 61
Report
I still can't manage to do this, can anybody help me? I have It grabbing Wins, Losses and Total games...I can't figure out how to get Win % in there.

Here are the important parts of my code:

Clot.py:
http://postimg.org/image/sz1p52uqt/

Cron.py:
http://postimg.org/image/e8bikwg11/

As you can see I comment the parts of the code that are not original. All of it works except the parts I added today in Clot.py

I get this error on the website:

File "/base/data/home/apps/s~wg-rotating-1v1/1.370641115765141202/templates/renderlot.html", line 31, in top-level template code
<td {%if player.key.id() not in container.lot.playersParticipating %} style="background-color: #A4A4A4" {%endif%}>{{ container.lot.playerWinPercentage.get(player.key.id(), 0) }}</td>
UndefinedError: 'None' has no attribute 'get'
Get Win% in column: 10/3/2013 01:32:20

Fizzer 
Level 64

Warzone Creator
Report
If you have wins and total games, can't you just divide them to get the win%?

container.lot.playerWinPercentage.get(...}
UndefinedError: 'None' has no attribute 'get'


This is saying that playerWinPercentage is None (i.e. null). You should figure out why that thing isn't set to figure out why this error is happening.
Get Win% in column: 10/3/2013 15:04:01


ChrisCMU 
Level 61
Report
Well, I was trying to do that with the part at the bottom of the Clot.py image I posted, but something isn't working. I did:

winpercentage = finishedGamesGroupedByTotalGames/finishedGamesGroupedByWinner*100

Since the container is an integer value I multiplied by 100.

I am missing something though, I just can't figure out what.
Get Win% in column: 10/4/2013 14:40:32


Krzysztof 
Level 67
Report
1. finishedGamesGroupedByTotalGames/finishedGamesGroupedByWinner

assuming finishedGamesGroupedByTotalGames - wins
and finishedGamesGroupedByWinner - totalgames
it should be finishedGamesGroupedByWinner/finishedGamesGroupedByTotalGames

2 but the problem is, that all those variables are probably integers, so

wins/totalgames = 0 (always, except wins=totalgames) so wins/totalgames * 100 = 0

try: float(wins)/totalgames * 100

Edited 10/4/2013 14:42:25
Get Win% in column: 10/15/2013 22:49:42


ChrisCMU 
Level 61
Report
Whoops, I put those in wrong order, good catch.

I tried:

winpercentage = float(finishedGamesGroupedByWinner)/finishedGamesGroupedByTotalGames*100


And both times it gave me this error:

"float() argument must be a string or a number"


I don't understand because if I am seeing things right, then finishedGamesGroupedByWinner should be an integer.
Get Win% in column: 10/15/2013 23:46:10

Fizzer 
Level 64

Warzone Creator
Report
finishedGamesGroupedByWinner sounds like it's a dictionary or list or something. You should check its type.

Python can't divide a list of numbers, it can only divide numbers. Example:

>>> 3.0 / 4.0
0.75
>>> [2.0, 3.0, 4.0] / [5.0, 6.0, 7.0]

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    [2.0, 3.0, 4.0] / [5.0, 6.0, 7.0]
TypeError: unsupported operand type(s) for /: 'list' and 'list'


It sounds like you need to loop through the players and divide each one.
Posts 1 - 6 of 6