Example #1
0
    def testCalculateAnswerRating(self):
        original = 'profitable, moneymaking, remunerative'

        # No match == -POINTS_PER_GUESS
        res = calculateAnswerRating(original, '-')
        self.assertEqual(-POINTS_PER_GUESS, res)
        # One good match == POINTS_PER_GUESS
        res = calculateAnswerRating(original, 'moneymaking, blah')
        self.assertEqual(POINTS_PER_GUESS, res)
        # One partially good match
        res = calculateAnswerRating(original, 'profetabl')
        self.assertTrue(POINTS_PER_GUESS, res)
        # Full match PPGx1 + PPGx2 + PPGx3
        res = calculateAnswerRating(original,\
             'profitable,moneymaking,remunerative')
        self.assertEqual(POINTS_PER_GUESS + 2 * POINTS_PER_GUESS + \
            3 * POINTS_PER_GUESS, res)
        # Full match with errors  80<= res <100
        res = calculateAnswerRating(original, 'profitable,monemeking')
        self.assertTrue(POINTS_PER_GUESS, res)
        # One correct and one wrong
        res = calculateAnswerRating(original, 'monemeking, expensive')
        self.assertTrue(POINTS_PER_GUESS, res)
        res = calculateAnswerRating(u"прокос, ряд, широкий профиль", \
            u"прокос, полоса")
        self.assertEqual(POINTS_PER_GUESS, res)
Example #2
0
def processMessage(message):
    today = datetime.date.today()
    # You can get addressee name by checking current
    # Twitter bot username, but this requires additional API call
    twitter_user = message.sender_screen_name
    # Get User
    user = User.all().filter("twitter =", twitter_user).get()
    # Exit if user is not registred. This is to avoid spam
    if not user:
        return
    parsed_dict = parseMessage(message.text, message.recipient_screen_name)
    # Exit if message is not a valid dict_entry format
    if parsed_dict == {}:
        return
    question = checkForAnswer(parsed_dict, twitter_user)

    # Check if message is an answer to a previously sent question
    if question:
        answer_rating = calculateAnswerRating(question.lli_ref.dict_entry.meaning,\
             parsed_dict["meaning"])
        question.answer_received = today
        question.answer_rating = answer_rating
        question.lli_ref.latest_answer_rating = answer_rating
        question.answer_text = parsed_dict["meaning"]
        question.put()
        question.lli_ref.put()
        if (user.total_points + answer_rating) > 0:
            user.total_points = user.total_points + answer_rating
        else:
            user.total_points = 0
        user.put()
        # If answer_rating is very poor, we need to show correct answer right away
        # else reschedule as normal accorsing to answer_rating
        if answer_rating < 0:
            question.lli_ref.next_serve_time = 0
            question.lli_ref.next_serve_date = today
            question.put()
            question.lli_ref.put()
        else:
            rescheduleLearnListItem(question.lli_ref, answer_rating)
        return
    # If message is a valid dictionary entry -- save it to database
    addNewWord(parsed_dict, user, message.id)
    user.put()