Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Getting more accurate problem solved counts by adding up user solved counts #190

Merged
merged 1 commit into from

2 participants

@daviddavis

This is for issue #118.

@amalloy
Owner

SOLD. Thanks David.

@amalloy amalloy merged commit 27517c0 into 4clojure:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 11, 2011
  1. Getting more accurate problem solved counts by adding up solved from …

    David Davis authored
    …users instead of golf scores
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 4 deletions.
  1. +3 −2 src/foreclojure/mongo.clj
  2. +6 −2 src/foreclojure/problems.clj
View
5 src/foreclojure/mongo.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)
View
8 src/foreclojure/problems.clj
@@ -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))])}))
Something went wrong with that request. Please try again.