anchor.diff:  (in-package :autobench-web)
   
   (defparameter *go-back-days* 50)
  -(defparameter *stddev-dev* 2)
  -(defparameter *ignore-benchmarks* '(quote ("CORE-FILE-SIZE" "MAKE-LIST-SEQUENTIAL/RPLACD" "MAKE-LIST-SEQUENTIAL/PUSH-NREVERSE" "CRC40")))
  +(defparameter *stddev-dev* 0.1)
  +(defparameter *ignore-benchmarks* '(quote ("MAKE-LIST-SEQUENTIAL/RPLACD" "MAKE-LIST-SEQUENTIAL/PUSH-NREVERSE" "CRC40")))
   
   (defclass atom-handler (handler) ())
   
   (defun explain-change (day benchmark impl from-revision to-revision from to)
  -  `(|li| ,(format nil "run time for benchmark <a href=\"~A\">~A</a> ~
  +  `(|li| ,(format nil "Run time for benchmark <a href=\"~A\">~A</a> ~
                          ~A from ~As to ~As between ~A revision ~A and ~A"
                      (html-escape (format nil "http://sbcl.boinkor.net/bench/?HOST=~A&IMPLEMENTATIONS=~A&ONLY-RELEASE=~A#~A"
                                           "walrus.boinkor.net" ; FIXME
  
positive.code:                    (if (< from to) "increased" "decreased")
                     from to impl from-revision to-revision)))
  
  (defun summarize-day/benchmark (day b-name v-name results)
    (let ((first-r (first results))
          (last-r (first (last results))))
      (destructuring-bind (from-version from-sec _) first-r
        (declare (ignore _))
        (destructuring-bind (to-version to-sec _) last-r
          (declare (ignore _))
          (when (> (abs (- to-sec from-sec)) *stddev-dev*)
            (explain-change day b-name v-name from-version to-version from-sec to-sec))))))
  
  (defun days-ago (days)
    (- (get-universal-time) (* 86400 days)))
  
negative.code:                       :start 0 :end 1)))
      :tuple 0)))
  
  (defun days-with-revisions (days-back)
    (iterate (for (day-nr) in-relation
                  (format nil "select distinct to_universal_time('today')/86400::integer - release_date/86400::integer ~
                               from version ~
                               where release_date between to_universal_time('today')- 86400*~A and to_universal_time('today');"
                          days-back)
                  on-connection *dbconn*)
             (collect day-nr)))
  
  (defun emit-significant-changes (&rest args &key implementation host &allow-other-keys)
    (declare (ignore args))
    (multiple-value-bind (entries last-modified)
        (iterate (for day in (days-with-revisions *go-back-days*))
                 (for p-day previous day initially nil)
                 (for pp-day previous p-day initially nil)
                 (when (null pp-day)
                   (next-iteration)) ; skip until we are two days ahead.
                 (for entry =
                      (iterate (for (v-name b-name) in-relation
                                    (translate
                                     ;; terminology: "y" = yesterday,
                                     ;; "t" = today (which is a lie,
                                     ;; because this program's yesterday
                                     ;; is "the last day on which there
                                     ;; was a commit")
                                     `(select (t.v-name t.b-name)
                                              (having
                                               (group-by (where (join (join (as result t) (as version t-v)
                                                                            :on (and (= t.v-name t-v.i-name) (= t.v-version t-v.version)))
                                                                      (join (as result y) (as version y-v)
                                                                            :on (and (= y.v-name y-v.i-name) (= y.v-version y-v.version)))
                                                                      :on (and (= t.v-name y.v-name) (= t.b-name y.b-name) (= t.m-name y.m-name)))
                                                                (and
                                                                 (between t-v.release_date
                                                                          (- (to_universal_time "today") (* 86400 ,day))
                                                                          (- (to_universal_time "today") (* 86400 ,p-day)))
                                                                 (between y-v.release-date
                                                                          (- (to_universal_time "today") (* 86400 ,p-day))
                                                                          (- (to_universal_time "today") (* 86400 ,pp-day)))
                                                                 (not (in t.b-name ,*ignore-benchmarks*))
                                                                 (= t.v_name ,implementation)
                                                                 (= t.m_name ,host)))
                                                         (t.v-name t.b-name))
                                               (and
                                                (> (abs (- (avg t.seconds) (avg y.seconds)))
                                                   (* 0.05 (avg y.seconds)))
                                                (> (abs (- (avg t.seconds) (avg y.seconds)))
                                                   (* 3 (sqrt (+ (* (/ (stddev t.seconds) (sqrt (count t.seconds)))
                                                                    (/ (stddev t.seconds) (sqrt (count t.seconds))))
                                                                 (* (/ (stddev y.seconds) (sqrt (count y.seconds)))
                                                                    (/ (stddev y.seconds) (sqrt (count y.seconds))))))))))))
                                    on-connection *dbconn*)
                               (collect (summarize-day/benchmark day p-day pp-day b-name v-name))))
                 (when entry
                   (collect
                       `(|entry|
  