Jump to content

Recommended Posts

Posted (edited)

Link to current version

NOTE! As of writing this project is fare from finished. But I claimed I would have something going in @Vollys chat topic by to night, so her is the start. Let's call it version 0.001 ..:D

For a while I have been looking for a project implementing a flash card, memo card, memory game type of software. On one of my rare visits recently I happened to see @Volly aske for the same thing In chat and in help. So I thought 'why not just do it'? You should read the two topics to get a feel for what the project is about at the moment.

Setup : Create the files dbgtools.au3, au3FlashCard.au3, au3FlashCardTest.au3. Copy content from next post. I use SciTE4Autoit3 as my editor. dbgtools use ConsoleWrite as output so if you use another editor you have to make some adjustments in dbgtools.au3. I have the files in the same directory. au3FlashCard.au3 and au3FlashCardTest.au3 reference each other so you can run any of them to run the tests.

LOG:

22.04.2009 version 0.1: Implemented most of the core functionality for sequential test mode. Takes a lot longer (not in work but timespan) and more effort (as in how is it possible to forget all of this in such a short time ) than planed but I'm slowly creeping toward the finishing line..:o

30.03.2009 version 0.001: UDF API core defined (but still moving a bit while tests are written). Some implemented with unit tests. Several tests fail due to missing implementation in UDF and test setup.

Edited by Uten
Posted

FILE: au3FlashCards.au3

; FILENAME: au3FlashCards.au3
; PURPOSE: Functions to support a flash card program
;
; INITIAL NOTES:
#cs FILEFORMAT:
; au3 flashcard card format
; Select card type. Write question. Write optional answers seperated by |. Correct answer is enclosed by [].
; Card type:=text|option|checkbox|mathdrill|mathformula
; question:= What is a horse
; Answer options:=fruite|flower|[animal]

[text card]
; Check agains matching text
; Check agains text pattern

[option card]
; check agains selected regular text based option.
; Check agains slected picture based option.

[checkbox card]
; Chek agains slected check boxes

[math drill]
; Check agains answer or formula? Formula could check agains answers by using the formula?
#CE - FILEFORMAT
#include-once
#include <dbgtools.au3>
#include <au3FlashCardsTest.au3>
global $gfsDeckNames = ''
global $gfsCurrentDeckID = 0
Global $gfsCurrentCardID = 0
global $gfsArrDecks = ''
global $gfsDeckMode = ''
Global Enum $gfsEnumDeckMode0, $gfsEnumDeckMode1
Func _fsGetNextCard(ByRef $question, ByRef $answers, ByRef $type, $previousID=-1)
    ; RETURN 0 if there is no next card or on error.
    ; ByRef $question: Returns a string with the question.
    ; ByRef $answers: Returns an array with the answer sugestions.
    ; ByRef $type: Returns a string with answer type information.
    ; $previousID: Optional. Provide Id of the previous question. If the deck was opened in 
    ;   sequential mode the next card id is delivered.
    $deck = _fsShufleDecks()
    If @error then Return SetError(@error, @extended, 0)
    ; Read next card from 
    Local $cardID = _fsGetNextCardID($previousID)
EndFunc
Func _fsGetLastCardID()
    ; Return last cardID in Current deck
    Local $sn = IniReadSectionNames(_fsGetCurrentDeck())
    If err('Could not read section names') Then 
        Return SetError(@error, @extended, 0)
    Else
        dbgarr($sn)
    EndIf
    Return $sn[0]
EndFunc
Func _fsSetCurrentCardID($cardID)
    ; External Overide of sequence 
    $gfsCurrentCardID = $cardID
EndFunc
func _fsGetNextCardID($fsMode=0, $previousID=-1)
    ; Determine deck based on information provided in _fsOpenDeck$
    ; Get the next cardID. Thyis could depend on $fsMode indicating
    ;   0=sequensial read, 
    ;   1=random but not allready read in this session
    ;   2=Memory access mode (1,+3,+7,+14,+30,+90,+180,+352)
    Local $ret=0
    assert(false, 'functionality not implemented')
    Switch $gfsDeckMode
        case 0 ;Sequential read. Read until last card in deck. 
            ;Then Switch to next deck in array. Repet until last card.
            If $previousID >= 0 Then 
                If $previousID <= _fsGetLastCardID() -1 Then 
                    $ret = $previousID + 1
                Else
                    ; The caller must shufle or set next deck
                    ; NOTE: Should SetExteneded be done to indicate why return is 0?
                    $ret = 0
                EndIf
            ElseIf $gfsCurrentCardID <= _fsGetLastCardID() Then 
                    $gfsCurrentCardID += 1
                    $ret = $gfsCurrentCardID
            Else
                ; First card in next deck
                $gfsCurrentCardID = 1
                $gfsCurrentDeckID += 1
                If $gfsCurrentDeckID > $gfsArrDecks[0] Then $gfsCurrentDeckID = 1
                
                assert(false, 'functionality not implemented')
            EndIf
        case 1 ; Random but no repetition (of correctly answered card)
            assert(false, 'Random mode functionality not implemented')
        case 2 ; Memory access (strengthening) mode (1,+3,+7,+14,+30,+90,+180,+352)
            assert(false, 'Memory access/strengthening functionality not implemented')
    EndSwitch
    Return $ret
EndFunc
Func _fsGetCardByID(ByRef $question, ByRef $answer, $cardID)
    ;Read card matching 
    assert(false, 'functionality not implemented')
EndFunc
Func _fsCheckAnswer($answer, $cardID)
    ; RETURN: True or false
    ; Check answer given against $cardID
    assert(false, 'functionality not implemented')
EndFunc
Func _fsRecordAnswer($bool, $cardID, $fsMode=0, $static=0)
    ; $bool = true or false determines if the giwen asver was correct.
    assert(false, 'functionality not implemented')
EndFunc
Func _fsWriteTrackRecord($bool, $cardID, $fsMode=0)
    ; TODO: Personal or global tracking of answers?
    ; Personal Tracking and recording is prefered.
    ; Application is portableapps compatible as efault
    ; Application ini could overide this and create tracking IniDelete
    ; in profile folder.
    assert(false, 'functionality not implemented')
EndFunc
Func _fsOpenDecks($deckNames, $deckMode=$gfsEnumDeckMode0)
    ; Return True on success, false on error
    ; $deckNames is a | delimited list of pathnames (or ID) to ini(later on z7) files containing a deck.
    ; $deckMode = 0 --> sequential shufeling in _fsShufleDecks()
    ; $deckMode = 1 --> random shufeling in _fsShufleDecks()
    Local $arr = StringSplit($deckNames, '|')
    Local $i
    If $arr[0] = 1 then 
        If not FileExists($arr[1]) Then Return SetError(1,0, false)
    Else
        For $i = 1 to $arr[0]
            If Not FileExists($arr[$i]) Then Return SetError(1, 1, false)
        Next
        $gfsArrDecks = $arr
        $gfsDeckMode = $deckMode
    EndIf
    Return true
EndFunc
Func _fsShufleDecks()
    ; If several decks are provided in _fsOpenDecks then set current deck to use
    ; If _fsOpenDecks has not been called return error.
    If Not IsArray($gfsArrDecks) Then Return SetError(1,0,'')
    ; Shuffle
    $gfsCurrentDeckID = Random(1, $gfsArrDecks[0], 1)
    Return $gfsArrDecks[$gfsCurrentDeckID]
EndFunc

Func _fsGetCurrentDeck()
    ; Return current deck pathname (or ID)
    If $gfsDeckNames = '' Then Return SetError(1,0, '')
    ;
    Return $gfsArrDecks[$gfsCurrentDeckID]
EndFunc
Func _fsSetCurrentDeck($deck)
    Local $i
    If Not FileExists($deck) Then Return SetError(1,0,False)
    If IsNumber($deck) Then 
        If $deck >= $gfsArrDecks[0] Then $gfsCurrentDeckID = $deck
    Else
        For $i = 1 to $gfsArrDecks[0]
            If $deck = $gfsArrDecks[$i] Then 
                $gfsCurrentDeckID = $i
                ExitLoop
            EndIf
        Next 
        If $i > $gfsArrDecks[0] Then
            ; deck asked for is not in list. Make new call to _fsOpenDecks
            Return SetError(2, 0, false)
        EndIf
    EndIf
    Return true
EndFunc

