예제 #1
0
def next_high_score(user):
    global db
    try:
        score = database.get_score(user)
        c=database.open_db()
        command = "SELECT user,pts FROM accounts WHERE pts>? ORDER BY pts ASC"
        c.execute(command, (score,))
        data = c.fetchone()
        database.close_db()
    except:
        print "Error: could the next higher score"
        return None
    return data
예제 #2
0
파일: score.py 프로젝트: HKCodeCamp/vocably
def choose_words(email, nwords_to_send = 10):
    """
    Choose nwords_to_send words for user to learn. If less words are available
    only the available words will be sent.
    Words chosen will be assumed to be learned by user and are added to the
    user vocabulary in the db. User score in db is updated.
    """
    # query database for known words of user
    userwords = database.get_list(email)

    # create complete dict and remove known words
    unknown_words = reference_wordlist.copy()
    for w in userwords:
        unknown_words.pop(w,0)
 
    # convert unknown words dict to sorted list
    unknown_words = sorted(unknown_words,
            key=lambda x: unknown_words.get(x).freq, reverse=True)

    # at best we can send all the unknown words
    nwords_to_send = min(nwords_to_send, len(unknown_words))

    # query database for user score
    userscore = database.get_score(email)

    def add_word():
        target = int(percentile() * userscore * len(unknown_words))
        candidate = int(target * (1 + random.random() * (1 - percentile())))
        candidate = min(candidate, len(unknown_words) - 1)
        return unknown_words.pop(candidate)

    wordlist = [add_word() for i in range(nwords_to_send)]
  
    # new score and add words to db
    database.store_user_words(email, wordlist)
    newscore = score(wordlist + userwords)
    database.set_score(email, newscore)

    return wordlist
예제 #3
0
def choose_words(email, nwords_to_send=10):
    """
    Choose nwords_to_send words for user to learn. If less words are available
    only the available words will be sent.
    Words chosen will be assumed to be learned by user and are added to the
    user vocabulary in the db. User score in db is updated.
    """
    # query database for known words of user
    userwords = database.get_list(email)

    # create complete dict and remove known words
    unknown_words = reference_wordlist.copy()
    for w in userwords:
        unknown_words.pop(w, 0)

    # convert unknown words dict to sorted list
    unknown_words = sorted(unknown_words,
                           key=lambda x: unknown_words.get(x).freq,
                           reverse=True)

    # at best we can send all the unknown words
    nwords_to_send = min(nwords_to_send, len(unknown_words))

    # query database for user score
    userscore = database.get_score(email)

    def add_word():
        target = int(percentile() * userscore * len(unknown_words))
        candidate = int(target * (1 + random.random() * (1 - percentile())))
        candidate = min(candidate, len(unknown_words) - 1)
        return unknown_words.pop(candidate)

    wordlist = [add_word() for i in range(nwords_to_send)]

    database.store_user_words(email, wordlist)
    newscore = score(wordlist + userwords)
    database.set_score(email, newscore)

    return wordlist
예제 #4
0
파일: score.py 프로젝트: Liongrass/vocably
def choose_words(userid, nwords_to_send = 10):
    """
    Choose words for user to learn. 
    """
    # query database for known words of user
    userwords = database.get_list(userid)

    # query database for user score
    userscore = database.get_score(userid)

    target = int(percentile() * userscore * words_in_language())
    
    # add a word not yet known to user to wordlist (ugly solution)
    def add_word(target,wordlist):
        tries = 0
        while tries < 1000:
            candidate = int(target * (1.0 + random.random() \
                * (1 - percentile())))
            tries += 1
            if candidate > words_in_language() + 1: 
                continue
            word = sorted_reference_wordlist[candidate] 
            if word not in wordlist:         
                return wordlist + [word]
        
        # can't find unknown words, returning whatever I have
        return wordlist + [word]

    wordlist = []
    
    for i in range(nwords_to_send):
        wordlist = add_word(target,wordlist)
   
    database.store_user_words(userid, wordlist)
    newscore = score(wordlist + userwords)
    database.set_score(newscore)

    return wordlist
예제 #5
0
        if variant == p2:
            return True
    return False

if __name__ == "__main__":

    db.init_db()
    games = {}

    if ARGS.g:
        games[ARGS.g] = ARGS.c
    else:
        games = load_csv()

    for src_game, src_platform in games.iteritems():
        if not db.get_score(src_game):
            resp = json.loads(send_request(src_game))

            found = False
            score = None

            if resp:
                for res in resp:
                    if not res['score']:
                        print "No score ", res['title']
                        continue
                    else:
                        for res_platform in res['platforms'].itervalues():
                            if platform_equal(res_platform, src_platform):
                                score = res['score']
                                found = True
예제 #6
0
파일: score.py 프로젝트: vhew/vocably
def get_score(email):
    return int(database.get_score(email) * words_in_language() )
예제 #7
0
def get_score(email):
    return int(database.get_score(email) * words_in_language())