Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Getting more accurate problem solved counts by adding up solved from …

…users instead of golf scores
  • Loading branch information...
commit 46980ebb5021ad25ea85fd1e4a917e5dba47c3c7 1 parent 84b9868
David Davis authored
Showing with 9 additions and 4 deletions.
  1. +3 −2 src/foreclojure/mongo.clj
  2. +6 −2 src/foreclojure/problems.clj
5 src/foreclojure/mongo.clj
View
@@ -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)
8 src/foreclojure/problems.clj
View
@@ -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))])}))
Please sign in to comment.
Something went wrong with that request. Please try again.