a | b | |
---|
| 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))) |
---|
... | |
---|