                   (gr-assoc gr :best (finalize-cmt-stats tid comment-conv-stats))
                   gr)
                 ; Also keep track of best agree comment is, so we can throw that the front preferentially
-                (if (beats-best-agrr? comment-conv-stats (gr-get gr :best-agree))
+                (if (beats-best-agr? comment-conv-stats (gr-get gr :best-agree))
                   (gr-assoc gr :best-agree (assoc comment-conv-stats :tid tid))
                   gr))))
           result

      (> (max rat rdt) current-best-z)))


(defn- beats-best-agrr?
  "Like beats-best-by-test?, but only considers agrees. Additionally, doesn't focus solely on repness,
  but also on raw probability of agreement, so as to ensure that there is some representation of what
  people in the group agree on. Also, note that this takes the current-best, instead of just current-best-z."
  [{:keys [ra rat pa pat] :as comment-conv-stats} current-best]
  (cond
    (and current-best (> (:ra current-best) 1.0))
        ; XXX - a litte messy, since we're basicaly reimplimenting the repness sort function
        (> (* ra rat pa pat) (apply * (map current-best [:ra :rat :pa :pat])))
    current-best
        (> (* pa pat) (apply * (map current-best [:pa :pat])))
    :else
        (or (> ra 1.0)
            (> pa 0.5))))


(defn passes-by-test?
  "Decide whether we should count a given comment-conv-stat hash-map as being representative."
  [{:keys [pat rat pdt rdt] :as comment-conv-stats}]
  (or (and (z-sig-90? rat) (z-sig-90? pat))

     :repful-for   repful-for}))


(defn repness-metric
  [{:keys [repness repness-test p-success p-test]}]
  (* repness repness-test p-success p-test))


(defn repness-sort
  [repdata]
  (sort-by
    (comp - repness-metric)
    repdata))


