Example #1
0
    def get(self):
        pigeon_id = self.request.get('pigeon_id')
        house_id = self.request.get('house_id')

        # get all cards for generation of feed
        list_of_all_cards = ops.get_single_house_2(house_id)

        # each pigeon has a special familiar factor to each card, initial is 0
        list_of_familiar_factor = []
        # get it one by one
        for card in list_of_all_cards:
            # iterate the key (although it has only one)
            for card_key in card:
                # append the familiar factor to the list
                list_of_familiar_factor.append(
                    ops.get_familiar_factor(pigeon_id, house_id, card_key))

        # set the threshhold to 50.0, maybe change later
        count = 0
        for i in range(len(list_of_familiar_factor)):
            if list_of_familiar_factor[i] < 50.0:
                count = count + 1

        if count != 0:
            is_finished = False
        else:
            is_finished = True

        return_info = {'is_finished': is_finished}

        self.response.content_type = 'text/html'
        self.response.write(json.dumps(return_info))
Example #2
0
 def get(self):
     house_id = self.request.get('house_id')
     list_of_all_cards = ops.get_single_house_2(house_id)
     size_of_house = len(list_of_all_cards)
     return_info = {'size_of_house': size_of_house}
     self.response.content_type = 'text/html'
     self.response.write(json.dumps(return_info))
Example #3
0
    def get(self):
        pigeon_id = self.request.get('pigeon_id')
        house_id = self.request.get('house_id')

        # get all cards for generation of feed
        list_of_all_cards = ops.get_single_house_2(house_id)

        # each pigeon has a special familiar factor to each card, initial is 0
        list_of_familiar_factor = []
        # number of times (factor) the pigeon has learned this card
        list_of_learn_factor = []
        # get it one by one
        for card in list_of_all_cards:
            # iterate the key (although it has only one)
            for card_key in card:
                # append the familiar factor to the list
                list_of_familiar_factor.append(
                    ops.get_familiar_factor(pigeon_id, house_id, card_key))
                list_of_learn_factor.append(
                    ops.get_learn_factor(pigeon_id, house_id, card_key))

        number_of_key_per_day = ops.get_num_per_day(pigeon_id, house_id)

        # find out how many unlearn words (familiar_factor == 0)
        unlearn_count = 0
        # find out how many unfamiliar words (0 < familiar_factor < 50)
        unfamiliar_count = 0
        total_learn_factor = 0
        for i in range(len(list_of_familiar_factor)):
            if list_of_familiar_factor[i] == 0:
                unlearn_count = unlearn_count + 1
            if 0 < list_of_familiar_factor[i] < 50:
                unfamiliar_count = unfamiliar_count + 1
            # get the total learn factor for parametrize the approx day
            total_learn_factor += list_of_learn_factor[i]

        # estimation part
        # calculate the average learn factor
        average_learn_factor = total_learn_factor / len(list_of_learn_factor)
        day_new = float(unlearn_count) / float(number_of_key_per_day)
        day_review = float(unfamiliar_count) / float(number_of_key_per_day)
        # pre-parametrize approx day, get the max between day_new and day_review
        approx_day_left = int(max(math.ceil(day_new), math.ceil(day_review)))
        # parametrize the approx day with average learn factor, because the familiar factor will decrease with time
        approx_day_left = approx_day_left / math.exp(
            -1 / float(average_learn_factor))

        approx_day_left = int(math.ceil(approx_day_left))

        return_info = {
            'num_of_unlearn_key': unlearn_count,
            'num_of_unfamiliar_key': unfamiliar_count,
            'approx_day_left': approx_day_left
        }
        self.response.content_type = 'text/html'
        self.response.write(json.dumps(return_info))
Example #4
0
    def get(self):
        pigeon_id = self.request.get('pigeon_id')
        house_id = self.request.get('house_id')

        list_of_dict = ops.get_single_house_2(house_id)

        return_info = {'list_of_dict': list_of_dict}

        self.response.content_type = 'text/html'
        self.response.write(json.dumps(return_info))