If StringLeft(@ScriptName, StringLen(@scriptname)-4) = 'au3FlashCards' Then suite_sfTestMain()oÝ÷ Ù±H,F®ÜYZ²­ÛzËZ»Ûjëh×6; FILENAME: au3FlashCardsTest.au3
; PURPOSE: Unit test collection against au3FlashCards.au3
#include-once
#include <au3FlashCards.au3>
#include <dbgtools.au3>
#region - Global variables
Global $test_fsGetLastCardID = 4
Global $test_fsGetCurrentDeck = 'Test_au3FlashCards.ini'
Global $fstsr = 0 ; flash card test sucess rate
Global $test_fsArrtestDecks[4] = [3, 'testDeck1.ini', 'testDeck2.ini', 'testDeck2.ini']
#EndRegion - Global variables
#Region - test common maintenance routines
Func testCreateTestDeckAndData($iniFile)
    ; PRPOSE: Creat test data:
    If FileExists($iniFile) then FileDelete($iniFile)
    ; Use as identifier in the test 
    IniWriteSection($iniFile, StringRight($iniFile, StringLen($iniFile) - StringInStr($iniFile, '\', 0, -1)), 'pathname=' & $inifile)
    ; Various sections following the quiz crad format
    IniWriteSection($iniFile, 'quiz_1','CardType=text' & @CRLF & _
            'question=Can you ride on a horse?'  & @CRLF & _
            'answer=[yes]|[you can]|[ofcource]')
    iniWriteSection($iniFile, 'quiz_2', 'CardType=option' & @CRLF & _
        'question=The capitol of Norway is named?' & @CRLF & _
        'answer=[Oslo]|Stocholm|Copenhagen|Paris' & @CRLF & _
        'image=OsloTownHall.jpg' & @CRLF & _
        'link=en.wikipedia.org/norway')
    iniWriteSection($iniFile, 'quiz_3', 'CardType=check' & @CRLF & _
        'question=A dolphine is' & @CRLF & _
        'answer=[a mamal]|[a see mamal]|[a clever animal]|a shark,a wale,a fish,a land animal'  & @CRLF & _
        'image=dolphine.jpg' & @CRLF & _
        'link=en.wikipedia.org/dolphine')
    IniWriteSection($iniFile, 'quiz_4', 'CardType=image option' & @CRLF & _
        'question=Select the picture displaying a valve' & @CRLF & _
        'answer=house.jpg|img2.jpg|[house.jpg]|cotage.jpg')
    err('uhh, what happend?')
EndFunc
Func testCreateData()
    Local $i
    For $i = 1 to $test_fsArrTestDecks[0]
        testCreateTestDeckAndData($test_fsArrTestDecks[$i])
    Next

EndFunc
Func testCleanUp()
    Local $i
    For $i = 1 to $test_fsArrTestDecks[0]
        If FileExists($test_fsArrTestDecks[$i]) Then FileDelete($test_fsArrTestDecks[$i])
    Next
EndFunc
#EndRegion - test common maintenance routines
; ---------------------------------------------
#Region - test suite routines
func suite_sfTestMain()
    testCreateTestDeckAndData($test_fsGetCurrentDeck)
    test_fsGetNextCard()
    test_fsGetLastCardID()
    test_fsGetNextCardID()
    test_fsGetCardByID()
    test_fsCheckAnswer()
    test_fsRecordAnswer()
    test_fsWriteTrackRecord()
    test_fsOpenDecks()
    test_fsShufleDecks()
    test_fsGetCurrentDeck()
    test_fsSetCurrentDeck()
    assertreport()
    ;dbg('TEST RESULTS ' & $dbgtoolsAssertCallCount - $fstsr & ' of ' & $dbgtoolsAssertCallCount &' asserts failed. ' )
EndFunc
#EndRegion - test suite routines
; ---------------------------------------------
Func test_fsGetNextCard()
    ; _fsGetNextCard(ByRef $question, ByRef $answers, ByRef $type, $previousID=-1)
    Local $question, $answer, $type
    assert(0=_fsGetNextCard($question, $answer, $type), 'Call to _fsGetNextCard(...) without previous call to _fsOpenDecks should return 0 and set @error=1')
EndFunc
Func test_fsGetLastCardID()
    
    ; Return last cardID in Current deck
    assert($test_fsGetLastCardID = _fsGetLastCardID(), 'Expected _fsGetLastCradID() to return ' & $test_fsGetLastCardID  & ' in deck ' & _fsGetCurrentDeck())
EndFunc
Func test_fsGetNextCardID()
    ; _fsGetNextCardID( $fsMode=0, $previousID=-1)
    ; Determine deck based on information provided in _fsOpenDeck$
    ; Get the next cardID. Thyis could depend on $fsMode indicating
    ;   0=sequensial read, 
    ;   1=random but not allready read in this session
    ;   2=Memory access mode (1,+3,+7,+14,+30,+90,+180,+352)
    
    ; mode=0 Sequencial read 
    Local $cardIDs[3] 
    assert(_fsGetNextCardID(0) = 1, '_fsGetNextCardID(1,0) returned unexpected result')
    ; This call should not affect a new call with (0)
    assert(_fsGetNextCardID(0, 2) = 3, '_fsGetNextCardID(1,0) returned unexpected result')
    assert(_fsGetNextCardID(0, 3) = 4, '_fsGetNextCardID(1,0) returned unexpected result')
    assert(_fsGetNextCardID(0) = 2, '_fsGetNextCardID(1,0) returned unexpected result')
    assert(_fsGetNextCardID(0, -1) = 3, '_fsGetNextCardID(1,0) returned unexpected result')
    ; mode=1
    
    ; mode=2
    assert(0, 'NOT IMPLEMENTED: Tests are not implemented')
EndFunc
Func test_fsGetCardByID()
    ; _fsGetCardByID(ByRef $question, ByRef $answer, $cardID)
    ;Read card matching 
    assert(0, 'NOT IMPLEMENTED: Tests are not implemented')
EndFunc
Func test_fsCheckAnswer()
    ; _fsCheckAnswer($answer, $cardID)
    ; RETURN: True or false
    ; Check answer given against $cardID
    assert(0, 'NOT IMPLEMENTED: Tests are not implemented')
EndFunc
Func test_fsRecordAnswer()
    ; _fsRecordAnswer($bool, $cardID, $fsMode=0, $static=0)
    ; $bool = true or false determines if the giwen asver was correct.
    assert(0, 'NOT IMPLEMENTED: Tests are not implemented')
EndFunc
Func test_fsWriteTrackRecord()
    ; _fsWriteTrackRecord($bool, $cardID, $fsMode=0)
    ; TODO: Personal or global tracking of answers?
    ; Personal Tracking and recording is prefered.
    ; Application is portableapps compatible as efault
    ; Application ini could overide this and create tracking IniDelete
    ; in profile folder.
    assert(0, 'NOT IMPLEMENTED: Tests are not implemented')
EndFunc
Func test_fsOpenDecks()
    ;_fsOpenDecks($deckNames, $deckMode=0)
    ; $deckNames is a | delimited list of pathnames (or ID) to ini(later on z7) files containing a deck.
    ; Check for error when deck does not exist.
    _fsOpenDecks('nonexistsingdeck.ini')
    assert(@error = 1 AND @extended = 0, '_fsOpendeck(...) should return error01 as deck does not exists')
    _fsOpenDecks($test_fsGetCurrentDeck & '|nonexistsingdeck.ini|Anothernonexistsingdeck.ini')
    assert(@error = 1 and @extended = 1 , 'Some of the $deckNmaes entries could not be located')
    _fsOpenDecks($test_fsGetCurrentDeck)
    assert(@error=0, 'Expected @error to be 0 as ' & $test_fsgetCurrentDeck & ' should exist') 
    ; Check for error when deck in list does not exsist.
    
    ; Check agains existing decks
    testCreateData()
    ;
    Local $i, $s
    For $i = 0 to $test_fsArrtestDecks[0]
        $s &= $test_fsArrtestDecks[$i] & '|'
    Next 
    StringTrimRight($s, StringLen('|'))
    assert(_fsOpenDecks($s), '_fsOpenDecks should return true')
    ; 
    testCleanUp()
EndFunc

Func test_fsShufleDecks()
    ; If several decks are provided in _fsOpenDecks then set current deck to use
    ; If _fsOpenDecks has not been called return error.
    _fsOpenDecks($test_fsGetCurrentDeck)
    assert($test_fsGetCurrentDeck = _fsShufleDecks(), 'Unexpected return by _fsShufleDecks() should return same value as $test_fsGetCurrentDeck as this should be the only open deck')
    assert(false, 'TODO: Need more tests to check all error cionditions')
EndFunc
Func test_fsGetCurrentDeck()
    ; Return current deck pathname (or ID)
    assert($test_fsGetCurrentDeck = _fsGetCurrentDeck(), '_fsGetCurrentDeck() returned unexpected result compared to $test_fsGetCurrentDeck:=' & $test_fsGetCurrentDeck)
EndFunc
Func test_fsSetCurrentDeck()
    assert(false, 'TODO: No test implemented')
EndFunc

;----------------------------------------------------------------------
; call test suite
If StringLeft(@ScriptName, StringLen(@scriptname)-4) = 'au3FlashCardsTest' Then suite_sfTestMain()oÝ÷ Ù±H,G[Ú(Æ®ßöÚºÚ"µÍÚ[ÛYK[ÛÙBÛØ[    ÌÍÙÝÛÛÐÜÙØ[ÛÝ[HÛØ[    ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[H[È  ÌÍÛÙË  ÌÍÛ[OPØÜ[S[X   ÌÍÙPÜ   ÌÍÙ^P^[Y
BZY ÌÍÙ  ÝÈ[BYÊ   ÌÎNÑTÔ  ÌÎNÈ [È ÌÍÛÙË  ÌÍÛ[K    ÌÍÙ  ÌÍÙ^
BBT]Ù]Ü   ÌÍÙ  ÌÍÙ^YJBQ[ÙRY    ÌÍÙ^ ÝÈ[BYÊ   ÌÎNÑVSQ  ÌÎNÈ [È ÌÍÛÙË  ÌÍÛ[K    ÌÍÙ  ÌÍÙ^
BBT]Ù]^[Y
    ÌÍÙ^YJBQ[YT][ÙB[[Â[ÈÊ    ÌÍÛÙË  ÌÍÛ[OPØÜ[S[X   ÌÍÙPÜ   ÌÍÙ^P^[Y ÌÍÜOIÌÎNÉÌÎNÊBPÛÛÛÛUÜ]J   ÌÍÜH [È ÌÎNÊ ÌÎNÈ [È ÌÍÛ[H    [È ÌÎNÊH
    ÌÎNÈ [È ÌÍÙ  [È ÌÎNÊJ    ÌÎNÈ [È ÌÍÙ^ [È ÌÎNÊH    ÌÎNÈ [È ÌÍÛÙÈ  [ÈÔB[[Â[ÈÐ ÌÍØ  ÌÍÛ[HPØÜ[S[X   ÌÍÙPÜ   ÌÍÙ^P^[Y
BYÊ    ][ÝÐTVHSTÕTXÝ[I][ÝÈ   [ÈPÝ[
    ÌÍØK ÌÍÛ[K    ÌÍÙ  ÌÍÙ^
BSØØ[ ÌÍÚBQÜ  ÌÍÚHHÈPÝ[
    ÌÍØKLBBRYÝ[ÓY
    ÌÍØÉÌÍÚWKJHH ][ÝÊ  ][ÝÈ[BBYÊ    ÌÍØÉÌÍÚWH    [È ][ÝÈ  ÉÏOIÌÍØÉ][ÝÈ    [È ÌÍÚH [È ][Ý×I][ÝÈ   ÌÍÛ[K    ÌÍÙ  ÌÍÙ^
BBQ[ÙBBBYÊ    ][ÝÉÌÍØÉ][ÝÈ    [È ÌÍÚH [È ][Ý×NI][ÝÈ  [È ÌÍØÉÌÍÚWK    ÌÍÛ[K    ÌÍÙ  ÌÍÙ^
BBQ[YS^YÊ  ][ÝÐTVHSTÓN][ÝË    ÌÍÛ[K    ÌÍÙ  ÌÍÙ^
B[[Â[ÈÜÙ
    ÌÍØÛÛ  ÌÍÛÙÏI][ÝÉ][ÝË ÌÍÛ[OPØÜ[S[X   ÌÍÙPÜ   ÌÍÙ^P^[Y
BIÌÍÙÝÛÛÐÜÙØ[ÛÝ[
ÏHBRY  ÌÍØÛÛ[ ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[
ÏHBRYÝ    ÌÍØÛÛ[Ê   ÌÎNÐTÔÑTRSQ    ÌÎNÈ [È ÌÍÛÙË  ÌÍÛ[K    ÌÍÙ  ÌÍÙ^
BT]Ù]Ü    ÌÍÙ  ÌÍÙ^[X   ÌÍØÛÛ
JB[[Â[ÈÜÙÜ
    ÌÍØØ[XÚÏI][ÝÉ][ÝÊBRY  ÌÍØØ[XÚÈ  ÉÝÈ  ][ÝÉ][ÝÈ[BNÈØ[XÚÈÒQÓUTN   Ù[Ý[Û[YIÝÊ ÌÍÜÝXÙÜË ÌÍÙZ[K   ÌÍØÛÝ[
BBPØ[
    ÌÍØØ[XÚË  ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[  ÌÍÙÝÛÛÐÜÙØ[ÛÝ[H ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[  ÌÍÙÝÛÛÐÜÙØ[ÛÝ[
BQ[ÙBBYÊ  ÌÎNËKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKIÌÎNÊBBYÊ ÌÎNÔÝXÙÜÎIÌÎNÈ    [È ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[  [È ÌÎNËZ[ÎIÌÎNÈ [È ÌÍÙÝÛÛÐÜÙØ[ÛÝ[H ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[  [È ÌÎNËØ[ÎIÌÎNÈ    [È ÌÍÙÝÛÛÐÜÙØ[ÛÝ[
BBYÊ   ÌÎNËKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKIÌÎNÊBQ[Y[[Â[ÈÝÙ
BSØØ[ ÌÍØÜÙÛÝ[HTÙ]ÜK
BXÜÙ
    ÌÎNÑÜÙYÜXZÙÈ]YIÌÎNÊK ÌÎNÑÛÝ[^XÝY[ÙHÛHIÌÎNÊBTÙ]ÜJBXÜÙ
    ÌÎNÙÜÙY^[YXZÙÈ]YIÌÎNÊK    ÌÎNÑÛÝ[^XÝY[ÙHÛHIÌÎNÊBTÙ]^[Y

BXÜÙ
[ÙHH   ÌÎNÙÜL[^[YLÚÝ[XZÙH]H[ÙIÌÎNÊK ÌÎNÑÛÝ[^XÝYYHÛHIÌÎNÊBXÜÙÜ

B[[ÂYÝ[ÓY
ØÜ[YKÝ[Ó[ØÜ[YJKM
HH  ÌÎNÙÝÛÛÉÌÎNÈ[]ÝÙ
B[Y
  • 4 weeks later...
Posted

FILE: au3FlashCards.au3

[autoit]; FILENAME: au3FlashCards.au3

; PURPOSE: Functions to suport a flash card program

;

; INITIAL NOTES:

#CS FILEFORMAT:

; au3 flashcard card format

; Select card type. Write question. Write optional answers seperated by |. Correct answer is enclosed by [].

; Card type:=text|option|checkbox|mathdrill|mathformula

; question:= What is a horse

; Answer options:=fruite|flower|[animal]

[text card]

; Check agains matching text

; Check agains text pattern

[option card]

; check agains selected regular text based option.

; Check agains slected picture based option.

[checkbox card]

; Chek agains slected check boxes

[math drill]

; Check agains answer or formula? Formula could check agains answers by using the formula?

#CE - FILEFORMAT

#include-once

#include <dbgtools.au3>

#include <au3FlashCardsTest.au3>

AutoitSetOption('MustDeclareVars',1)

global $gfsDeckNames = ''

global $gfsCurrentDeckID = 0

Global $gfsCurrentCardID = 0

global $gfsArrDecks[1] = [0]

global $gfsDeckMode = ''

Global Enum $gfsEnumDeckMode0, $gfsEnumDeckMode1

Func __fsGetQuizType(ByRef $quizData)

; Return quiz type

;text|option|checkbox|mathdrill|mathformula

If not IsArray($quizData) Then Return SetError(1,0,0)

For $i = 1 to $quizData[0][0]

If $quizData[$i][0] == 'CardType' Then ExitLoop

Next

If $i > $quizData[0][0] Then Return SetError(2,0,0)

Return $quizData[$i][1]

EndFunc

func _fsCloseDecks()

$gfsDeckMode = ''

$gfsArrDecks[0] = 0

$gfsCurrentCardID = 0

$gfsCurrentDeckID = 0

$gfsDeckNames = ''

EndFunc

Func _fsOpenDecks($deckNames, $deckMode=$gfsEnumDeckMode0)

; Return True on success, false on error

; $deckNames is a | delimited list of pathnames (or ID) to ini(later on z7) files containing a deck.

; $deckMode = 0 --> sequential shufeling in _fsShufleDecks()

; $deckMode = 1 --> random shufeling in _fsShufleDecks()

;

; @error = 1, @extended=0: The one filename provided could not be located.

; @error = 1, @extended>0: File nr @extended in the list could not be located.

; Make sure we have an array

Local $arr , $i

If IsArray($decknames) then

$arr = $decknames

Else

$arr = StringSplit($deckNames, '|')

EndIf

If $arr[0] == 1 then

If not FileExists($arr[1]) Then

err('Could not locat deck file: ' & $arr[1],@ScriptLineNumber-1, 1,0)

$gfsArrDecks[0] = 0

$gfsCurrentDeckID = 0

Return SetError(1,0, false)

EndIf

Else

For $i = 1 to $arr[0]

if $arr[$i] <> "" then

If Not FileExists($arr[$i]) Then

err('Could not locat deck file:' & $arr[$i] & ' in ' & @WorkingDir,@ScriptLineNumber-1, 1,0)

$gfsArrDecks[0] = 0

$gfsCurrentDeckID = 0

; Return @error=1 and @extended = index of missing file.

Return SetError(1, $i, false)

EndIf

EndIf

Next

EndIf

$gfsArrDecks = $arr

$gfsDeckMode = $deckMode

; TODO: How does $deckMode affect first $gfsCurrentDeckID?

$gfsCurrentDeckID = 1

Return true

EndFunc

Func _fsShufleDecks()

; If several decks are provided in _fsOpenDecks then set current deck to use

; If _fsOpenDecks has not been called return error.

;

; @error=1: No files in the list. Need to call _fsOpenDecks

If Not IsArray($gfsArrDecks) Then Return SetError(1,0,'')

; Shuffle

If $gfsArrDecks[0] == 0 then

err('deck count=0. Need valide call to _fsOpenDecks(...)')

Return SetError(1,0,0)

ElseIf $gfsArrDecks[0] == 1 Then

$gfsCurrentDeckID = 1

Else

$gfsCurrentDeckID = Random(1, $gfsArrDecks[0], 1)

EndIf

Return $gfsArrDecks[$gfsCurrentDeckID]

EndFunc

Func _fsGetCurrentDeck()

; Return current deck pathname (or ID)

If $gfsCurrentDeckID == 0 Then

err('no available decks.Make call to _fsOpendecks(...)?')

Return SetError(1,0, '')

EndIf

;

Return $gfsArrDecks[$gfsCurrentDeckID]

EndFunc

Func _fsSetCurrentDeck($deck)

;@error=1, @extended=0: deck not in list

;@error=2, $extended=MAX_ID; ID Out of bounds

;@error=2, $extended=0; ID equals 0

Local $i

If IsNumber($deck) Then

If $deck == 0 then

Return SetError(2, 0, $gfsArrDecks[$gfsCurrentDeckID])

ElseIf $deck >= $gfsArrDecks[0] Then

Return SetError(2, $gfsArrDecks[0], $gfsArrDecks[$gfsCurrentDeckID])

Else

$gfsCurrentDeckID = $deck

EndIf

Else

For $i = 1 to $gfsArrDecks[0]

If $deck == $gfsArrDecks[$i] Then

$gfsCurrentDeckID = $i

ExitLoop

EndIf

Next

If $i > $gfsArrDecks[0] Then

; deck asked for is not in list. Make new call to _fsOpenDecks

Return SetError(2, 0, $gfsArrDecks[$gfsCurrentDeckID])

EndIf

EndIf

Return $gfsArrDecks[$gfsCurrentDeckID]

EndFunc

Func __fsGetCardList(ByRef $arrCards, $deck='')

; Get deck information

If $deck = '' Then $deck = _fsGetCurrentDeck()

If err('_fsGetCurrentDeck():=' & $deck & ', missing call to _fsOpendecks()?') then Return SetError(@error, @extended, 0)

;

; Get cards count and reference information

$arrCards = IniReadSectionNames($deck)

if err('IniReadSectionNames(' & $deck & ') failed. Could not locate any cards in the deck') Then Return SetError(2,0,0)

Return True

EndFunc

Func _fsGetNextCard(ByRef $quizdata, $previousID=-1)

; RETURN 0 if there is no next card or on error.

; ByRef $question: Returns a string with the question.

; ByRef $answers: Returns an array with the answer sugestions.

; ByRef $type: Returns a string with answer type information.

; $previousID: Optional. Provide Id of the previous question. If the deck was opened in

; sequential mode the next card id is delivered.

;

; @error = 1: $previousID > _fsGetLastCardID()

; Next card ddepends upon the deck (application mode) to use.

; It allso depends on the card uised last in that deck.

; Who is responsible for shuffeling decks?

; TODO: Should ther be some kind of history tracking in the cards?

;

; ChangeLog:

; Changed interface from

; (byref $question, byref $answers, byref $type, $previousID)

; To:

; (byref $quizdata, $previousID)

; $quizdata does now contain the an two dimentional array where [n][0] = keyname and

; [n][1] is the data. [0][0] contains the last index in the array.

Local $cardID=0, $cardList

Local $deck = _fsGetCurrentDeck()

;

If err('__fsGetCardList(...)' & __fsGetCardList($cardList)) Then return SetError(@error, @extended, 0)

Local $cardID

Switch $gfsDeckMode

case 0

;Check if we have a valide previousID

; $previousID <> -1 The caller has determined witch card to get.

If $previousID < -1 OR $previousID > $cardList[0]-1 Then Return SetError(4,0,0)

$cardID = _fsGetNextCardID($gfsDeckMode, $previousID)

case 1

assertNoCode()

case 2

assertNoCode()

EndSwitch

If Not _fsGetCardByID($quizdata, $cardID) Then Return SetError(@error, @extended, 0)

;

; Read next card from selected deck

; If err('_fsgetnextcardID(' & $previousID & ') failed.') Then

; assertNoCode()

; Else

; ; Check validity of cardID and read the card if it is valide.

; if $cardID > $cardList[0] then

; ; TODO: error or Next deck or start from begining?

; Return SetExtended(11,0)

; Else

; ; card ok. read it and return the values

; $quizdata = IniReadSection($deck, $cardList[$cardID])

; If err('InireadSection(' & $deck & ', ' & $cardList[$cardID] & ') failed') then

; Return setError(12, 0, 0)

; EndIf

; EndIf

; EndIf

return $cardID

EndFunc

Func _fsGetLastCardID()

; Return last cardID in Current deck

; @error:=1, @exteneded:=0 > Missing deck file? Call _fsopenDecks(...)

Local $deck = _fsGetCurrentDeck()

If not err('call to _fsGetCurrentDeck() failed. No current deck?') Then

Local $sn = IniReadSectionNames($deck)

If err('_fsGetLastCardID: Could not read section names in ' & _fsGetCurrentDeck()) Then

Return SetError(@error, @extended, 0)

EndIf

Else

Return SetError(@error, @extended, 0)

EndIf

Return $sn[0]

EndFunc

Func _fsSetCurrentCardID($cardID)

; External Overide of sequence

$gfsCurrentCardID = $cardID

EndFunc

func _fsGetNextCardID($fsMode=0, $previousID=-1)

; Determine deck based on information provided in _fsOpenDeck$

; Get the next cardID. Thyis could depend on $fsMode indicating

; 0=sequensial read,

; 1=random but not allready read in this session

; 2=Memory access mode (1,+3,+7,+14,+30,+90,+180,+352)

Local $ret=0

If _fsGetCurrentDeck() == '' Then

err('No deck available')

Return SetError(1,0,0)

EndIf

Switch $gfsDeckMode

case 0 ;Sequential read. Read until last card in deck.

;Then Switch to next deck in array. Repet until last card.

If $previousID >= 0 Then

If $previousID <= _fsGetLastCardID() -1 Then

$ret = $previousID + 1

Else

; The caller must shufle or set next deck

; NOTE: Should SetExteneded be done to indicate why return is 0?

assertNoCode('NO CODE Should the caller or I shufle and set next deck?')

$ret = 0

EndIf

ElseIf $gfsCurrentCardID <= _fsGetLastCardID() Then

$gfsCurrentCardID += 1

$ret = $gfsCurrentCardID

Else

; First card in next deck

$gfsCurrentCardID = 1

$gfsCurrentDeckID += 1

If $gfsCurrentDeckID > $gfsArrDecks[0] Then $gfsCurrentDeckID = 1

assertNoCode('NO CODE Sequential read. Read until last card in deck is implemented but what about faulty answers?.')

EndIf

case 1 ; Random but no repetition (of correctly answered card)

assertNoCode('NO CODE Random mode functionality not implemented')

case 2 ; Memory access (strengthening) mode (1,+3,+7,+14,+30,+90,+180,+352)

assertNoCode('NO CODE Memory access/strengthening functionality not implemented')

EndSwitch

Return $ret

EndFunc

Func _fsGetCardByID(ByRef $quizdata, $cardID, $line=@ScriptLineNumber)

;Read card matching

; @error=1, @extended=0 : Missing call to _fsOpenDecks?

; Changed interface from (ByRef $question, ByRef $answer, $cardID)

; to: (ByRef $quizdata, $cardID)

Local $cardList

Local $deck = _fsGetCurrentDeck()

If err(__fsGetCardList($cardList, $deck)) Then return SetError(@error, @extended, 0)

; Makse sure we dont acces out of bounds

If $cardList[0] < $cardID OR $cardID < 1 Then Return SetError(4,0,0)

$quizdata = IniReadSection($deck, $cardList[$cardID])

If err('InireadSection(' & $deck & ', ' & $cardList[$cardID] & ') failed') then Return setError(3, 0, 0)

Return True

EndFunc

Func _fsCheckAnswer($answer, $cardID)

; RETURN: True or false

; Check answer given against $cardID

; The answer is a | delimited list or array.

Local $quizData, $i, $j, $answers

If not IsArray($answer) Then $answers = StringSplit($answer, '|')

If err(_fsGetCardByID($quizData,$cardID)) then Return SetError(@error, @extended, false)

if not IsArray($quizData) Then Return SetError(19,0,false)

For $i = 1 to $quizData[0][0]

If $quizData[$i][0] == 'answer' Then ExitLoop

Next

If $i > $quizData[0][0] then Return SetError(20,0,False)

For $j = 1 to $answers[0]

if not StringInStr($quizdata[$i][1], __fsStringBracketClose($answers[$j])) Then

todo('Add tracking functionality')

Return SetExtended($j,False)

EndIF

Next

Return True

EndFunc

Func __fsStringBracketClose($str)

Local $ret = $str

If Not (StringLeft($str,StringLen('[')) == '[') Then $ret = '[' & $ret

If Not (StringRight($str,StringLen(']')) == ']') Then $ret = $ret & ']'

Return $ret

EndFunc

Func _fsRecordAnswer($bool, $cardID, $fsMode=0, $static=0)

; $bool = true or false determines if the giwen asver was correct.

; TODO: Personal or global tracking of answers?

; Personal Tracking and recording is prefered.

; Application is portableapps compatible as efault

; Application ini could overide this and create tracking IniDelete

; in profile folder.

assertNoCode()

EndFunc

Func test_fsRecordAnswer()

; _fsRecordAnswer($bool, $cardID, $fsMode=0, $static=0)

; $bool = true or false determines if the giwen asver was correct.

; _fsWriteTrackRecord($bool, $cardID, $fsMode=0)

; TODO: Personal or global tracking of answers?

; Personal Tracking and recording is prefered.

; Application is portableapps compatible as efault

; Application ini could overide this and create tracking IniDelete

; in profile folder.

;

; Logging correct or false answers could be done by means of an MRU list

; MRUwrong = 3 6 11

Local $section = @username & '@' & @computername & '::' & _fsGetCurrentDeck()

assertNoCode()

_fsCloseDecks()

EndFunc

If StringLeft(@ScriptName, StringLen(@scriptname)-4) == 'au3FlashCards' Then suite_au3FlashCardstest()

Posted

Hmm I would just update your previous posts instead posting new code for every update, also just put links to .au3 files in the 1st post. Other then that seems like a good idea though

[Cheeky]Comment[/Cheeky]
  • 4 weeks later...
Posted

ASSERT FAILED: NO CODE

Succes:=20, Failures:=1, calls:=21

Can't you just post downloadable AU3 files? Much easier for others.

  • 7 months later...
Posted (edited)

Has anymore progress been made or is this project shelved?, seems the code is incomplete or has got corrupted? I wish to start making a Flash Card application for my workplace and this looked like a good start, is it possible to get me a download link.

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...