<commit_before>(ns foreclojure.solutions
  (:require [clojure.string      :as   s])
  (:use     [somnium.congomongo  :only [fetch-one update!]]
            [useful.debug        :only [?]]))

(defn get-solution
  ([perm-level user-id problem-id]
     (when (or (= :private perm-level)
               (not (:hide-solutions (fetch-one :users
                                                :where {:_id user-id}
                                                :only [:hide-solutions]))))
       (get-solution user-id problem-id)))
  ([user-id problem-id]
     (:code (fetch-one :solutions
                       :where {:user user-id
                               :problem problem-id}))))

(defn save-solution [user-id problem-id code]
  (update! :solutions
           {:user user-id
            :problem problem-id}
           {:$set {:code code}}
           :upsert true))<commit_msg>Fix #119 - explain why solution is missing<commit_after>(ns foreclojure.solutions
  (:require [clojure.string      :as   s])
  (:use     [somnium.congomongo  :only [fetch-one update!]]
            [useful.debug        :only [?]]))

(defn get-solution
  ([perm-level user-id problem-id]
     (when (or (= :private perm-level)
               (not (:hide-solutions (fetch-one :users
                                                :where {:_id user-id}
                                                :only [:hide-solutions]))))
       (get-solution user-id problem-id)))
  ([user-id problem-id]
     (or (:code (fetch-one :solutions
                           :where {:user user-id
                                   :problem problem-id}))
         (let [{:keys [scores solved]}
               (fetch-one :users
                          :where {:_id user-id}
                          :only [(keyword (str "scores." problem-id))
                                 :solved])]
           (cond (seq scores) (str "Scored " (first (vals scores))
                                   ", before 4clojure started storing solutions."),

                 (some #{problem-id} solved) "Solved before 4clojure started scoring solutions")))))

(defn save-solution [user-id problem-id code]
  (update! :solutions
           {:user user-id
            :problem problem-id}
           {:$set {:code code}}
           :upsert true))
{'fraction_non_alphanumeric': 0.13034001743679163, 'fraction_numerical': 0.002179598953792502, 'mean_word_length': 1.4107142857142858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2860071', 'n_tokens_mistral': 665, 'n_tokens_neox': 621, 'n_words': 163}