--- 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)))