Example #5
0
    def get(self):
        pigeon_id = self.request.get('pigeon_id')
        number_of_key_per_day = int(self.request.get('number_of_key_per_day'))
        house_id = self.request.get('house_id')

        list_of_all_cards = ops.get_single_house_2(house_id)

        # get the total card length
        total_cards = len(list_of_all_cards)

        # calculate the supposed day needed, total number of review blocks
        supposed_day = int(
            math.ceil(float(total_cards) / float(number_of_key_per_day)))
        # calculate the total day needed based on the Ebbinghaus Curve
        total_day = int(supposed_day +
                        math.pow(2, math.floor(math.log(supposed_day, 2)))) - 1
        # increase factor is to calculate how many extra days needed for review
        increase_factor = int(math.floor(math.log(supposed_day, 2)))

        # construct a schedule list
        list_of_schedule = [None] * total_day
        for i in range(0, len(list_of_schedule)):
            list_of_schedule[i] = []

        # study the new material at the beginning of a day
        for i in range(0, supposed_day):
            list_of_schedule[i].append("new" + str(i))

        # review the old material based on the general memory forgotten curve
        for i in range(0, supposed_day):
            for j in range(0, increase_factor + 1):
                list_of_schedule[int(math.pow(2, j) - 1 + i)].append("review" +
                                                                     str(i))

        # for test
        return_info = {'list_of_schedule': list_of_schedule}
        self.response.content_type = 'text/html'
        self.response.write(json.dumps(return_info))
Example #6
0
    def get(self):
        number_of_quiz = int(self.request.get('number_of_quiz'))
        house_id = self.request.get('house_id')

        # all_cards is a list of dictionary
        list_of_all_cards = ops.get_single_house_2(house_id)

        # add a error preventing mechanism
        if number_of_quiz > len(list_of_all_cards):
            return

        # get a list of all values for future convenience
        list_of_all_values = []
        for single_card in list_of_all_cards:
            for key in single_card:
                list_of_all_values.append(single_card[key])

        # get a random list of cards with total number is number_of_quiz
        list_of_random_cards = random.sample(list_of_all_cards, number_of_quiz)

        # construct the list of answer
        list_of_answer = []
        list_of_question = []
        for single_card in list_of_random_cards:
            single_answer = {}
            single_question = {}
            list_of_all_random_values = random.sample(list_of_all_values,
                                                      len(list_of_all_values))
            for key in single_card:
                single_answer["key"] = key
                single_answer["value"] = single_card[key]
                single_question["key"] = key
                single_question["list_of_possible_answer"] = []
                # including the right answer first
                single_question["list_of_possible_answer"].append(
                    single_card[key])
                count = 0
                while len(single_question["list_of_possible_answer"]
                          ) < 4 and count < len(list_of_all_random_values):
                    if list_of_all_random_values[count] != single_card[key]:
                        single_question["list_of_possible_answer"].append(
                            list_of_all_random_values[count])
                    count = count + 1
                single_question["list_of_possible_answer"] = random.sample(
                    single_question["list_of_possible_answer"],
                    len(single_question["list_of_possible_answer"]))
                single_question["answer"] = single_question[
                    "list_of_possible_answer"].index(single_card[key])
            list_of_question.append(single_question)
            list_of_answer.append(single_answer)

        # # construct the list of multiple choice
        # list_of_question = []
        # for card in list_of_random_cards:
        #     # construct a random answer list for future use
        #     list_of_all_random_values = random.sample(list_of_all_values, len(list_of_all_values))
        #     # construct a single question dict
        #     single_question = {}
        #     # get the key of the single card
        #     for key in card:
        #         # the choice is a list including 4 answers
        #         single_question[key] = []
        #         # include the right answer first
        #         single_question[key].append(card[key])
        #         # append three other values in single_question[key]
        #         count = 0
        #         while len(single_question[key]) < 4 and count < len(list_of_all_random_values):
        #             if list_of_all_random_values[count] != card[key]:
        #                 single_question[key].append(list_of_all_random_values[count])
        #             count = count + 1
        #         single_question[key] = random.sample(single_question[key], len(single_question[key]))
        #     list_of_question.append(single_question)

        return_info = {
            'list_of_question': list_of_question
            # 'list_of_answer': list_of_answer
        }
        self.response.content_type = 'text/html'
        self.response.write(json.dumps(return_info))
Example #7
0
    def get(self):
        # get the pigeon id and the house the pigeon want to learn
        pigeon_id = self.request.get('pigeon_id')
        house_id = self.request.get('house_id')
        # the number of key per day the pigeon want to learn is pre-set by user
        number_of_key_per_day = ops.get_num_per_day(pigeon_id, house_id)
        # get all cards for generation of feed
        list_of_all_cards = ops.get_single_house_2(house_id)

        # each pigeon has a special familiar factor to each card, initial is 0
        list_of_familiar_factor = []
        # number of times (factor) the pigeon has learned this card
        list_of_learn_factor = []
        # get it one by one
        for card in list_of_all_cards:
            # iterate the key (although it has only one)
            for card_key in card:
                # append the familiar factor to the list
                list_of_familiar_factor.append(
                    ops.get_familiar_factor(pigeon_id, house_id, card_key))
                list_of_learn_factor.append(
                    ops.get_learn_factor(pigeon_id, house_id, card_key))

        # the total number of the cards
        number_of_cards = len(list_of_all_cards)

        # list of feed stores the index rather than content
        list_of_feed = []
        # limit by number of new words the pigeon want to learn
        count_of_new = 0
        # assume review is equal to the new
        count_of_review = 0

        for i in range(number_of_cards):
            # TODO: which should be cron job set by 1 day (modify later)
            # the familiar factor is decreased due to Ebbinghaus forgetting curve equation
            list_of_familiar_factor[i] = list_of_familiar_factor[i] * math.exp(
                -1 / float(list_of_learn_factor[i]))
            # fetch the words need review first, the number is limited by number of key per day
            if 0 < list_of_familiar_factor[
                    i] < 50 and count_of_review < number_of_key_per_day:
                list_of_feed.append(i)
                # we assume the user 100% learn that
                # set the familiar factor to 100 (know it very well)
                list_of_familiar_factor[i] = 100.0
                count_of_review = count_of_review + 1
                # learn factor gets increased due to multiple time learning
                list_of_learn_factor[i] = list_of_learn_factor[i] * 2
            # fetch the new words
            elif list_of_familiar_factor[
                    i] == 0 and count_of_new < number_of_key_per_day:
                list_of_feed.append(i)
                list_of_familiar_factor[i] = 100.0
                count_of_new = count_of_new + 1
                # learn factor gets increased, the more time you review the less chance you forget it
                list_of_learn_factor[i] = list_of_learn_factor[i] * 2

        # set a count 1 -> 1 card
        count = 0
        for card in list_of_all_cards:
            # iterate the key (although it has only one)
            for card_key in card:
                # set a familiar factor for user towards each card
                ops.set_familiar_factor(pigeon_id, house_id, card_key,
                                        list_of_familiar_factor[count])
                # set a learn factor for user towards each card
                ops.set_learn_factor(pigeon_id, house_id, card_key,
                                     list_of_learn_factor[count])
                count = count + 1

        # construct a list of feed cards
        list_of_feed_cards = []
        for index in list_of_feed:
            single_card = {}
            for key in list_of_all_cards[index]:
                single_card["key"] = key
                single_card["value"] = list_of_all_cards[index][key]
            # [{Key: Value}, {Key: Value}, ..., {Key: Value}]
            list_of_feed_cards.append(single_card)

        # [{Key: Value}, {Key: Value}, ..., {Key: Value}]
        return_info = {'list_of_feed_cards': list_of_feed_cards}

        self.response.content_type = 'text/html'
        self.response.write(json.dumps(return_info))
Example #8
0
    def get(self):
        number_of_quiz = int(self.request.get('number_of_quiz'))
        house_id = self.request.get('house_id')

        # all_cards is a list of dictionary
        list_of_all_cards = ops.get_single_house_2(house_id)

        # add a error preventing mechanism
        if number_of_quiz > len(list_of_all_cards):
            return

        # get a list of all values for future convenience
        list_of_all_values = []
        for single_card in list_of_all_cards:
            for key in single_card:
                list_of_all_values.append(single_card[key])

        # get a random list of cards with total number is number_of_quiz
        list_of_random_cards = random.sample(list_of_all_cards, number_of_quiz)

        # construct the list of answer
        list_of_answer = []
        list_of_question = []
        for single_card in list_of_random_cards:
            single_answer = {}
            single_question = {}
            list_of_possible_answer = []
            for key in single_card:
                single_answer["key"] = key
                single_answer["value"] = single_card[key]

                list_of_possible_answer.append(single_card[key])
                list_of_possible_answer.append(
                    random.choice(list_of_all_values))
                # single_question[key] = str(random.choice(list_of_possible_answer))

                single_question["key"] = key
                single_question["possible_answer"] = str(
                    random.choice(list_of_possible_answer))

                if single_question["possible_answer"] == single_card[key]:
                    single_question["answer"] = "T"
                else:
                    single_question["answer"] = "F"

            list_of_answer.append(single_answer)
            list_of_question.append(single_question)

        # list_of_question = []
        # for single_card in list_of_random_cards:
        #     # construct a single question with only one true or false answer
        #     single_question = {}
        #     # this list should have only two values, true value and false value
        #     list_of_possible_answer = []
        #     for key in single_card:
        #         list_of_possible_answer.append(single_card[key])
        #         list_of_possible_answer.append(random.choice(list_of_all_values))
        #         single_question[key] = str(random.choice(list_of_possible_answer))
        #     list_of_question.append(single_question)

        return_info = {
            'list_of_question': list_of_question
            # 'list_of_answer': list_of_answer
        }
        self.response.content_type = 'text/html'
        self.response.write(json.dumps(return_info))