Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
components
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wandelwerk-Software
libraries
components
Commits
e078833e
Commit
e078833e
authored
Sep 11, 2020
by
Joachim Schunk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return calculatio-error from phys-val-check
parent
eccd5237
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
22 deletions
+26
-22
src/cljc/lernmeister/components/exercise_types/multistep_calculation/check.cljc
...omponents/exercise_types/multistep_calculation/check.cljc
+26
-22
No files found.
src/cljc/lernmeister/components/exercise_types/multistep_calculation/check.cljc
View file @
e078833e
...
...
@@ -12,7 +12,7 @@
[
answer-scheme-version
migrate-answer
]]
[
lernmeister.components.helper
:refer
[
math-abs
migrate-if-necessary
]])]
[
double-division
math-abs
migrate-if-necessary
]])]
:cljs
[(
:require
[
clojure.string
:as
clj-str
:refer
[
join
split
trim
]]
...
...
@@ -23,7 +23,7 @@
[
answer-scheme-version
migrate-answer
]]
[
lernmeister.components.helper
:refer
[
math-abs
migrate-if-necessary
]])]))
[
double-division
math-abs
migrate-if-necessary
]])]))
(
def
prefix-mapping
{
"Y"
24
"Z"
21
...
...
@@ -169,10 +169,14 @@
:factor
(
:factor
based-units-map
)
:oom
(
:oom
based-units-map
)}))
(
defn
tolerable-error?
[
calculation-error
error-relative
]
(
when
(
every?
#
(
and
(
number?
%
)
(
not
(
neg?
%
)))
[
calculation-error
error-relative
])
(
<=
(
*
calculation-error
100
)
error-relative
)))
(
defn
convert-phys-val-to-ref-units
[
phys-val
ref-units
]
(
let
[
phys-val-base-unit-map
(
units-to-baseunits
(
:units
phys-val
))
ref-base-unit-map
(
units-to-baseunits
ref-units
)
convert-factor
(
/
(
:factor
phys-val-base-unit-map
)
(
:factor
ref-base-unit-map
))
convert-factor
(
double-division
(
:factor
phys-val-base-unit-map
)
(
:factor
ref-base-unit-map
))
convert-oom
(
-
(
:oom
phys-val-base-unit-map
)
(
:oom
ref-base-unit-map
))
significand
(
edn/read-string
(
get-in
phys-val
[
:number
:significand
]))
oom
(
edn/read-string
(
get-in
phys-val
[
:number
:order-of-magnitude
]))]
...
...
@@ -294,14 +298,13 @@
ans-significand
(
get-combined-significand
:ans
)
calc-oom
(
get-combined-oom
:calc
)
ans-oom
(
get-combined-oom
:ans
)
oom-difference
(
-
calc-oom
ans-oom
)
calc-multiplier
(
Math/pow
10
oom-difference
)]
(
when
(
<=
(
math-abs
(
-
ans-significand
(
*
calc-multiplier
calc-significand
)))
(
math-abs
(
*
(
/
1
100
)
ans-significand
)))
true
)))
(
defn
check-answer
[
cur-calc
cur-ans
&
{
:keys
[
with-oom
with-units
]}]
oom-difference
(
-
ans-oom
calc-oom
)
ans-multiplier
(
Math/pow
10
oom-difference
)]
(
assoc
result
:calculation-error
(
math-abs
(
double-division
(
-
calc-significand
(
*
ans-significand
ans-multiplier
))
calc-significand
)))))
(
defn
check-phys-vals
[
cur-calc
cur-ans
&
{
:keys
[
with-oom
with-units
]}]
(
some->>
{}
(
get-number-part
cur-calc
with-oom
:calc
)
(
get-number-part
cur-ans
with-oom
:ans
)
...
...
@@ -368,12 +371,13 @@
(
defmethod
check-step
:constant
[
_
{
:keys
[
ans-id
ans-obj
ex-obj
assignment
res-map
]}]
(
let
[
update-res-map
(
fn
[
points
]
(
assoc
res-map
ans-id
{
:points
points
:points-max
4
}))]
(
if
(
and
(
get-in
ans-obj
[
:number
:significand
])
(
check-answer
{
:number
(
:number
ex-obj
)
:units
(
:units
assignment
)}
(
select-keys
ans-obj
[
:number
:units
])
:with-oom
true
:with-units
true
))
(
update-res-map
4
)
(
if
(
get-in
ans-obj
[
:number
:significand
])
(
let
[
phys-val-check-res
(
check-phys-vals
{
:number
(
:number
ex-obj
)
:units
(
:units
assignment
)}
(
select-keys
ans-obj
[
:number
:units
])
:with-oom
true
:with-units
true
)]
(
if
(
tolerable-error?
(
:calculation-error
phys-val-check-res
)
1
)
(
update-res-map
4
)
(
update-res-map
2
)))
(
update-res-map
2
))))
(
defmethod
check-step
:formula
[
_
{
:keys
[
ans-id
ans-obj
ex-obj
assignment
param-id-map
ex-id-map
...
...
@@ -389,11 +393,11 @@
(
if-not
(
some
(
comp
nil?
val
)
match-var-map
)
(
let
[
calc-mapping
(
:calc-mapping
assignment
)
formula-vec
(
formula-to-vec
(
:formula
assignment
))
calc-number
(
mathjs-str-to-number-obj
(
calc-step
formula-vec
calc-mapping
match-var-map
))
]
(
if
(
check-answer
{
:number
calc-number
:units
(
:units
assignment
)}
(
select-keys
ans-obj
[
:number
:units
])
:with-oom
true
:with-units
true
)
calc-number
(
mathjs-str-to-number-obj
(
calc-step
formula-vec
calc-mapping
match-var-map
))
phys-val-check-res
(
check-phys-vals
{
:number
calc-number
:units
(
:units
assignment
)}
(
select-keys
ans-obj
[
:number
:units
])
:with-oom
true
:with-units
true
)]
(
if
(
tolerable-error?
(
:calculation-error
phys-val-check-res
)
1
)
(
update-res-map
6
)
(
update-res-map
4
)))
(
update-res-map
2
))))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment