Merge lp:open-leaderboard-app/1.1 into lp:open-leaderboard-app

Proposed by James-Robert Corken Knight
Status: Merged
Approved by: James-Robert Corken Knight
Approved revision: 9
Merged at revision: 2
Proposed branch: lp:open-leaderboard-app/1.1
Merge into: lp:open-leaderboard-app
Diff against target: 101 lines (+54/-6)
2 files modified
LICENSE.txt (+8/-0)
openleaderboardapp.py (+46/-6)
To merge this branch: bzr merge lp:open-leaderboard-app/1.1
Reviewer Review Type Date Requested Status
James-Robert Corken Knight Approve
Review via email: mp+154579@code.launchpad.net

Commit message

Merge with 1.1

Description of the change

Add Basic Statistics and bad input detection.

To post a comment you must log in.
Revision history for this message
James-Robert Corken Knight (nexxusdrako) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'LICENSE.txt'
2--- LICENSE.txt 1970-01-01 00:00:00 +0000
3+++ LICENSE.txt 2013-03-21 02:51:21 +0000
4@@ -0,0 +1,8 @@
5+Copyright (c) 2013 James-Robert Corken Knight
6+
7+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
11+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
13
14=== modified file 'openleaderboardapp.py'
15--- openleaderboardapp.py 2013-03-21 01:00:49 +0000
16+++ openleaderboardapp.py 2013-03-21 02:51:21 +0000
17@@ -1,17 +1,40 @@
18 leaderboard = {}
19 import cPickle as pickle
20-import sys
21-
22+
23+def average(values):
24+ """ Return the average of the values in the list. """
25+ return sum(values) / float(len(values))
26+
27+def standardDeviation(values):
28+ """ Computer the standard deviation of the values in
29+ the list.
30+ """
31+ mean = average(values)
32+
33+ differences = [(value - mean)**2 for value in values]
34+
35+ return average(differences) ** 0.5
36+
37 def askScore():
38+ """ Asks the user for a score. """
39 scorer = raw_input("What is the scorer's name? ")
40 scorer = scorer + ": "
41- score = float(raw_input("How much did they score? "))
42- addScore(scorer, score)
43+ score = raw_input("How much did they score? ")
44+ if score.isdigit():
45+ score = float(score)
46+ if score != 0:
47+ addScore(scorer, score)
48+ else:
49+ print "Zero doesn't warrant a leaderboard entry, sorry about that."
50+ else:
51+ print "Invalid score input."
52
53 def addScore(scorer, score):
54+ """ Adds the user's score. """
55 leaderboard[scorer] = score
56
57 def printLeaderboard():
58+ """ Displays the leaderboard """
59 for key, v in sorted(leaderboard.iteritems(), key=lambda item: -item[1]):
60 for key in leaderboard:
61 if leaderboard[ key ] == v:
62@@ -19,13 +42,28 @@
63 break
64
65 def saveLeaderboard():
66+ """ Saves the leaderboard """
67 f = open("leaderboard.ola", "wb")
68 pickle.dump(leaderboard, f)
69 f.close()
70+
71+def getAverage():
72+ """ Gets the average """
73+ avg = 0
74+ avg = average(valuesList)
75+ return avg
76
77+def getStandardDeviation():
78+ stdDev = 0
79+ stdDev = standardDeviation(valuesList)
80+ return stdDev
81+
82 choice = 0
83-while choice != "6":
84- choice = str(raw_input("1. Add Score\n2. Show Leaderboard\n3. Save Leaderboard\n4. Load Leaderboard\n5. Delete Leaderboard\n6. Quit\nEnter choice: "))
85+
86+# Main menu
87+while choice != "7":
88+ valuesList = leaderboard.values()
89+ choice = str(raw_input("1. Add Score\n2. Show Leaderboard\n3. Save Leaderboard\n4. Load Leaderboard\n5. Delete Leaderboard\n6. Show Statistics\n7. Quit\nEnter choice: "))
90 if choice == "1":
91 askScore()
92 continue
93@@ -43,6 +81,8 @@
94 leaderboard = {}
95 saveLeaderboard()
96 elif choice == "6":
97+ print "Average:" + str(getAverage()) + "\nStandard Deviation:" + str(getStandardDeviation())
98+ elif choice == "7":
99 print "See you soon!"
100 else:
101 print "Sorry, I couldn't understand you."

Subscribers

People subscribed via source and target branches

to all changes: