4G3EnJAaNgKXvFPlyAKNHc changeset

Changeset336338616161 (b)
ParentNone (a)
ab
0+(setq glist
0+      '(("Duke" "UNC" 1)
0+        ("Duke" "Maryland" 1)
0+        ("Wake" "Duke" 0)
0+        ("UNC" "Duke" 1)
0+        ("Maryland" "Wake" 1)
0+        ("Wake" "UNC" 0)))
0+
0+;;
0+;; Calculate WP (Winning Percentage) for "team"
0+;;
0+;; Note that for WP only, home games count differently than
0+;; road games
0+;;
0+(defun wp (team gamelist)
0+  ;; Running count of wins and losses
0+  (let ((wins 0) (losses 0))
0+    ;; Go through all the games
0+    (loop for g in gamelist
0+       do (if (equal team (car g))      ;; team = home
0+              (if (eq 1 (caddr g))      ;; home team won?
0+                  (incf wins 0.6)       ;; home win
0+                  (incf losses 1.4))    ;; home loss
0+              (if (equal team (cadr g)) ;; team = road
0+                  (if (eq 0 (caddr g))  ;; road team won?
0+                      (incf wins 1.4)       ;; road win
0+                      (incf losses 0.6))))) ;; road loss
0+    ;; Result is wins/total
0+    (/ wins (+ wins losses))))
0+
0+;;
0+;;  Helper function calculates the OWP for "opponent" of "team"
0+;;
0+(defun owp-helper (team opponent gamelist)
0+  (let ((wins 0) (losses 0))
0+    (loop for g in gamelist
0+         ;; Need to ignore all of opponent's games that involve team
0+       do (if (not (or (and (equal opponent (car g))
0+                            (equal team (cadr g)))
0+                       (and (equal team (car g))
0+                            (equal opponent (cadr g)))))
0+              ;;  Otherwise...
0+              (if (equal opponent (car g))
0+                  (if (eq 1 (caddr g))
0+                      (incf wins)       ;; home win
0+                      (incf losses))    ;; home loss
0+                  (if (equal opponent (cadr g))
0+                      (if (eq 0 (caddr g))
0+                          (incf wins)        ;; road win
0+                          (incf losses)))))) ;; road loss
0+       (/ wins (+ wins losses))))
0+
0+;;
0+;;  Calculte OWP for team
0+;;
0+;;  Calculate the OWP for each opponent of team (counting opponents
0+;;  multiple times if the teams have played more than once) and then
0+;;  average.
0+;;
0+(defun owp (team gamelist)
0+  (let ((total-owp 0.0)
0+        (num-opponents 0))
0+    (loop for g in gamelist
0+       do (if (equal team (car g))  ;; team was home
0+              (progn
0+                ;; Calculate OWP of the away team
0+                (incf total-owp (owp-helper (car g) (cadr g) gamelist))
0+                (incf num-opponents)))
0+       do (if (equal team (cadr g)) ;; team was away
0+              (progn
0+                ;; Calculate OWP of the home team
0+                (incf total-owp (owp-helper (cadr g) (car g) gamelist))
0+                (incf num-opponents))))
0+    ;;  Average all the OWPs
0+    (if (> num-opponents 0)
0+        (/ total-owp num-opponents)
0+        0)))
0+ 
0+;;
0+;;  Calculate OOWP for team
0+;;
0+;;  OOWP is the average of all of team's opponent's OWP.
0+;;
0+(defun oowp (team gamelist)
0+  (let ((total-oowp 0.0)
0+        (num-opponents 0))
0+    (loop for g in gamelist
0+       do (if (equal team (car g))
0+              (progn
0+                (incf total-oowp (owp (cadr g) gamelist))
0+                (incf num-opponents)))
0+       do (if (equal team (cadr g))
0+              (progn
0+                (incf total-oowp (owp (car g) gamelist))
0+                (incf num-opponents))))
0+    (if (> num-opponents 0)
0+        (/ total-oowp num-opponents)
0+        0)))
0+   
0+
0+;;
0+;; RPI = 0.25*WP + 0.50*OWP + 0.25*OOWP
0+;;
0+(defun rpi (team gamelist)
0+  (+ (* (wp team gamelist) 0.25)
0+     (* (owp team gamelist) 0.50)
0+     (* (oowp team gamelist) 0.25)))
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
--- Revision None
+++ Revision 336338616161
@@ -0,0 +1,107 @@
+(setq glist
+ '(("Duke" "UNC" 1)
+ ("Duke" "Maryland" 1)
+ ("Wake" "Duke" 0)
+ ("UNC" "Duke" 1)
+ ("Maryland" "Wake" 1)
+ ("Wake" "UNC" 0)))
+
+;;
+;; Calculate WP (Winning Percentage) for "team"
+;;
+;; Note that for WP only, home games count differently than
+;; road games
+;;
+(defun wp (team gamelist)
+ ;; Running count of wins and losses
+ (let ((wins 0) (losses 0))
+ ;; Go through all the games
+ (loop for g in gamelist
+ do (if (equal team (car g)) ;; team = home
+ (if (eq 1 (caddr g)) ;; home team won?
+ (incf wins 0.6) ;; home win
+ (incf losses 1.4)) ;; home loss
+ (if (equal team (cadr g)) ;; team = road
+ (if (eq 0 (caddr g)) ;; road team won?
+ (incf wins 1.4) ;; road win
+ (incf losses 0.6))))) ;; road loss
+ ;; Result is wins/total
+ (/ wins (+ wins losses))))
+
+;;
+;; Helper function calculates the OWP for "opponent" of "team"
+;;
+(defun owp-helper (team opponent gamelist)
+ (let ((wins 0) (losses 0))
+ (loop for g in gamelist
+ ;; Need to ignore all of opponent's games that involve team
+ do (if (not (or (and (equal opponent (car g))
+ (equal team (cadr g)))
+ (and (equal team (car g))
+ (equal opponent (cadr g)))))
+ ;; Otherwise...
+ (if (equal opponent (car g))
+ (if (eq 1 (caddr g))
+ (incf wins) ;; home win
+ (incf losses)) ;; home loss
+ (if (equal opponent (cadr g))
+ (if (eq 0 (caddr g))
+ (incf wins) ;; road win
+ (incf losses)))))) ;; road loss
+ (/ wins (+ wins losses))))
+
+;;
+;; Calculte OWP for team
+;;
+;; Calculate the OWP for each opponent of team (counting opponents
+;; multiple times if the teams have played more than once) and then
+;; average.
+;;
+(defun owp (team gamelist)
+ (let ((total-owp 0.0)
+ (num-opponents 0))
+ (loop for g in gamelist
+ do (if (equal team (car g)) ;; team was home
+ (progn
+ ;; Calculate OWP of the away team
+ (incf total-owp (owp-helper (car g) (cadr g) gamelist))
+ (incf num-opponents)))
+ do (if (equal team (cadr g)) ;; team was away
+ (progn
+ ;; Calculate OWP of the home team
+ (incf total-owp (owp-helper (cadr g) (car g) gamelist))
+ (incf num-opponents))))
+ ;; Average all the OWPs
+ (if (> num-opponents 0)
+ (/ total-owp num-opponents)
+ 0)))
+
+;;
+;; Calculate OOWP for team
+;;
+;; OOWP is the average of all of team's opponent's OWP.
+;;
+(defun oowp (team gamelist)
+ (let ((total-oowp 0.0)
+ (num-opponents 0))
+ (loop for g in gamelist
+ do (if (equal team (car g))
+ (progn
+ (incf total-oowp (owp (cadr g) gamelist))
+ (incf num-opponents)))
+ do (if (equal team (cadr g))
+ (progn
+ (incf total-oowp (owp (car g) gamelist))
+ (incf num-opponents))))
+ (if (> num-opponents 0)
+ (/ total-oowp num-opponents)
+ 0)))
+
+
+;;
+;; RPI = 0.25*WP + 0.50*OWP + 0.25*OOWP
+;;
+(defun rpi (team gamelist)
+ (+ (* (wp team gamelist) 0.25)
+ (* (owp team gamelist) 0.50)
+ (* (oowp team gamelist) 0.25)))