store the number of guesses in /history, print stats
M src/numberdle/factordle.cljs +2 -1
@@ 114,6 114,7 @@ 
    [input-div]
    [lib/error-div :factordle/errors]
    [history-div]
+   [lib/stats-div :factordle/history]
    [game-management-div]])
 
 (defn is-valid-guess [guess]

          
@@ 241,7 242,7 @@ 
                        :factordle/history
                        assoc
                        (:factordle/date db)
-                       true)
+                       (count (:factordle/guesses db)))
                :factordle/game-won true
                :factordle/game-under-way nil
                :factordle/errors []

          
M src/numberdle/formuladle.cljs +2 -1
@@ 179,6 179,7 @@ 
    [history-div]
    [lib/error-div :formuladle/errors]
    [input-div]
+   [lib/stats-div :formuladle/history]
    [game-management-div]])
 
 (defn get-m

          
@@ 334,7 335,7 @@ 
                        :formuladle/history
                        assoc
                        (:formuladle/date db)
-                       true)
+                       (count (:formuladle/guesses db)))
                :formuladle/game-won true
                :formuladle/game-under-way false
                :formuladle/errors [])

          
M src/numberdle/lib.cljs +34 -13
@@ 129,19 129,7 @@ 
                    (if (= 1 guess-count)
                      " guess."
                      " guesses."))
-             (list "You lost. " guess-count " was too many guesses"))]
-      (let [grouped (group-by second history)
-            wins (grouped true)
-            losses (grouped false)
-            times-won (count wins)
-            times-played (+ times-won
-                            (count losses))]
-        [:p
-         (gstring/format "You've played %s game%s, and won %s (%i%%) of them."
-                         times-played
-                         (if (= 1 times-played) "" "s")
-                         times-won
-                         (* 100 (/ times-won times-played)))])])])
+             (list "You lost. " guess-count " was too many guesses"))]])])
 
 (defn history-div-fn
   "Return a div for the history.

          
@@ 291,3 279,36 @@ 
     [:div [:h3 "Oh no! Errors!"]
      (for [[error id] @(rf/subscribe [error-event])]
        [:div {:key id} warning " " error])]))
+
+(defn stats-div [history-event]
+  (let [history @(rf/subscribe [history-event])
+        [wins losses] (loop [[[date result] & rest] (seq history)
+                             wins {}
+                             losses {}]
+                        (if date
+                          (if result
+                            (recur rest
+                                   (assoc wins date result)
+                                   losses)
+                            (recur rest
+                                   wins
+                                   (assoc losses date result)))
+                          [wins losses]))
+        times-won (count wins)
+        times-lost (count losses)
+        times-played (+ times-won
+                        times-lost)]
+    [:div
+     [:p
+      (gstring/format "You've played %s game%s, and won %s (%s) of them."
+                      times-played
+                      (if (= 1 times-played) "" "s")
+                      times-won
+                      (if (zero? times-won)
+                        "none!"
+                        (str (* 100 (/ times-won times-played))
+                             "%")))]
+     (when-not (zero? times-won)
+       [:p (gstring/format "Of the games you've won, you average %.2f guesses."
+                           (/ (reduce + (vals wins))
+                              times-won))])]))

          
M src/numberdle/rationerdle.cljs +2 -1
@@ 145,6 145,7 @@ 
    [input-div]
    [lib/error-div :rationerdle/errors]
    [history-div]
+   [lib/stats-div :rationerdle/history]
    [game-management-div]])
 
 (rf/reg-event-fx

          
@@ 245,7 246,7 @@ 
                        :rationerdle/history
                        assoc
                        (:rationerdle/date db)
-                       true)
+                       (count (:rationerdle/guesses db)))
                :rationerdle/game-under-way nil
                :rationerdle/game-won true)
     :dispatch [:numberdle/save-to-local-storage rationerdle-variables]}))