Commit 36bf0902 authored by Joachim Schunk's avatar Joachim Schunk
Browse files

use new migration mechanics in calculation-check

parent d43b1b16
Pipeline #106308 passed with stages
in 2 minutes and 31 seconds
(ns leukipp.components.exercise-types.calculation.check
(:require
[leukipp.components.exercise-types.calculation.migrate-answer
:refer
[answer-scheme-version migrate-answer]]
[leukipp.components.exercise-types.check :as e-check]
[leukipp.components.exercise-types.multistep-calculation.check
:refer
[check-phys-vals tolerable-error?]]
[leukipp.components.helper :refer [migrate-if-necessary]]))
(defn get-calculation-ids [exercise]
(reduce (fn [res item] (conj res (:id item)))
#{} (get-in exercise [:core :calculations])))
:refer
[check-phys-vals tolerable-error?]]
[leukipp.components.exercise-types.calculation.migration :refer [migrate-answer migrate-backend]]))
(defn no-negative-points [result]
(if (neg? (:points result))
......@@ -49,8 +42,7 @@
{:points 0 :points-max 0 :correct-calculations #{}})
no-negative-points)))
(defmethod e-check/check-answer :calculation [exercise answer callback]
(let [calculation-ids (get-calculation-ids exercise)
migrated-answer (migrate-if-necessary answer :answer-scheme "calculation"
answer-scheme-version (partial migrate-answer calculation-ids))]
(calculation-check exercise migrated-answer callback)))
(defmethod e-check/check-answer :calculation [prepared-backend answer callback]
(let [migrated-backend (migrate-backend prepared-backend)
migrated-answer (migrate-answer answer migrated-backend)]
(calculation-check migrated-backend migrated-answer callback)))
(ns leukipp.components.exercise-types.calculation.migrations.m20220124-01.answer
(:require
[clojure.set :refer [difference]]
[leukipp.components.exercise-types.calculation.check :refer [get-calculation-ids]]
[leukipp.components.exercise-types.multistep-calculation.migrations.m20220124-01.blueprint
:refer [migrate-object convert-number-to-object]]))
(def answer-scheme-version "2020-09-07")
(defn get-calculation-ids [exercise]
(reduce (fn [res item] (conj res (:id item)))
#{} (get-in exercise [:core :calculations])))
(defn convert-calculation-numbers [answer]
(update answer :calculations (fn [calcs] (migrate-object convert-number-to-object calcs))))
......
Supports Markdown
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