Browse Source

Refactoring

Stephen Starkey 1 year ago
parent
commit
43fa8ce0ee
2 changed files with 30 additions and 22 deletions
  1. 0
    1
      project.clj
  2. 30
    21
      src/xp_assessment/core.clj

+ 0
- 1
project.clj View File

@@ -23,7 +23,6 @@
23 23
   :min-lein-version "2.0.0"
24 24
   :main xp-assessment.core
25 25
   :dependencies [[org.clojure/clojure "1.8.0"]
26
-                 [cheshire "5.8.1"]
27 26
                  [com.taoensso/timbre "4.10.0"]
28 27
                  [coreagile/defenv "1.0.2"]
29 28
                  [hiccup "1.0.5"]

+ 30
- 21
src/xp_assessment/core.clj View File

@@ -16,8 +16,7 @@
16 16
 ;
17 17
 
18 18
 (ns xp-assessment.core
19
-  (:require [cheshire.core :as json]
20
-            [clojure.java.io :as io]
19
+  (:require [clojure.java.io :as io]
21 20
             [clojure.string :as str]
22 21
             [defenv.core :refer :all]
23 22
             [hiccup.core :refer :all]
@@ -225,16 +224,34 @@
225 224
 (defn- add-to-score [base-score addition] (+ (or base-score 0) addition))
226 225
 
227 226
 (defn render-results [form-params]
228
-  (let [{{:strs [Collaborating Developing Planning Releasing Thinking]
229
-          :as score-by-topic}
230
-         :score-by-topic}
227
+  (let [{:keys [score-by-topic]}
231 228
         (reduce-kv
232 229
           (fn [m i {:keys [topic] :as q}]
233 230
             (let [qv (-> (str "question-" i) form-params keyword)
234 231
                   score (q qv)]
235 232
               (when qv
236 233
                 (update-in m [:score-by-topic topic] add-to-score score))))
237
-          {:score-by-topic {}} questions-by-index)]
234
+          {:score-by-topic {}} questions-by-index)
235
+
236
+        topics
237
+        ["Thinking" "Collaborating" "Releasing" "Planning" "Developing"]
238
+
239
+        comma-separated (partial str/join ",")
240
+
241
+        labels
242
+        (->> topics (map #(str/replace % #"^(.*)$" "'$1'")) comma-separated)
243
+
244
+        background-colors
245
+        ["'lightblue'" "'palegoldenrod'" "'pink'" "'lightgreen'" "'thistle'"]
246
+
247
+        scores
248
+        (map score-by-topic topics)
249
+
250
+        score-summary
251
+        (str/join
252
+          ", "
253
+          (map (comp (partial str/join " = ") (juxt identity score-by-topic))
254
+               topics))]
238 255
     [:div
239 256
      [:h2 "Results"]
240 257
      [:div {:class "chart-container"}
@@ -242,25 +259,17 @@
242 259
      (javascript-tag
243 260
        (str "data = {\n"
244 261
             "  datasets: [{\n"
245
-            "    data: ["
246
-            (str/join
247
-              ","
248
-              [Thinking Collaborating Releasing Planning Developing])
249
-            " ],\n"
262
+            "    data: [" (comma-separated scores) "],\n"
250 263
             "    backgroundColor: ["
251
-            (str/join "," ["'lightblue'" "'palegoldenrod'" "'pink'"
252
-                           "'lightgreen'" "'thistle'"])
253
-            " ]\n"
264
+            (comma-separated background-colors)
265
+            "]\n"
254 266
             "  }],\n"
255
-            "  labels: [\n"
256
-            (str/join "," ["'Thinking'" "'Collaborating'" "'Releasing'"
257
-                           "'Planning'" "'Developing'"])
258
-            " ]\n"
267
+            "  labels: [" labels "]\n"
259 268
             "};\n"
260
-            "new Chart('results-chart', {data: data, type: 'polarArea',\n"
261
-            "          options: {}});\n"))
269
+            "new Chart('results-chart', \n"
270
+            "          {data: data, type: 'polarArea', options: {}});\n"))
262 271
      [:div {:class "results-json"}
263
-      [:pre (str/join ", " (map (partial str/join " = ") score-by-topic))]]
272
+      [:pre score-summary]]
264 273
      [:div {:class "chart-explanation"}
265 274
       "Wondering what the scoring, topics, and so on mean? "
266 275
       (link "https://www.jamesshore.com/Agile-Book/assess_your_agility.html"