Permalink
Browse files

Merge pull request #190 from daviddavis/fix-solved

Getting more accurate problem solved counts by adding up user solved counts
  • Loading branch information...
2 parents 84b9868 + 46980eb commit 27517c09f2b532fcc47fbb8b4afd0fee8c19d5eb @amalloy amalloy committed Dec 11, 2011
Showing with 9 additions and 4 deletions.
  1. +3 −2 src/foreclojure/mongo.clj
  2. +6 −2 src/foreclojure/problems.clj
@@ -54,8 +54,9 @@
[(number-from-mongo-key id) score]
+ times))
{}))
- total (count (mapcat :solved users))]
- (send solved-stats (constantly (assoc scores :total total)))))
+ solved-counts (frequencies (map int (mapcat :solved users)))
+ total (reduce + (vals solved-counts))]
+ (send solved-stats (constantly (assoc scores :total total :solved-counts solved-counts)))))
(defn prepare-mongo []
(connect-to-db)
@@ -128,7 +128,11 @@
(when (not-any? #{problem-id} (get-solved username))
(update! :users {:_id user-id} {:$addToSet {:solved problem-id}
:$set {:last-solved-date current-time}})
- (send solved-stats update-in [:total] inc))
+ (let [inc (fnil inc 0)]
+ (send solved-stats
+ #(-> %
+ (update-in [:total] inc)
+ (update-in [:solved-counts problem-id] inc)))))
(record-golf-score! user-id problem-id (code-length code))
(save-solution user-id problem-id code)))
@@ -402,7 +406,7 @@ Return a map, {:message, :error, :url, :num-tests-passed}."
(s/join " " (map #(str "<span class='tag'>" % "</span>")
tags))]
[:td.centered user]
- [:td.centered (reduce + (vals (get @solved-stats id)))]
+ [:td.centered (get-in @solved-stats [:solved-counts id] 0)]
[:td.centered (checkbox-img (contains? solved id))]])
problems))])}))

0 comments on commit 27517c0

Please sign in to comment.