;calculate points and grades for students in Psych 30C 1999

(data 
 :use p30pts
 :variables '(attend hmwk1 hmwk2 hmwk3 hmwk4 hmwk5 hmwk6 homework 
                     midterm1 midterm2 advtop exams total grade)
 :types (combine (repeat "numeric" 13) "category")
 :program
 (let* ((attend (+ a7-1 a2-2 a4-2 a9-2 a11-2 a16-2 a18-2 a23-2 a25-2 
                   a2-3 a4-3 a16-3 a18-3 a23-3 a25-3 a29-3 a1-4 a6-4 a8-4))
        (hmwk1 (* 5/10 r1))
        (hmwk2 (+ (* 6/10 r2a) (* 4/10 r2b)))
        (hmwk3 (+ (* 7/10 r3abd) (* 3/10 r3c)))
        (hmwk4 (* 15/10 r4))
        (hmwk5 (* 15/10 r5))
        (hmwk6 hwk6)
        (homework (+ hmwk1 hmwk2 hmwk3 hmwk4 hmwk5 hmwk6))
        (midterm2 (+ m2abc m2d))
        (advtop (repeat 0 (length hmwk1)))
        (exams (+ m1 midterm2 advtop))
        (total (+ homework m1 midterm2 attend))
        (grade (mapcar #'(lambda (total)
                           (cond 
                             ((> total 220)     "A")
                             ((< 180 total 220) "B")
                             ((< 150 total 180) "C")
                             ((< total 150) "D")))
                       total))
        )
   (list attend 
         hmwk1 hmwk2 hmwk3 hmwk4 hmwk5 hmwk6 homework
         m1 midterm2 advtop exams total grade)
   ))

;Create a second data object with only major point sources

(data 
 :use *current-data*
 :variables '(homework exams total grade)
 :types (combine (repeat "numeric" 3) "category")
 :program
 (list homework exams total grade)
 )

;Sort into order by point total

(sort-permute :variable "total" :descending t)