Пример #1
0
def run_test(spellBee):
    _FUNC_NAME_ = "run_test"

    spellBee.display_about()
    display_help("test")
    userInput = cinput.get_keypress("\nReady for the test? Press any key when ready ... ")

    testDate = time.strftime('%a %d-%b-%Y %H:%M:%S')
    testTotalCount = spellBee.active_word_count()
    testCorrectCount = 0

    userResponse = SB_EMPTY_STRING
    testValuation = SB_EMPTY_STRING

    spellBee.reset_test_result()

    
    # Disable saving practice words if :
    # saving is disabled for test results, or
    # the test is based on practice, revision or wild card lists
    savePracticeWordsEnabled = SB_TEST_SAVE_PRACTICE
    if SB_TEST_SAVE_RESULT == False or 'practice' in spellBee.contestList.lower() or 'revision' in spellBee.contestList.lower() or '*' in spellBee.contestList:
        savePracticeWordsEnabled = False
    coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "SB_TEST_SAVE_PRACTICE :: {0}".format(SB_TEST_SAVE_PRACTICE))
    coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "savePracticeWordsEnabled :: {0}".format(savePracticeWordsEnabled))

    activeWordIndex = 0

    while True:
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "activeWordIndexList :: {0}".format(spellBee.activeWordIndexList))
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "activeWordIndex :: {0}".format(activeWordIndex))
        if (activeWordIndex < 0) or (activeWordIndex >= len(spellBee.activeWordIndexList)):
            break

        wordIndex = spellBee.activeWordIndexList[activeWordIndex]
        coutput.print_debug(SB_ERR_DEBUG, _FUNC_NAME_, "wordIndex :: {0}".format(wordIndex))

        # Lookup word definition
        spellBee.lookup_dictionary_by_index(wordIndex)
        spellBee.display_word_cue(SB_PRACTICE_WORD_DEFN_TITLE.format(INDEX=wordIndex + 1))
        userResponse = cinput.get_input("Enter spelling: ")

        # E[x]it test
        if userResponse.lower() == "x":
            break

        # [R]epeat question
        elif userResponse.lower() == "r":
            continue

        # Display [h]elp and statistics
        elif userResponse.lower() == "h":
            print SB_EMPTY_STRING
            spellBee.display_about()
            display_help("test")
            continue

        else:
            correctResponse = False

            # Process correct response
            if spellBee.valuate_test_response(userResponse, spellBee.activeWord, SB_TEST_MODE):
                correctResponse = True
                testValuation = SB_RIGHT_SYMBOL + " " + userResponse
                testCorrectCount += 1
            # Process incorrect response
            else:
                testValuation = SB_WRONG_SYMBOL + " " + userResponse
                spellBee.log_practice_word(spellBee.activeWord)

            # Indicate correct form of the answer, if different from the response
            if userResponse != spellBee.activeWord:
                testValuation = testValuation + " (" + spellBee.activeWord + ")"

            # Display valuation
            # Handle display text in ascii
            asciiTestValuation = testValuation.encode('utf-8')
            if correctResponse:
                coutput.print_color('green', " " * 50 + asciiTestValuation)
            else:
                coutput.print_color('red', " " * 50 + asciiTestValuation)
            
            # Save valuation
            spellBee.log_test_valuation(testValuation)

            # Move to next word
            activeWordIndex += 1
    
    spellBee.log_test_result(testDate, str(testCorrectCount) + "/" + str(testTotalCount))
    print "\nYour test is complete. Displaying results..."
    
    spellBee.display_evaluation_result('test', SB_TEST_SAVE_RESULT, savePracticeWordsEnabled)
Пример #2
0
def run_practice(spellBee, practiceMode):

    userPracticeMode = practiceMode.strip().lower()

    if userPracticeMode == "study":
        spellBee.print_active_word_list()
    else:
        spellBee.display_about()
    display_help(userPracticeMode)
    userInput = cinput.get_keypress("\nReady to {0}? Press any key when ready ... ".format(userPracticeMode))

    activeWordIndex = 0

    while True:
        if (activeWordIndex < 0) or (activeWordIndex >= len(spellBee.activeWordIndexList)):
            break

        wordIndex = spellBee.activeWordIndexList[activeWordIndex]

        # Lookup word definition
        spellBee.lookup_dictionary_by_index(wordIndex)
        if userPracticeMode == "study":
            spellBee.display_word_cue(SB_STUDY_WORD_DEFN_TITLE.format(INDEX=wordIndex + 1, WORD=spellBee.wordList[wordIndex]))
        else:
            spellBee.display_word_cue(SB_PRACTICE_WORD_DEFN_TITLE.format(INDEX=wordIndex + 1))
        userInput = cinput.get_keypress(SB_PROMPT_SYMBOL)
        
        while True:
            # Move to [n]ext word
            if userInput.lower() == "n":
                activeWordIndex += 1
                break
            # Move to [p]revious word
            elif userInput.lower() == "p":
                activeWordIndex -= 1
                break
            # [R]epeat current word
            elif userInput.lower() == "r":
                if userPracticeMode == "study":
                    spellBee.display_word_cue(SB_STUDY_WORD_DEFN_TITLE.format(INDEX=wordIndex + 1, WORD=spellBee.wordList[wordIndex]))
                else:
                    spellBee.display_word_cue(SB_PRACTICE_WORD_DEFN_TITLE.format(INDEX=wordIndex + 1))
                userInput = cinput.get_keypress(SB_PROMPT_SYMBOL)
            # Re[v]iew active word list
            elif userInput.lower() == "v":
                print SB_EMPTY_STRING
                spellBee.print_active_word_list()
                userInput = cinput.get_keypress(SB_PROMPT_SYMBOL)
            # [S]how current word spelling
            elif userInput.lower() == "s":
                spellBee.display_word_cue(SB_STUDY_WORD_DEFN_TITLE.format(INDEX=wordIndex + 1, WORD=spellBee.wordList[wordIndex]))
                userInput = cinput.get_keypress(SB_PROMPT_SYMBOL)
            # [L]ookup word definition and pronunciation
            elif userInput.lower() == "l":
                userLookupWord = cinput.get_input("\nEnter word to be looked up: ")
                spellBee.lookup_all_dictionaries_by_word(userLookupWord)
                userInput = cinput.get_keypress(SB_PROMPT_SYMBOL)
            # Display [h]elp and statistics
            elif userInput.lower() == "h":
                print SB_EMPTY_STRING
                spellBee.display_about()
                display_help(userPracticeMode)
                userInput = cinput.get_keypress(SB_PROMPT_SYMBOL)
            # E[x]it application
            elif userInput.lower() == "x":
                exit_app()
            else:
                print "\nInvalid response."
                display_help(userPracticeMode)
                userInput = cinput.get_keypress(SB_PROMPT_SYMBOL)