def getCognitiveTestsAndFilterByParameters(self, testType, testSubType,
                                            userLanguage, chosenDif, trace):
     cognitiveTestsOfTypeResponse = CognitiveExerciseHelperFunctions.getCognitiveTestsOfType(
         testType, userLanguage)
     testsOfTypeOrdered = self.filterTestsbyDifficultyAndSubtype(
         cognitiveTestsOfTypeResponse, chosenDif, testSubType, trace)
     return testsOfTypeOrdered
 def returnTestsFunction(self,req):
   try:      
     res = returnTestsOfTypeSubtypeDifficultySrvResponse()
     if(req.testType==""):
       error="Error, empty testType field"
       raise AppError(error, error)
     supportedLanguages=CognitiveExerciseHelperFunctions.getTestLanguagesFromOntology()      
     keepEntries = dict()
     testCount=0      
     for currentLanguage in supportedLanguages:
       cognitiveTestsOfTypeResponse=CognitiveExerciseHelperFunctions.getCognitiveTestsOfType(req.testType,currentLanguage)        
       tests=CognitiveExerciseHelperFunctions.filterTestsbyDifficultyAndSubtype(cognitiveTestsOfTypeResponse,req.difficulty,req.testSubType)       
       if(req.language=="" or currentLanguage==req.language):
         for k, v in tests.items():
           if(not k in keepEntries):
             currentCognitiveTest =  CognitiveExercisesMsg()
             currentCognitiveTest.testName=k.split('#')[1]
             currentCognitiveTest.testType=req.testType
             currentCognitiveTest.testSubType=(v[0][2]).split('#')[1]
             currentCognitiveTest.testSubType=(v[0][2]).split('#')[1]
             currentCognitiveTest.difficulty=(v[0][1])
             currentCognitiveTest.test_id=(v[0][3])
             currentCognitiveTest.languages.append(currentLanguage)              
             res.cognitiveExercises.append(currentCognitiveTest)
             keepEntries[k]=testCount
             testCount=testCount+1
           else:
             res.cognitiveExercises[keepEntries[k]].languages.append(currentLanguage)
     res.totalNumberOfTestsReturned=testCount
     res.success=True
   except IndexError, e:
     res.trace.append("IndexError: " +str(e))
     res.error="IndexError: "+str(e)
     res.success=False
     CognitiveExerciseHelperFunctions.traceError(res.error,res.trace)
 def selectTestManuallyByGivenParameters(self,testType,testSubtype,testIndex,testDifficulty,userLanguage, res):
   if(not testType=="" and not testDifficulty=="" and not testIndex=="" and not testSubtype==""):
     testIndex=str(int(testIndex)-1)
     tests=CognitiveExerciseHelperFunctions.getCognitiveTestsOfType(testType,userLanguage) 
     tests=CognitiveExerciseHelperFunctions.filterTestsbyDifficultyAndSubtype(tests,testDifficulty,testSubtype)
     filepath=""
     for k, v in tests.items():
       if(testIndex==(v[0][3])):
         filepath=(v[0][0])      
     if(filepath==""):
       error="No such test exists, or not available in user's language"
       raise AppError(error,error) 
     self.retrieveDataFromTestXml(filepath,userLanguage,res)  
   else:
     error="Error, manual test detection detected as testIndex or testDifficulty was defined. One or more of testType, testSubtype, testIndex, testDifficulty were not defined, cannot proceed"
     raise AppError(error,error) 
Exemple #4
0
 def returnTestsFunction(self, req):
     try:
         res = returnTestsOfTypeSubtypeDifficultySrvResponse()
         if (req.testType == ""):
             error = "Error, empty testType field"
             raise AppError(error, error)
         supportedLanguages = CognitiveExerciseHelperFunctions.getTestLanguagesFromOntology(
         )
         keepEntries = dict()
         testCount = 0
         for currentLanguage in supportedLanguages:
             cognitiveTestsOfTypeResponse = CognitiveExerciseHelperFunctions.getCognitiveTestsOfType(
                 req.testType, currentLanguage)
             tests = CognitiveExerciseHelperFunctions.filterTestsbyDifficultyAndSubtype(
                 cognitiveTestsOfTypeResponse, req.difficulty,
                 req.testSubType)
             if (req.language == "" or currentLanguage == req.language):
                 for k, v in tests.items():
                     if (not k in keepEntries):
                         currentCognitiveTest = CognitiveExercisesMsg()
                         currentCognitiveTest.testName = k.split('#')[1]
                         currentCognitiveTest.testType = req.testType
                         currentCognitiveTest.testSubType = (
                             v[0][2]).split('#')[1]
                         currentCognitiveTest.testSubType = (
                             v[0][2]).split('#')[1]
                         currentCognitiveTest.difficulty = (v[0][1])
                         currentCognitiveTest.test_id = (v[0][3])
                         currentCognitiveTest.languages.append(
                             currentLanguage)
                         res.cognitiveExercises.append(currentCognitiveTest)
                         keepEntries[k] = testCount
                         testCount = testCount + 1
                     else:
                         res.cognitiveExercises[keepEntries[
                             k]].languages.append(currentLanguage)
         res.totalNumberOfTestsReturned = testCount
         res.success = True
     except IndexError, e:
         res.trace.append("IndexError: " + str(e))
         res.error = "IndexError: " + str(e)
         res.success = False
         CognitiveExerciseHelperFunctions.traceError(res.error, res.trace)
 def selectTestManuallyByGivenParameters(self, testType, testSubtype,
                                         testIndex, testDifficulty,
                                         userLanguage, res):
     if (not testType == "" and not testDifficulty == ""
             and not testIndex == "" and not testSubtype == ""):
         testIndex = str(int(testIndex) - 1)
         tests = CognitiveExerciseHelperFunctions.getCognitiveTestsOfType(
             testType, userLanguage)
         tests = CognitiveExerciseHelperFunctions.filterTestsbyDifficultyAndSubtype(
             tests, testDifficulty, testSubtype)
         filepath = ""
         for k, v in tests.items():
             if (testIndex == (v[0][3])):
                 filepath = (v[0][0])
         if (filepath == ""):
             error = "No such test exists, or not available in user's language"
             raise AppError(error, error)
         self.retrieveDataFromTestXml(filepath, userLanguage, res)
     else:
         error = "Error, manual test detection detected as testIndex or testDifficulty was defined. One or more of testType, testSubtype, testIndex, testDifficulty were not defined, cannot proceed"
         raise AppError(error, error)
 def getCognitiveTestsAndFilterByParameters(self,testType,testSubType,userLanguage,chosenDif,trace):
   cognitiveTestsOfTypeResponse=CognitiveExerciseHelperFunctions.getCognitiveTestsOfType(testType,userLanguage)
   testsOfTypeOrdered=self.filterTestsbyDifficultyAndSubtype(cognitiveTestsOfTypeResponse,chosenDif,testSubType,trace)    
   return testsOfTypeOrdered