-
Notifications
You must be signed in to change notification settings - Fork 22
/
imsqtiv1.py
executable file
·6334 lines (5327 loc) · 178 KB
/
imsqtiv1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env python
"""Copyright (c) 2004-2008, University of Cambridge.
All rights reserved.
Redistribution and use of this software in source and binary forms
(where applicable), with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions, and the following
disclaimer in the documentation and/or other materials provided with
the distribution.
* Neither the name of the University of Cambridge, nor the names of
any other contributors to the software, may be used to endorse or
promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."""
MIGRATION_VERSION="Version: 2008-06-??"
from types import *
import string
import os, sys, re
from xml.sax import make_parser, handler, SAXParseException
import StringIO
from random import randint
try:
import vobject
GOT_VOBJECT=1
except:
GOT_VOBJECT=0
RESPONSE_PREFIX="RESPONSE_"
OUTCOME_PREFIX="OUTCOME_"
FEEDBACK_PREFIX="FEEDBACK_"
CURRENT_FILE_NAME=None
from iso8601 import *
from xmlutils import *
from rtfutils import *
from lom import *
from imscp import *
from imsqti import *
# QTIParserV1Options
# ------------------
#
class QTIParserV1Options:
def __init__(self):
self.vobject=GOT_VOBJECT
# settable options follow
self.qmdExtensions=0
self.ucVars=0
self.forceFloat=0
self.lang=''
self.noComment=0
self.dtdDir=''
self.cpPath=''
self.prepend_path=None
self.create_error_files=None
# QTIException Class
# ------------------
#
class QTIException:
def __init__ (self,msg,param=None):
if param:
self.msg=msg+": "+param
def __str__(self):
return self.msg
# Exceptions that might be expected to occurr
eUnknownElement="Unknown element"
eUnknownShape="Unknown shape"
eNoParentPackage="QTI object outside <questestinterop> element"
eInvalidStructure="QTI object in unexpected location"
eEmptyCondition="QTI <conditionvar> contained no expressions"
eUndeclaredResponse="Reference to undeclared response variable"
eUndeclaredOutcome="Reference to undeclared outcome variable"
eUnimplementedOperator="Unimplemented operator"
eDuplicateVariable="Duplicate variable name"
eIndexIntoMultiple="Index into multiple"
eUnexpectedContainer="Unexpected Container"
eUnexpectedVarAction="Unexpected Var Action"
eTooManySimilarVariables="Too many similar variables"
eDuplicateResponse="Duplicate Response"
eUnboundResponse="Unbound Response"
eNoParentItem="No parent item"
eNoParentMDContainer="No parent metadata container"
# Exceptions that should never happen!
assertElementOutsideRoot="Element outside root"
VIEWMAP={'administrator':'invigilator','adminauthority':'invigilator',
'assessor':'scorer','author':'author','candidate':'candidate',
'invigilator':'invigilator','proctor':'invigilator','psychometrician':'scorer',
'tutor':'tutor',
'scorer':'scorer'}
D2L_IDENTIFIER_REPLACER = re.compile(r'_(?:ans|str)$', flags=re.I)
#
# QTIObjectV1
#
class QTIObjectV1:
def __init__(self,name,attrs,parent):
self.parent=parent
self.ParseAttributes(attrs)
def ParseAttributes (self,attrs):
for aName in attrs.keys():
if aName[:4]=='xml:':
f=getattr(self,'SetAttribute_xml_'+aName[4:],0)
elif aName[:6]=='webct:':
f=getattr(self,'SetAttribute_webct_'+aName[6:],0)
else:
f=getattr(self,'SetAttribute_'+aName,0)
if f:
f(attrs[aName])
elif not (aName=='xmlns' or ':' in aName):
# suppress warnings about any schema or namespace magic
print "Unknown or unsupported attribute: "+aName
def ReadYesNo (self,value,default):
if value.lower()=="yes":
return 1
elif value.lower()=="no":
return 0
else:
print 'Warning: bad value for yes/no, ignoring "'+value+'"'
def ReadFloat (self,value,default):
try:
return float(value)
except:
print 'Warning: bad number for attribute, ignoring "'+value+'"'
return default
def ReadInteger (self,value,default):
try:
return int(value)
except:
print 'Warning: bad integer for attribute, ignoring "'+value+'"'
return default
def ReadIdentifier (self,value,prefix="ID-"):
value=self.CheckNMTOKEN(value.strip(),prefix)
if ":" in value:
self.PrintWarning('Warning: removing colon from identifier "%s"'%value)
value=value.replace(':','_')
if "." in value:
self.PrintWarning('Warning: removing period from identifier "%s"'%value)
value=value.replace('.','_')
return value
def CheckNMTOKEN (self,token,prefix):
token = token.strip()
unchecked=0
newtoken=""
bad=0
for c in token:
if not c in NMTOKEN_CHARS:
if ord(c)<128:
# character not allowed
bad=1
c="-"
else:
unchecked=1
if not newtoken and not (c in NMSTART_CHARS):
bad=1
newtoken=prefix
newtoken=newtoken+c
if unchecked:
self.PrintWarning('Warning: couldn\'t check NMTOKEN with non-ascii character(s): "%s"'%token)
if bad:
self.PrintWarning('Warning: replacing bad NMTOKEN "%s" with "%s"'%(token,newtoken))
return newtoken
def ReadView (self,value):
view=value.strip().lower()
if view!='all':
if VIEWMAP.has_key(view):
new_view=VIEWMAP[view]
if new_view!=view:
self.PrintWarning('Warning: changing '+view+' to '+new_view)
view=new_view
else:
self.PrintWarning('Warning: ignoring unknown view ('+view+')')
return view
def ConvertAreaCoords (self,shape,value):
# Code fixed up to be much more generous about use of strange separators.
# Mixed comma and space seen in the wild!
#coordStrs=string.split(string.join(string.split(value),''),',')
coords=[]
vStr=[]
sep=0
for c in value:
if c in "0123456789.":
if sep and vStr:
coords.append(int(string.join(vStr,'')))
sep=0
vStr=[]
vStr.append(c)
else:
sep=1
if vStr:
coords.append(int(string.join(vStr,'')))
if shape=='rect':
if len(coords)<4:
self.PrintWarning("Error: not enough coordinates for rectangle, padding with zeros")
while len(coords)<4:
coords.append(0)
coords=[coords[0],coords[1],coords[0]+coords[3]-1,coords[1]+coords[2]-1]
self.PrintWarning("Warning: rectangle conversion assumes pixel-centred coordinates, watch out for off-by-one errors")
elif shape=='ellipse':
if len(coords)<4:
self.PrintWarning("Error: not enough coordinates for ellipse, padding with zeros")
while len(coords)<4:
coords.append(0)
if coords[2]==coords[3]:
self.PrintWarning("Warning: ellipse conversion assumes pixel-centred coordinates, watch out for off-by-one errors")
r=coords[2]/2 # centre-pixel coordinate model again
coords=[coords[0],coords[1],r]
shape='circle'
else:
self.PrintWarning("Warning: ellipse shape is deprecated in version 2")
coords=[coords[0],coords[1],coords[2]/2,coords[3]/2]
return shape,coords
def AddData (self,data):
data=data.strip()
if data:
print "Ignoring data: "+XMLString(data)
def CloseObject (self):
pass
def GetRoot (self):
if not self.parent:
return self
else:
return self.parent.GetRoot()
def GetParser (self):
return self.GetRoot().parser
def GetItemV1 (self):
assert self.parent,QTIException(eNoParentItem)
return self.parent.GetItemV1()
def GetMDContainer(self):
assert self.parent,QTIException(eNoParentMDContainer)
return self.parent.GetMDContainer()
def GetInstructureHelperContainer(self):
assert self.parent,QTIException(eNoParentMDContainer)
return self.parent.GetInstructureHelperContainer()
def SniffRenderHotspot (self):
if self.parent:
return self.parent.SniffRenderHotspot()
else:
return None
def PrintWarning (self, warning, force=0):
if not self.parent:
print warning
else:
self.parent.PrintWarning(warning,force)
def CheckLocation (self, expected_parents, tag, do_assert=True):
if not isinstance(self.parent, expected_parents):
if do_assert:
raise QTIException(eInvalidStructure,tag)
else:
print "Tag (%s) in unexpected location - parent: (%s)" % (tag, self.parent)
return False
return True
# Unsupported
# -----------
#
class Unsupported(QTIObjectV1):
"""Unsupport QTI object"""
def __init__(self,name,attrs,parent):
self.parent=parent
if not isinstance(parent,Unsupported):
print "Unsupported element <"+name+">"
def AddData (self,data):
pass
# Skipped
# -------
#
class Skipped(QTIObjectV1):
"""Skipped QTI object"""
def __init__(self,name,attrs,parent):
pass
#print "Skipping element <"+name+">"
def AddData (self,data):
pass
# QuesTestInterop
# ---------------
#
class QuesTestInterop(QTIObjectV1):
"""
<!ELEMENT questestinterop (qticomment? , (objectbank | assessment | (section | item)+))>
"""
def __init__(self,name,attrs,parent):
QTIObjectV1.__init__(self,name,attrs,parent)
self.path=None
self.cp=None
self.parser=None
self.resources=[]
self.description=None
def SetCP (self,cp):
self.cp=cp
def SetPath (self,path):
self.path=path
def SetParser (self,parser):
self.parser=parser
def SetLOMDescription (self,desc):
self.description=desc
def GetBankId(self):
if CURRENT_FILE_NAME:
return CURRENT_FILE_NAME
else:
return None
def GetBankName(self):
return self.GetBankId
def AddResource (self,resource):
self.resources.append(resource)
self.cp.AddResource(resource)
def AddSection (self,id):
pass
def ResolveURI (self,uri):
# The base URI of this XML file is self.path
# resolve URI to make it a full path
path,discard=os.path.split(self.path)
segments=string.split(uri,'/')
for segment in segments:
if segment==".":
continue
elif segment=="..":
path,discard=os.path.split(path)
else:
path=os.path.join(path,DecodePathSegment(segment))
return path
def CloseObject (self):
if len(self.resources)==1 and self.description:
# A description of the questestinterop object when it only contains one object is probably misplaced
self.PrintWarning('Warning: found qticomment on a questestinterop with single item: treating as metadata for the item *not* the content package')
self.resources[0].GetLOM().GetGeneral().AddDescription(self.description)
elif self.description:
self.cp.GetLOM().GetGeneral().AddDescription(self.description)
# QTIComment
# ----------
#
class QTIComment(QTIObjectV1):
"""
<!ELEMENT qticomment (#PCDATA)>
<!ATTLIST qticomment xml:lang CDATA #IMPLIED >
"""
def __init__(self,name,attrs,parent):
self.data=""
self.lang=None
# appears almost everywhere, no point in checking
QTIObjectV1.__init__(self,name,attrs,parent)
def SetAttribute_xml_lang (self,lang):
self.lang=lang
def CloseObject (self):
if isinstance(self.parent,QuesTestInterop):
self.GetRoot().SetLOMDescription(LOMLangString(self.data,self.lang))
else:
self.PrintWarning('Warning: ignoring qticomment')
def AddData (self,data):
self.data=self.data+data
# QTIMetadataContainer
# --------------------
#
class QTIMetadataContainer(QTIObjectV1):
def GetMDContainer(self):
return self
def SetTitle(self,title):
pass
def AddKeyword(self,keyword):
pass
def AddDescription(self,description):
pass
def AddContributor(self,contributor):
pass
def SetStatus(self,source,value):
pass
def AddEducationalContext(self,context,lomValue):
pass
def AddEducationalDifficulty(self,difficulty,lomValue):
pass
def AddEducationalDescription (self,description):
pass
def SetMaximumScore(self,max):
pass
def SetToolVendor(self,vendor):
pass
# InstructureHelperContainer
# --------------------
#
class InstructureHelperContainer(QTIMetadataContainer):
def __init__(self):
self.sessionControl=None
self.showTotalScore=None
self.whichAttemptToGrade=None
self.assessmentType=None
self.instructureMetadata=None
self.bb_id=None
self.bb_assessment_type=None
self.bb_question_type=None
self.question_type=None
self.bb_max_score=None
self.points_possible=None
self.calculated=None
def GetInstructureHelperContainer(self):
return self
def set_calculated(self, c):
self.calculated = c
self.SetQuestionType("Calculated")
def SetMaxAttempts(self,attempts):
if not self.sessionControl: self.sessionControl = ItemSessionControl()
self.sessionControl.SetMaxAttempts(attempts)
def SetShowFeedback(self, show):
if not self.sessionControl: self.sessionControl = ItemSessionControl()
self.sessionControl.SetShowFeedback(show)
def SetWhichAttemptToGrade(self, which):
self.whichAttemptToGrade = which
def SetShowTotalScore(self, show):
self.showTotalScore = show
def AddMetaField(self, key, val):
if not self.instructureMetadata: self.instructureMetadata = InstructureMetadata()
self.instructureMetadata.AddMetaField(key, val)
def SetPointsPossible(self, points):
self.AddMetaField("points_possible", points)
def SetAssessmentQuestionIdentiferref(self, ref):
self.AddMetaField("assessment_question_identifierref", ref)
def SetAssessmentType(self, type):
self.assessmentType = type
def StartMatchingList(self):
if not self.instructureMetadata: self.instructureMetadata = InstructureMetadata()
self.instructureMetadata.StartMatchingList()
def AddMatchingItem(self, item):
self.instructureMetadata.AddMatchingItem(item)
def SetQuestionBank(self, name, id=None):
self.AddMetaField("question_bank", name)
if id:
self.AddMetaField("question_bank_iden", id)
def SetBBObjectID(self, id):
self.SetAttribute_ident(id)
self.bb_id = id
def SetBBAssessmentType(self, type):
""" Possible values for BB8: Test, Pool, Survey
"""
self.bb_assessment_type = type
def SetBBQuestionType(self, type):
"""These are the possible BB8 values:
Multiple Choice, Calculated, Numeric, Either/Or, Essay,
File Upload, Fill in the Blank Plus, Fill in the Blank,
Hot Spot, Jumbled Sentence, Matching, Multiple Answer,
Multiple Choice, Opinion Scale, Ordering, Quiz Bowl,
Short Response, True/False
"""
if self.question_type: return
self.bb_question_type = type
self.AddMetaField("bb_question_type", type)
def SetQuestionType(self, type):
"""These are the known values:
Matching - Only seen from respondus
"""
self.question_type = type
self.AddMetaField("question_type", type)
def SetBBMaxScore(self, max):
self.bb_max_score = max
self.AddMetaField("max_score", max)
# QTIObjectBank
# -------------
#
class QTIObjectBank(InstructureHelperContainer):
"""
<!ELEMENT objectbank (qticomment? , qtimetadata* , (section | item)+)>
<!ATTLIST objectbank %I_Ident; >
"""
def __init__(self,name,attrs,parent):
QTIObjectV1.__init__(self,name,attrs,parent)
self.question_bank = None
self.question_bank_name = None
self.CheckLocation((QuesTestInterop),"<objectbank>")
self.PrintWarning('Warning: objectbank not supported, looking inside for items')
self.ParseAttributes(attrs)
def SetAttribute_ident (self,id):
self.question_bank = id
def SetBankName(self, name):
self.question_bank_name = name
def GetBankId(self):
return self.question_bank
def GetBankName(self):
if self.question_bank_name:
return self.question_bank_name
else:
return self.question_bank
def AddSection (self,id):
pass
# mat_extension
# -------------
#
class WCTMatExtension(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
QTIObjectV1.__init__(self,name,attrs,parent)
self.PrintWarning('Warning: mat_extension not supported, looking inside for needed data.')
self.calc = None
def GetCalculated(self):
if not self.calc: self.calc = Calculated()
return self.calc
def add_formula(self, formula):
self.GetCalculated()
self.calc.formula = formula
def AppendElement(self, data):
self.parent.AppendElement(data)
def CloseObject(self):
if self.calc:
self.GetInstructureHelperContainer().set_calculated(self.calc)
## D2L Calculated classes
class D2LVariable(QTIObjectV1):
def __init__(self, name, attrs, parent):
self.parent = parent
self.CheckLocation((WCTMatExtension),"<variable>")
self.calc = parent.GetCalculated()
self.var = Var()
self.ParseAttributes(attrs)
def SetAttribute_name(self, name):
self.var.name = name
def set_min(self, min):
self.var.min = min
def set_max(self, max):
self.var.max = max
def set_decimal(self, val):
self.var.scale = val
def CloseObject(self):
self.calc.add_var(self.var)
class D2LMinvalue(QTIObjectV1):
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((D2LVariable),"<minvalue>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.set_min(self.data)
class D2LMaxvalue(QTIObjectV1):
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((D2LVariable),"<maxvalue>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.set_max(self.data)
class D2LDecimalplaces(QTIObjectV1):
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((D2LVariable),"<decimalplaces>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.set_decimal(self.data)
class BBMatFormattedText(QTIObjectV1):
"""Holds question and response data in BB8 exports.
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.type=None
def SetAttribute_type(self, type):
self.type = type
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.AppendElement(xhtml_text(self.data))
# material_table
# -------------
#
class WCTMaterialTable(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
QTIObjectV1.__init__(self,name,attrs,parent)
self.PrintWarning('Warning: material_table not supported, looking inside for needed data')
def SetAttribute_label (self,id):
pass
class WCTCalculatedAnswer(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.ihc = self.GetInstructureHelperContainer()
self.calc = self.ihc.calculated
self.CheckLocation((ItemProcExtension),"<calculated>")
self.ParseAttributes(attrs)
def SetAttribute_webct_precision(self, precision):
self.calc.answer_scale = precision
def SetAttribute_webct_toleranceType(self, type):
self.calc.answer_tolerance_type = type
def SetAttribute_webct_tolerance(self, tol):
self.calc.answer_tolerance = tol
def AddRule(self, rule):
if rule.identifier and rule.identifier == "SCORE":
if rule.expression and rule.expression.arguments:
if rule.expression.arguments[1]:
self.ihc.SetBBMaxScore(rule.expression.arguments[1].value)
# calculated
# -------------
#
class CalculatedNode(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.GetInstructureHelperContainer().SetBBQuestionType("Calculated")
self.CheckLocation((ItemProcExtension, WCTMatExtension),"<calculated>")
self.calc = Calculated()
def add_var(self, var):
self.calc.add_var(var)
def add_var_set(self, var):
self.calc.add_var_set(var)
def add_formula (self, formula):
self.calc.formula = formula
def CloseObject(self):
self.GetInstructureHelperContainer().set_calculated(self.calc)
# formula
# -------------
#
class CalculatedFormula(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode, CalculatedFormulas, WCTMatExtension),"<formula>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.add_formula(self.data)
# formulas
# -------------
#
class CalculatedFormulas(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.CheckLocation((CalculatedNode),"<formulas>")
self.ParseAttributes(attrs)
def SetAttribute_decimal_places(self, places):
self.parent.calc.formula_decimal_places = places
def add_formula (self, formula):
self.parent.calc.add_formula(formula)
def CloseObject (self):
pass
# answer_scale
# -------------
#
class BB8AnswerScale(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode),"<answer_scale>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.calc.answer_scale = self.data
# answer_tolerance
# -------------
#
class BB8AnswerTolerance(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode),"<answer_tolerance>")
self.ParseAttributes(attrs)
def AddData (self,data):
self.data=self.data+data
def SetAttribute_type(self, type):
self.parent.calc.answer_tolerance_type = type
def CloseObject (self):
self.data=self.data.strip()
self.parent.calc.answer_tolerance = self.data
# unit_points_percent
# -------------
#
class BB8UnitPointsPercent(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode),"<unit_points_percent>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.calc.unit_points_percent = self.data
# unit_required
# -------------
#
class BB8UnitRequired(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode),"<unit_required>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.calc.unit_required = self.data
# unit_value
# -------------
#
class BB8UnitValue(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode),"<unit_value>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.calc.unit_value = self.data
# unit_case_sensitive
# -------------
#
class BB8UnitCaseSensitive(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode),"<unit_case_sensitive>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.calc.unit_case_sensitive = self.data
# partial_credit_points_percent
# -------------
#
class BB8PartialCreditPointsPercent(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode),"<partial_credit_points_percent>")
def AddData (self,data):
self.data=self.data+data
def CloseObject (self):
self.data=self.data.strip()
self.parent.calc.partial_credit_points_percent = self.data
# partial_credit_tolerance
# -------------
#
class BB8PartialCreditTolerance(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.data=""
self.CheckLocation((CalculatedNode),"<partial_credit_tolerance>")
self.ParseAttributes(attrs)
def AddData (self,data):
self.data=self.data+data
def SetAttribute_type(self, type):
self.parent.calc.partial_credit_tolerance_type = type
def CloseObject (self):
self.data=self.data.strip()
self.parent.calc.partial_credit_tolerance = self.data
# vars
# -------------
#
class BB8Vars(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.CheckLocation((CalculatedNode),"<vars>")
self.calc = parent.calc
def add_var(self, var):
self.calc.add_var(var)
# var_sets
# -------------
#
class BB8VarSets(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.CheckLocation((CalculatedNode),"<var_sets>")
self.calc = parent.calc
def add_var_set(self, var):
self.calc.add_var_set(var)
# var_set
# -------------
#
class CalculatedVarSet(QTIObjectV1):
"""
"""
def __init__(self,name,attrs,parent):
self.parent=parent
self.CheckLocation((BB8VarSets, CalculatedNode),"<var_set>")
self.var_set = VarSet()
self.ParseAttributes(attrs)
def SetAttribute_ident(self, iden):
self.var_set.ident = iden
def add_var(self, var):
self.var_set.add_var(var)