Subversion Repositories wimsdev

Rev

Rev 5944 | Blame | Compare with Previous | Last modification | View Log | RSS feed

# number with range and/or significant digits
# correct answer format: number1,number2,number3...
# var1=2,-1,0,5 : significant digits in reply. empty or -1 to indicate no significant digits 
# var2=min1:max1,min2:max2,min3:max3,min4:max4.var2 is the range for the correct answer.
# var2 may be assymetrical , or empty 
# answer - min <= reply <= answer + max 
# optional a unit. if pupil ignores this ,the unit of correct answer is assumed
# var3 -1,kg,-1,m,-1,mol : optional unit of the correct answer : -1 for nonexisting or leave empty
# 
# 11/2010 corrected flaw in range when using derived si-units
# 10/2011 corrected typo's and flaws

n=$counter
!if $(reply$n)=?
    goback=0
    maxscore=0
    remark$n=$NOK
    !exit
!endif
errortext=$empty
goback=0
!if $rounding != -1
    errortext=Rounding (rounding=$rounding) needs to be deactivated in the answer type.<br />\
    Set rounding=-1 ;roundingtext=$empty or a remark on the accuracy of the expected reply<br />\
    Use var1 to declare significan digits <br />\
    Use var2 to declare the range of the number min1:max1,min2:max2...
    goback=1
    !exit 
!endif
 # var1 is number of significant digits 1,3,4,5
tg=!itemcnt $(answer$n)
!if $var1 = -1 or $var1=$empty
    checkdigits=-1
!else
    p=!itemcnt $var1
    !if $p!=$tg
        # als var2 perongeluk voor iets anders is bestemd
        errortext=var1=1,-1,6 : var1 is reserved and used for expected digits in answer.
        goback=1
        !exit
    !endif
    checkdigits=1
!endif

!if $var2 != $empty
    p=!itemcnt $var2
    !if $p!=$tg
        # als var2 perongeluk voor iets anders is bestemd
        errortext=var2 is reserved : range min1:max1,min2:max2... per answer<br />dus net zoveel "items" als in't goede antwoord $(answer$$n) : let op gebruik dezelfde eenheid !!
        goback=1
        !exit
    !endif
    range=1
    new_range=$empty
!else
    errortext=var2 is not declared : range min1:max1,min2:max2... per answer<br />dus net zoveel "items" als in't goede antwoord $(answer$$n) : let op gebruik dezelfde eenheid !!
    goback=1
    !exit
!endif

!if $var3=-1 or $var3=$empty
    checkunits=0
!else
    checkunits=1
!endif


ta=!itemcnt $(reply$n)
tg=!itemcnt $(answer$n)

!if $ta != $tg
    ex=!record 38 of $remarkdir/commonremarks.$taal
    errortext=$(reply$n) ... <br />$ex
    maxscore=$[$P6*$maxscore]
    goback=1
 !exit
!endif

yourreply=$empty
reply$n=!singlespace $(reply$n)
AAA=!lower $(reply$n)
aaa=$empty
!for p=1 to $ta
    # check on: distance = 1233.3443
    A=!item $p of $AAA
    test=!replace internal = by , in $A
    t=!itemcnt $test
    !if $t>1
        A=!item 2 of $test
        ex=!record 95 of $remarkdir/commonremarks.$taal
        extra=!append line $ex ($A) to $extra
    !endif
    unitsfilter$p=-1
    aaa=!append line $A to $aaa
!next p
AAA=!lines2items $aaa
ta=!itemcnt $AAA
AAA=!lower $AAA
GGG=$(answer$n)
!if $checkunits=1
    # translate common SI "prefixes" into number notation...
    # this could also called in "precheck.js" [called prefix()]
    PREFIX=*10^-1,*10^1,*10^6,*10^12,*10^15,*10^18,*10^15,*10^12,*10^9,*10^6,*10^3,*10^2,*10^1,*10^-1,*10^-2,*10^-3,*10^-6,*10^-9,*10^-12,*10^-15,*10^-18 
    prefix=déci,déca,méga,téra,péta,exa,peta,tera,giga,mega,kilo,hecto,deca,deci,centi,milli,micro,nano,pico,femto,atto 

    AAA=!replace internal ** by ^ in $AAA
    !for p=1 to 21
        !if $(prefix[$p]) isin $AAA
            AAA=!replace internal $(prefix[$p]) by $(PREFIX[$p]) $ in $AAA
        !endif
    !next p
    AAA=!replace internal ** by * in $AAA
    aaa=$empty
    !for p=1 to $ta
        A=!item $p of $AAA
        t1=!char 1 of $A
        !if $t1=*
            A=!char 2 to -1 of $A
        !endif
        aaa=!append line $A to $aaa
    !next p
    AAA=!lines2items $aaa
    aaa=$empty
    ggg=$empty

    !for p=1 to $ta
        rem$p=$empty
        A=!item $p of $AAA
        A=!nospace $A
        G=!item $p of $GGG
        unit_a=!item $p of $var3
        !if ($unit_a != -1) and (euro notin $unit_a)
            rep=$A
            !if NaN isin $[1*($A)]
                # A= 34 kg : pupils uses a unit ... allowing sqrt(34^2) kg 
                A1=!replace [a-z] by @ in $A
                t1=!positionof char @ in $A1
                t1=!item 1 of $t1
                number=!char 1 to $[$t1-1] of $A
                unit_r=!char $t1 to -1 of $A
                !if euro isin $unit_r
                    testvar=123 $unit_a
                    errortext=!record 53 of $remarkdir/commonremarks.$taal
                    maxscore=$[$maxscore*$P1]
                    goback=1
                    !exit
                !endif
                number=!lower $number
                number=$[1*($number)]
                !if NaN isin $number
                    errortext=!record 89 of $remarkdir/commonremarks.$taal
                    #@Ik kan je antwoord <b>$rep</b> niet kontroleren<br />Geef je antwoord in een geldige <b>SI</b> eenheid...<br />Je "eenheid" <b>$unit ...</b> geeft natuurlijk problemen met nakijken.
                    maxscore=$[$P4*$maxscore]
                    goback=1
                    !exit
                !endif
                a=!exec units-filter $number $unit_r
                !if ERROR isin $a
                    errortext=!record 89 of $remarkdir/commonremarks.$taal
                    #@Ik kan je antwoord <b>$rep</b> niet kontroleren<br />Geef je antwoord in een geldige <b>SI</b> eenheid...<br />Je "eenheid" <b>$unit ...</b> geeft natuurlijk problemen met nakijken.
                    maxscore=$[$P4*$maxscore]
                    goback=1
                    !exit
                !endif
                A=!word 1 of $a
                g=!exec units-filter $G $unit_a
                !if ERROR isin $g
                    errortext=The correct answer $G $unit_a is wrong: $g
                    goback=1
                    !exit
                !endif
                !if $unit_a != $unit_r          
                    ex=!record 92 of $remarkdir/commonremarks.$taal
                    rem$p=!append line $ex to $(rem$p)
                !endif
                factor=!charcnt $[ceil($number/$G)]
                !if $factor>2
                    ex=!record 100 of $remarkdir/commonremarks.$taal
                    #@Je antwoord verondersteld een veel te hoge nauwkeurigheid !
                    maxscore=$[$maxscore*$P3]
                    $(rem$p)=!append line $ex to $(rem$p)
                !else
                    !if $factor>1
                        ex=!record 101 of $remarkdir/commonremarks.$taal
                        #@Je antwoord verondersteld een iets te hoge nauwkeurigheid !<br />$digits decimalen was beter geweest.
                        maxscore=$[$maxscore*$P2]
                        rem$p=!append line $ex to $(extra$p)
                    !endif
                !endif
                G=!word 1 of $g     
                unitsfilter$p=1
            !else
                ex=!record 93 of $remarkdir/commonremarks.$taal
                rem$p=!append line $ex to $(rem$p)
                #unitfilter$p = -1
                #@<br />Je hebt geen eenheid vermeld.<br />Ik neem dus maar aan $unit_a !  
            !endif
            !if $range = 1 and $(unitsfilter$p)=1
                rng=!item $p of $var2
                rng=!replace internal : by , in $rng
                r1=!item 1 of $rng
                r2=!item 2 of $rng
                r1=!exec units-filter $r1 $unit_a
                r2=!exec units-filter $r2 $unit_a
                !if ERROR isin $r2$r1
                    range=0
                !else
                    r1=!word 1 of $r1
                    r2=!word 1 of $r2
                    new_range=!append item $r1:$r2 to $new_range
                !endif
            !endif
        !else
            # no unit used by pupil: that's fine too
            # assuming unit of answer
            !if NaN isin $[1*$A]
                # some bugus text present....preserve basic math
                !for p in sin,cos,tan,sqrt,log,ln,pi
                    P=!toupper $p
                    A=!replace internal $p by $P in $A
                !next p
                A=!replace [a-z\~\!\@\#\$\%\&\_\"\:\;\'\`] by $empty in $A
                A=!lower $A
                !if NaN isin $[1*($A)]
                    errortext=!record 26 of $remarkdir/commonremarks.$taal
                    goback=1
                    maxscore=$[$P6*$maxscore]
                    !exit
                !endif
            !endif
        !endif
        aaa=!append line $A to $aaa
        ggg=!append line $G to $ggg
    !next p
    !if $new_range != $empty
        var2=$new_range
    !endif
    AAA=!lines2items $aaa
    GGG=!lines2items $ggg
!else
    # no units to check: remove all bogus text, but preserve basic maths
    !for p in sin,cos,tan,sqrt,log,ln,pi
        P=!toupper $p
        AAA=!replace internal $p by $P in $AAA
    !next p
    AAA=!replace [a-z\~\!\@\#\$\%\&\_\"\:\;] by $empty in $AAA
    AAA=!tolower $AAA
!endif

ta=!itemcnt $AAA
tg=!itemcnt $GGG
!if $tg>1
    li=<li>
    end_li=</li>
    ul=<ul>
    end_ul=</ul>
!else
    li=$empty
    end_li=$empty
    ul=$empty
    end_ul=$empty
!endif

score=0
!for p=1 to $tg
    A=!item $p of $AAA
    G=!item $p of $GGG
    org=!item $p of $(reply$n)
    !if ? isin $A
        yourreply=!append line $li<span style="color:red">$dontknow</span>$end_li to $yourreply
    !else
        k=green
        k2=green
        k3=green
        score1=1
        r_ex1=&nbsp;
        r_ex2=&nbsp;
        r_ex3=&nbsp;
        !if $range=1
            ra=!item $p of $var2
            ra=!replace internal : by , in $ra
            range1=!item 1 of $ra
            range2=!item 2 of $ra
        !endif
        !if $checkdigits=1 and $(unitsfilter$p)=-1
            # unitsfilter will mess up the digits 1.000 km == 1000 m 
            # and the digits are already checked in the unitsfilter part
            digits=!item $p of $var1
        !else
            digits=-1
        !endif
        !if $digits != -1
            !if . notin $A
                !if $digits !=0
                    # geen digits
                    k3=orange
                    r_ex1=!record 98 of $remarkdir/commonremarks.$taal
                    #@<br />Ik verwachtte eigenlijk een antwoord met $digits decimalen...
                    maxscore=$[$maxscore*$P3]
                !else
                    k3=green
                    r_ex1=!record 99 of $remarkdir/commonremarks.$taal
                    #@<br />Heel goed, het juiste aantal decimalen !
                !endif
            !else
                t=!replace internal . by , in $A
                t2=!item 2 of $t
                t2=!charcnt $t2
                t1=$[$t2 - $digits]
                !if $t1 = 0
                    k3=green
                    r_ex1=!record 99 of $remarkdir/commonremarks.$taal
                    #@<br />Heel goed, het juiste aantal decimalen !
                !else
                    !if $t1>0
                        !if $t1>3
                            k3=red
                            r_ex1=!record 100 of $remarkdir/commonremarks.$taal
                            #@Je antwoord verondersteld een veel te hoge nauwkeurigheid !
                            maxscore=$[$maxscore*$P4]
                        !else
                            !if $t1=1
                                k3=orange
                                maxscore=$[$maxscore*$P1]
                                r_ex1=!record 101 of $remarkdir/commonremarks.$taal
                                #@Je antwoord verondersteld een iets te hoge nauwkeurigheid !<br />$digits decimalen was beter geweest.
                            !else
                                k3=orange
                                maxscore=$[$maxscore*$P3]
                                r_ex1=!record 102 of $remarkdir/commonremarks.$taal
                                #@Je antwoord verondersteld een te hoge nauwkeurigheid !<br />$digits decimalen was beter geweest.
                            !endif
                        !endif
                    !else
                        maxscore=$[$maxscore*$P3]
                        r_ex1=!record 103 of $remarkdir/commonremarks.$taal
                        #@Je antwoord mocht wel wat nauwkeuriger worden opgegeven.<br />$digits decimalen was beter geweest.
                    !endif
                !endif
            !endif
        !endif
        !if $range=1
            !if $G=$A
                k=green
                k2=green
                hier=HIER
            !else
                !if $A >= $[$G - $range1] and $A <= $[$G + $range2]
                    r_ex2=!record 96 of $remarkdir/commonremarks.$taal
                    k2=green
                    k=green
                !else
                    !if $A >= $[$G - 1.5*$range1] and $A <= $[$G + 1.5*$range2]
                        r_ex2=!record 97 of $remarkdir/commonremarks.$taal
                        k2=orange
                        k=orange
                        score1=$P5
                    !else
                        k2=red
                        k=red
                        score1=0
                    !endif
                !endif
            !endif
            #errortext=G=A : $G=$A checking $A &ge; $[$G - $range1] en $A &le; $[$G + $range2] var2=$var2  score1=$score1 k=$k k2=$k2 ex=$r_ex2 hier=$hier
            #goback=1
            #!exit
        !else
            # range=0 : unitsfilter ERROR...
            !if $G=$A
                k=green
                k2=green
            !else
                !if $[round(10*($A))] = $[round(10*($G))]
                    r_ex2=!record 29 of $remarkdir/commonremarks.$taal
                    k2=red
                    k=orange
                    score1=$P3
                !else
                    k=red
                    k2=red
                    score1=0
                !endif
            !endif
        !endif
        !if $[-1*($G)] = $A
            r_ex3=!record 27 of $remarkdir/commonremarks.$taal
            score1=$P6
            k=red
        !endif
        !if $[1/($G)]=$A and $score1=0
            r_ex3=<br /><span style="color:red">$A</span>&nbsp;&nbsp;<span style="color:black">&#191;</span>&nbsp;&nbsp;<span style="color:green">$G</span>
            score1=$P9
            k=red
        !endif
        yourreply=!append line $ $li<span style="color:$k">$org</span>$(rem$p)&nbsp;$r_ex3&nbsp;<span style="color:$k2">$r_ex2</span><span style="color:$k3">$r_ex1</span> $end_li $ to $yourreply
        score=$[$score + $score1]
    !endif
!next p

maxscore=$[$maxscore*$score/$tg]
modulescore=$[$modulescore+$maxscore]

!if $maxscore>0.9
    remark$n=$OK
!else
    !if $maxscore>0.5
        remark$n=$BOK
    !else
        remark$n=$NOK
    !endif
!endif 

goback=0
reply$n=$ul $yourreply $end_ul 
!if $extra != $empty
    remark$n=!append line $extra to $(remark$n)
!endif
!exit