Esempio n. 1
0
    def runDebug(self,
                 page,
                 pageNum=1,
                 cookieTracker=True,
                 userName="******"):

        testSequence = sequence.TestSequence(self, self.sequenceFN)
        self.buildPage(pageNum, cookieTracker, page, userName, testSequence,
                       self.sourceCGIFN)
Esempio n. 2
0
    def _testSequenceOverride(self, userName):
        '''
        Override the test sequence
        
        This is done only when we're using individual sequences
        '''

        if self.individualSequences is True:
            if userName != "" and self.sequenceFN != userName + ".txt":
                testSequence = sequence.TestSequence(self, self.sequenceFN,
                                                     userName)
                self.testSequence = testSequence
Esempio n. 3
0
    def __init__(self,
                 surveyName,
                 sequenceFN,
                 languageFileFN,
                 disableRefreshFlag,
                 sourceCGIFN=None,
                 audioExtList=None,
                 videoExtList=None,
                 allowUsersToRelogin=False,
                 individualSequences=False):

        self.htmlDir = constants.htmlDir
        self.htmlSnippetsDir = constants.htmlSnippetsDir

        self.surveyRoot = join(constants.rootDir, "tests", surveyName)
        self.wavDir = join(self.surveyRoot, "audio_and_video")
        self.txtDir = join(self.surveyRoot, "txt")
        self.imgDir = join(self.surveyRoot, "imgs")
        self.outputDir = join(self.surveyRoot, "output")
        self.allowUsersToRelogin = allowUsersToRelogin
        self.individualSequences = individualSequences

        self.surveyName = surveyName
        self.sequenceFN = join(self.surveyRoot, sequenceFN)
        self.testSequence = sequence.TestSequence(self, self.sequenceFN)

        if languageFileFN is not None:
            languageFileFN = join(self.surveyRoot, languageFileFN)
        self.languageFileFN = languageFileFN

        if audioExtList is None:
            audioExtList = [".ogg", ".mp3"]
        self.audioExtList = audioExtList

        if videoExtList is None:
            videoExtList = [".ogg", ".mp4"]
        self.videoExtList = videoExtList

        if self.languageFileFN is None:
            self.langDict = loader.EmptyDict()
        else:
            self.langDict = loader.TextDict(self.languageFileFN)

        self.disableRefreshFlag = disableRefreshFlag

        self.textDict = self.langDict.batchGetText(TXT_KEY_LIST)

        # The sourceCGIFN is the CGI file that was requested from the server
        # (basically the cgi file that started the websurvey)
        self.sourceCGIFN = None
        if sourceCGIFN is None:
            self.sourceCGIFN = os.path.split(__main__.__file__)[1]
Esempio n. 4
0
def checkSequenceFile(survey):
    
    outputDir = join(survey.outputDir, survey.testSequence.sequenceTitle)
    
    if not os.path.exists(outputDir):
        print("FYI: Output folder does not exist: '%s'" % outputDir)
    
    try:
        if len(utils.findFiles(outputDir, filterExt=".csv")) > 0:
            print("FYI: User data already exists in output folder")
    except OSError:
        pass
    
    seq = sequence.TestSequence(survey, survey.sequenceFN)
    numErrors = 0
    for pageNum in range(seq.getNumPages()):
    
        try:
            page = seq.getPage(pageNum)
        except TypeError:
            print("Page %d: Problem with the number of arguments" % pageNum)
            continue
        except (utils.FilesDoNotExist,
                loader.TextNotInDictionaryException) as e:
            print("Page %d: %s\n" % (pageNum, str(e)))
            numErrors += 1
            continue
        
        try:
            page = page.getHTML()
        except BaseException as e:
            errStr = ("Page %d: Problem with at least one of the arguments: "
                      "'%s'\n%s:%s\n")
            print(errStr % (pageNum, str(seq.testItemList[pageNum]), e.__class__.__name__, str(e)))
            numErrors += 1
            continue
    
    if numErrors == 0:
        print("No errors found in sequence file.")
Esempio n. 5
0
def postProcessResults(testName, sequenceFN, removeDuplicatesFlag,
                       removeItemList=None):
    
    rootPath = join(constants.rootDir, "tests", testName)
    txtPath = join(rootPath, "txt")
    tmpSequence = sequence.TestSequence(None, join(rootPath, sequenceFN))
    fullPath = join(rootPath, "output", tmpSequence.sequenceTitle)
    pathToData = fullPath
    
    if removeDuplicatesFlag is True:
        removeDuplicates(pathToData, True)
        pathToData = join(pathToData, "duplicates_removed")
    else:
        newPathToData = join(pathToData, "duplicates_not_removed")
        utils.makeDir(newPathToData)
        for fn in utils.findFiles(pathToData, filterExt=".csv"):
            shutil.copy(join(pathToData, fn), join(newPathToData, fn))
        pathToData = newPathToData
    
    outputPath = pathToData + "_results"
    
    userResponseList = []
    fnList = utils.findFiles(pathToData, filterExt=".csv")
    for fn in fnList:
        fullPath = join(pathToData, fn)
        userResponseList.append(user_response.loadUserResponse(fullPath))
    
    # Don't continue if files are of different lengths
    testLen = len(userResponseList[0])
    if not all([len(response) == testLen for response in userResponseList]):
        print("ERROR: Not all responses in folder %s are the same length"
              % pathToData)
        countDict = {}
        for fn, response in utils.safeZip([fnList, userResponseList], True):
            countDict.setdefault(len(response), [])
            countDict[len(response)].append(fn)
            
        keyList = list(countDict.keys())
        keyList.sort()
        for numLines in keyList:
            print("%d lines - %s" % (numLines, str(countDict[numLines])))
        exit(0)
    
    # Don't continue if pages are different
    pageNameList = [[(pageTuple[0], pageTuple[1]) for pageTuple in response]
                    for response in userResponseList]
    sameList = []
    fnListOfLists = []
    for fn, pageList in utils.safeZip([fnList, pageNameList], True):
        i = 0
        while True:
            if len(sameList) == i:
                sameList.append(pageList)
                fnListOfLists.append([])
            else:
                if sameList[i] == pageList:
                    fnListOfLists[i].append(fn)
                    break
                else:
                    i += 1
    
    if len(sameList) == 0:
        print("ERROR: There don't appear to be any test data in folder %s"
              % pathToData)
        exit(0)
        
    if len(sameList) != 1:
        print("ERROR: User data doesn't agree.  Filenames printed on "
              "different lines differ in their pages.")
        
        for subFNList in fnListOfLists:
            print(", ".join(subFNList))
            
    # Extract the different tests users completed
    uniquePageList = []
    for pageTuple in pageNameList[0]:
        pageName = pageTuple[0]
        if pageName not in uniquePageList:
            uniquePageList.append(pageName)
    
    extractFromTest(pathToData, uniquePageList, removeItemList)
    
    # Transpose the surveys
    if "survey" in uniquePageList:
        surveyNameList = []
        for pageName, stimuliArgList in pageNameList[0]:
            if pageName == "survey":
                surveyName = stimuliArgList[0]
                surveyNameList.append(join(rootPath, surveyName + '.txt'))
        
        transpose_survey.transposeSurvey(join(pathToData, "survey"),
                                         surveyNameList, outputPath)
     
    # Transpose the rpt pages
    prominencePageList = ["prominence", "boundary", "boundary_and_prominence",
                          "syllable_marking"]
    for pageName in prominencePageList:
        if pageName in uniquePageList:
            transpose_rpt.transposeRPT(join(pathToData, pageName),
                                       txtPath, pageName, outputPath)
            
    choicePageList = ["media_choice", ]
    for pageName in choicePageList:
        if pageName in uniquePageList:
            transpose_choice.transposeChoice(join(pathToData, pageName),
                                             pageName,
                                             outputPath)
'''
Created on Apr 29, 2016

@author: Tim
'''

from os.path import join

import base_demo
from lmeds.user_scripts import get_test_duration
from lmeds.lmeds_io import sequence
from lmeds.utilities import constants

survey = base_demo.survey

rootPath = join(constants.rootDir, "tests", "lmeds_demo")
tmpSequence = sequence.TestSequence(None, join(rootPath, "sequence.txt"))
fullPath = join(rootPath, "output", tmpSequence.sequenceTitle)
get_test_duration.printTestDuration(fullPath)
Esempio n. 7
0
    
    timeDeviationList = [(time - meanTime) ** 2 for time in allTime]
    stDev = math.sqrt(sum(timeDeviationList) / len(allTime))
    print("Standard Deviation: %f" % stDev)
    
if __name__ == "__main__":
    
    description = "Prints how long each user spent on an experiment"
    parser = argparse.ArgumentParser(description=description)
    
    parser.add_argument('root_folder', action='store',
                        help=("The name of the root folder that stores the "
                              "test files"))
    parser.add_argument('sequence_fn', action='store',
                        help=("The sequence .txt file"))
    
    try:
        cmdArgs = user_script_helper.runScriptLogic(parser)
    except user_script_helper.InteractiveModeException:
        _root_folder = raw_input("Enter the name of your experiment "
                                 "(the root folder in /tests/):\n")
        _sequence_fn = raw_input("Enter the name of your sequence file:\n")
    else:
        _root_folder = cmdArgs.root_folder
        _sequence_fn = cmdArgs.sequence_fn
    
    rootPath = join(constants.rootDir, "tests", _root_folder)
    tmpSequence = sequence.TestSequence(None, join(rootPath, _sequence_fn))
    fullPath = join(rootPath, "output", tmpSequence.sequenceTitle)
    printTestDuration(fullPath)