Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
e8d0ff1e
Commit
e8d0ff1e
authored
6 years ago
by
srosse
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/OpenOLAT_12.5'
parents
c4228767
f120e5e5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/org/olat/ims/qti21/manager/extensions/MaximaOperator.java
+42
-0
42 additions, 0 deletions
...org/olat/ims/qti21/manager/extensions/MaximaOperator.java
with
42 additions
and
0 deletions
src/main/java/org/olat/ims/qti21/manager/extensions/MaximaOperator.java
+
42
−
0
View file @
e8d0ff1e
...
...
@@ -28,7 +28,11 @@ import uk.ac.ed.ph.jqtiplus.attribute.Attribute;
import
uk.ac.ed.ph.jqtiplus.attribute.AttributeList
;
import
uk.ac.ed.ph.jqtiplus.node.expression.ExpressionParent
;
import
uk.ac.ed.ph.jqtiplus.node.expression.operator.CustomOperator
;
import
uk.ac.ed.ph.jqtiplus.node.item.template.processing.ProcessTemplateValue
;
import
uk.ac.ed.ph.jqtiplus.node.shared.VariableDeclaration
;
import
uk.ac.ed.ph.jqtiplus.node.shared.VariableType
;
import
uk.ac.ed.ph.jqtiplus.running.ProcessingContext
;
import
uk.ac.ed.ph.jqtiplus.types.Identifier
;
import
uk.ac.ed.ph.jqtiplus.validation.ValidationContext
;
import
uk.ac.ed.ph.jqtiplus.value.BaseType
;
import
uk.ac.ed.ph.jqtiplus.value.BooleanValue
;
...
...
@@ -130,9 +134,38 @@ public class MaximaOperator extends CustomOperator<OpenOLATExtensionPackage> {
context
.
fireRuntimeError
(
this
,
"Failed to convert result from Maxima back to a QTI variable - returning NULL"
);
return
NullValue
.
INSTANCE
;
}
result
=
adjustTemplateValue
(
result
,
context
);
return
result
;
}
private
Value
adjustTemplateValue
(
Value
value
,
ProcessingContext
context
)
{
ExpressionParent
parent
=
getParent
();
if
(
parent
instanceof
ProcessTemplateValue
)
{
ProcessTemplateValue
processTemplateValue
=
(
ProcessTemplateValue
)
parent
;
Identifier
valueIdentifier
=
processTemplateValue
.
getIdentifier
();
VariableDeclaration
declaration
=
context
.
ensureVariableDeclaration
(
valueIdentifier
,
VariableType
.
TEMPLATE
);
if
(
declaration
!=
null
&&
declaration
.
getBaseType
()
!=
value
.
getBaseType
())
{
value
=
adjustValueBaseType
(
value
,
declaration
.
getBaseType
());
}
}
return
value
;
}
private
Value
adjustValueBaseType
(
Value
value
,
BaseType
desiredType
)
{
if
(
value
.
getBaseType
()
==
BaseType
.
INTEGER
&&
desiredType
==
BaseType
.
FLOAT
)
{
IntegerValue
integerValue
=
(
IntegerValue
)
value
;
return
new
FloatValue
(
integerValue
.
doubleValue
());
}
else
if
(
value
.
getBaseType
()
==
BaseType
.
FLOAT
&&
desiredType
==
BaseType
.
INTEGER
)
{
FloatValue
floatValue
=
(
FloatValue
)
value
;
int
intValue
=
(
int
)
Math
.
round
(
floatValue
.
doubleValue
());
return
new
IntegerValue
(
intValue
);
}
else
{
log
.
error
(
"Cannot convert "
+
value
.
getBaseType
()
+
" to "
+
desiredType
);
}
return
value
;
}
private
String
getValue
(
Value
value
)
{
String
val
=
null
;
if
(
value
.
getBaseType
()
==
BaseType
.
FLOAT
)
{
...
...
@@ -150,6 +183,15 @@ public class MaximaOperator extends CustomOperator<OpenOLATExtensionPackage> {
@Override
public
BaseType
[]
getProducedBaseTypes
(
ValidationContext
context
)
{
ExpressionParent
parent
=
getParent
();
if
(
parent
instanceof
ProcessTemplateValue
)
{
ProcessTemplateValue
processTemplateValue
=
(
ProcessTemplateValue
)
parent
;
Identifier
valueIdentifier
=
processTemplateValue
.
getIdentifier
();
VariableDeclaration
declaration
=
context
.
isValidLocalVariableReference
(
valueIdentifier
);
if
(
declaration
!=
null
&&
(
declaration
.
getBaseType
()
==
BaseType
.
INTEGER
||
declaration
.
getBaseType
()
==
BaseType
.
FLOAT
))
{
return
new
BaseType
[]
{
declaration
.
getBaseType
()
};
}
}
return
new
BaseType
[]
{
BaseType
.
FLOAT
,
BaseType
.
INTEGER
};
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment