def testUsers():
    users = getTenNewestUsers()
    # Not quite as dumb as it looks
    times = [[]] * len(users)
    totaldebug = [""] * len(users)
    for trial in range(10):
        for tupIndex in range(len(users)):
            (uid, placementID) = users[tupIndex]
            placementID += 1
            if placementID >= len(raw):
                # Right, but, like, are you sure?
                cnx = db.dbConnect("linkgame")
                cur = cnx.cursor()
                cur.execute("SELECT placementID FROM tournament WHERE uid=%s", [uid])
                placements_ = cur.fetchall()
                cnx.close()
                placements = []
                for (placement,) in placements_:
                    placements.append(placement)
                for i in range(len(raw)):
                    if not (i in placements):
                        placementID = i
                        users[tupIndex] = (uid, i - 1)
                if placementID >= len(raw):
                    # We've tested all the solutons for this user
                    continue

            if placementID == len(raw) - 1:
                # Ahahahahaha have fun
                (answer, debug, timeTaken) = runTest(uid, raw[placementID][:3], True)
            else:
                # 3 tiles * 3 chars/tile = 9 chars (~ 1s)
                (answer, debug, timeTaken) = runTest(uid, raw[placementID][:9], True)
            # An incorrect answer incurs a 10s penalty.
            # This is included in the mean calculation
            if len(answer) != 1 or answer[0] != raw[placementID]:
                timeTaken += 10000
                print "[debug] Answer incorrect or not given", uid, placementID, timeTaken
            else:
                print "[debug] Answer correct", uid, placementID, timeTaken
            # I have to do it this was because Python's lists are pass-by-reference
            # Seriously, both 'times[tupIndex].append(...)' and 'times[tupIndex] += [...]' fail!!
            times[tupIndex] = times[tupIndex] + [timeTaken]
            totaldebug[tupIndex] += debug
            totaldebug += ("\n" + ("-"*20) + "\n")

    ret = []
    for i in range(len(users)):
        if times[i] == []:
            ret.append((users[i][0], users[i][1] + 1, None, "No data."))
        else:
            ret.append((users[i][0], users[i][1] + 1, int(sum(times[i])/len(times[i])), totaldebug[i]))

    return ret; 
예제 #2
0
    def POST(self):
        '''Executes a python client API call identified by its generic name'''

        # Get the call name from the HTTP header
        call_name = web.input().call_name

        # Load the local ontology into the SMART client
        smart_client = get_smart_client(ONTOLOGY)

        # Figure out the SMART model corresponding to the API call
        model = get_model(call_name)

        # Get a reference to the conveninence method in the SMART client and execute the call
        method_to_call = getattr(smart_client, call_name)
        r = method_to_call()

        # Run the API tests on the result of the call
        messages = getMessages(runTest(model, r.body, r.contentType))

        # Encode and return the call and tests result as JSON
        return json.dumps(
            {
                'body': r.body,
                'contentType': r.contentType,
                'messages': messages
            },
            sort_keys=True,
            indent=4)
예제 #3
0
    def POST(self):
        '''Executes the appropriate series of tests for a given data model'''

        # Get the input data from the HTTP header
        model = web.input().model
        data = web.input().data
        contentType = web.input().content_type

        # Run the tests and obtain the failure messages
        messages = getMessages(runTest(model, data, contentType))

        # Return the failure messages encoded as JSON
        return json.dumps(messages, sort_keys=True, indent=4)
예제 #4
0
    def POST(self):
        '''Executes the appropriate series of tests for a given data model'''

        # Get the input data from the HTTP header
        model = web.input().model
        data = web.input().data
        contentType = web.input().content_type

        # Run the tests and obtain the failure messages
        messages = getMessages(runTest(model, data, contentType))

        # Return the failure messages encoded as JSON
        return json.dumps(messages, sort_keys=True, indent=4)
예제 #5
0
    def POST(self):
        '''Executes a python client API call identified by its generic name'''
        global _smart

        # make sure the SMARTClient is init'd
        cookies = web.cookies()
        api_base = cookies.api_base
        record_id = cookies.record_id

        # reconstruct acc_token from cookies
        acc_token = {
            'oauth_token_secret': cookies.oauth_token_secret,
            'oauth_token': cookies.oauth_token,
            'record_id': record_id,
            'user_id': cookies.user_id
        }

        logging.debug('Cookies are: api_base: ' + api_base + ' record_id: ' +
                      record_id + ' acc_token: ' + str(acc_token))

        smart = _smart_client(api_base, record_id)
        if smart is None:
            return False

        smart.update_token(acc_token)

        call_name = web.input().call_name

        # Figure out the SMART model corresponding to the API call
        model = get_model(call_name)

        logging.debug('Calling ' + call_name)
        method_to_call = getattr(SMARTClient, call_name)
        r = method_to_call(_smart)

        # Run the API tests on the result of the call
        contentType = r.response.get('content-type', None)
        messages = getMessages(runTest(model, r.body, contentType))

        # Encode and return the call and tests result as JSON
        return json.dumps(
            {
                'body': r.body,
                'contentType': contentType,
                'messages': messages
            },
            sort_keys=True,
            indent=4)
예제 #6
0
    def POST(self):
        '''Executes a python client API call identified by its generic name'''
        global _smart

        # make sure the SMARTClient is init'd
        cookies = web.cookies()
        api_base = cookies.api_base
        record_id = cookies.record_id

        # reconstruct acc_token from cookies
        acc_token = {
            'oauth_token_secret': cookies.oauth_token_secret,
            'oauth_token': cookies.oauth_token,
            'record_id': record_id,
            'user_id': cookies.user_id
        }

        logging.debug('Cookies are: api_base: ' + api_base +
                ' record_id: ' + record_id +
                ' acc_token: ' + str(acc_token))

        smart = _smart_client(api_base, record_id)
        if smart is None:
            return False

        smart.update_token(acc_token)

        call_name = web.input().call_name

        # Figure out the SMART model corresponding to the API call
        model = get_model(call_name)

        logging.debug('Calling ' + call_name)
        method_to_call = getattr(SMARTClient, call_name)
        r = method_to_call(_smart)

        # Run the API tests on the result of the call
        contentType = r.response.get('content-type', None)
        messages = getMessages(runTest(model, r.body, contentType))

        # Encode and return the call and tests result as JSON
        return json.dumps({
            'body': r.body,
            'contentType': contentType,
            'messages': messages
        }, sort_keys=True, indent=4)
예제 #7
0
 def POST(self):
     '''Executes a python client API call identified by its generic name'''
     
     # Get the call name from the HTTP header
     call_name = web.input().call_name
     
     # Load the local ontology into the SMART client
     smart_client = get_smart_client(ONTOLOGY)
     
     # Figure out the SMART model corresponding to the API call
     model = get_model(call_name)
     
     # Get a reference to the conveninence method in the SMART client and execute the call
     method_to_call = getattr(smart_client, call_name)
     r = method_to_call()
     
     # Run the API tests on the result of the call
     messages = getMessages(runTest(model,r.body,r.contentType))
     
     # Encode and return the call and tests result as JSON
     return json.dumps({'body':r.body, 'contentType':r.contentType, 'messages':messages}, sort_keys=True, indent=4)