Commit aada75f8 authored by Joachim Schunk's avatar Joachim Schunk

fix :number-migrations

parent 4ca80256
......@@ -9,9 +9,6 @@
(defn set-current-scheme [answer]
(assoc answer :answer-scheme {:type "calculation" :version answer-scheme-version}))
(defn remove-ooms [answer]
(update answer :calculations (fn [calcs] (migrate-object #(dissoc % :order-of-magnitude) calcs))))
(defn convert-calculation-numbers [answer]
(update answer :calculations (fn [calcs] (migrate-object convert-number-to-object calcs))))
......@@ -32,5 +29,4 @@
wrap-answer-calculations
(add-missing-calculation-objects calculation-ids)
convert-calculation-numbers
remove-ooms
set-current-scheme))
(ns lernmeister.components.exercise-types.multistep-calculation.migrate
(:require [clojure.tools.reader.edn :as edn]
(:require [clojure.string :as string]
[clojure.tools.reader.edn :as edn]
[lernmeister.components.helper :refer [find-in-vec-by-id]]))
(def exercise-scheme-version "2019-11-22")
......@@ -9,6 +10,11 @@
(assoc-in [:authoring :migration-status] :current)
(assoc :exercise-scheme {:type type :version version})))
(defn normalize-decimal-separator [number-string]
(if (string? number-string)
(string/replace number-string #"," ".")
number-string))
(defn migrate-object [migrate-fn obj]
(reduce-kv (fn [res-obj obj-k obj-v] (assoc res-obj obj-k (migrate-fn obj-v))) {} obj))
......@@ -26,7 +32,7 @@
(defn convert-number-obj [obj]
(if (contains? obj :number)
(let [significand (:number obj)
(let [significand (normalize-decimal-separator (:number obj))
order-of-magnitude (or (:order-of-magnitude obj) "0")]
{:significand significand :order-of-magnitude order-of-magnitude})
obj))
......@@ -34,7 +40,7 @@
(defn convert-number-to-object [obj]
(if (contains? obj :number)
(if-not (map? (:number obj))
(let [significand (:number obj)
(let [significand (normalize-decimal-separator (:number obj))
order-of-magnitude (or (:order-of-magnitude obj) "0")]
(-> obj
(dissoc :order-of-magnitude)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment