Beispiel #1
0
    def get_word_list_view(self, user: User) -> WordListView:
        # query = """
        #     optional match (u:User{email:"%s"})-[:Seen]->(wSeen:Word)
        #     optional match (u)-[:Forgotten]->(wForgotten:Word)
        #     optional match (u)-[:Learnt]->(wLearnt:Word)
        #     return wSeen, wForgotten, wLearnt
        # """ % user.email
        query = """
            match (u:User{email:"%s"})-[:Seen]->(wSeen:Word)
            return wSeen
        """ % user.email
        results = self._db.query(query)
        seen_list = WordModel.parse_words(results)

        query = """
            match (u:User{email:"%s"})-[:Forgotten]->(wForgotten:Word)
            return wForgotten
        """ % user.email
        results = self._db.query(query)
        forgotten_list = WordModel.parse_words(results)

        query = """
            match (u:User{email:"%s"})-[:Learnt]->(wLearnt:Word)
            return wLearnt
        """ % user.email
        results = self._db.query(query)
        learnt_list = WordModel.parse_words(results)

        # for element in results.elements:
        #     seen_list.append(element[0])
        #     forgotten_list.append(element[1])
        #     learnt_list.append(element[2])

        return WordListView(seen_list, learnt_list, forgotten_list)
Beispiel #2
0
def finished_round():

    user = User(session['email'])
    user_model = UserModel()
    word_list_view = user_model.get_word_list_view(user)
    seen_list = word_list_view.seen_word_list
    learnt_list = word_list_view.learnt_word_list
    forgotten_list = word_list_view.forgotten_word_list

    # graph_pygal = pygal.Line()
    # graph_pygal.title = '% Change Coolness of programming languages over time.'
    # graph_pygal.x_labels = ['2011', '2012', '2013', '2014', '2015', '2016']
    # graph_pygal.add('Python', [15, 31, 89, 200, 356, 900])
    # graph_pygal.add('Java', [15, 45, 76, 80, 91, 95])
    # graph_pygal.add('C++', [5, 51, 54, 102, 150, 201])
    # graph_pygal.add('All others combined!', [5, 15, 21, 55, 92, 105])

    pie_chart = pygal.Pie()
    pie_chart.title = 'TITLE'
    pie_chart.add('Seen Words', WordModel.get_number_labels(seen_list))
    pie_chart.add('Forgotten Words', WordModel.get_number_labels(forgotten_list))
    pie_chart.add('Learnt Words', WordModel.get_number_labels(learnt_list))
    pie_chart.render()
    graph_data = pie_chart.render_data_uri()

    return render_template('list.html',
                           seen_list=seen_list,
                           learnt_list=learnt_list,
                           forgotten_list=forgotten_list,
                           graph_data=graph_data
                           )
Beispiel #3
0
def get_next_words():
    if 'logged_in' in session:
        words = WordModel().get_words(14)
    else:
        words = WordModel().get_words(12)

    word_list = [word.get_dictionary() for word in words]
    return parse_json(word_list)
Beispiel #4
0
def check_word(word_name, word_definition, word_label):
    word_model = WordModel()
    state = word_model.is_matched(Word(name=word_name, definition=word_definition, label=word_label))
    print(state)
    if state:
        return parse_json(True)
    else:
        return parse_json(False)
Beispiel #5
0
 def get_forgotten_words(self, user: User) -> list:
     try:
         query = """
             MATCH (u:User{email:"%s"})-[:Forgotten]->(forgottenWords:Word)
             RETURN forgottenWords LIMIT %d
         """ % (user.email, self.word_set * 4)
         results = self._db.query(query)
         return WordModel.parse_words(results)
     except Exception as e:
         print(e)
         return []
Beispiel #6
0
 def get_random_recommendation(self) -> list:
     try:
         query = """
             MATCH (w:Word)
             WHERE rand() < 0.5
             return w limit %d
         """ % (self.word_set * 4)
         results = self._db.query(query)
         return WordModel.parse_words(results)
     except Exception as e:
         print(e)
         return []
Beispiel #7
0
 def get_recommended_words(self, user: User) -> list:
     try:
         query = """
             MATCH (u:User{email:"%s"})-[:Seen]->(w)<-[:Seen]-(colleges:User),
                   (colleges)-[:Seen]->(recW:Word)
             WHERE NOT (u)-[:Seen]->(recW) AND NOT (w)-[:Learnt]->(recW) AND NOT (w)-[:Forgotten]->(recW)
             RETURN recW LIMIT %d
         """ % (user.email, self.word_set * 4)
         results = self._db.query(query)
         return WordModel.parse_words(results)
     except Exception as e:
         print(e)
         return []
Beispiel #8
0
    def seen_word(self, user, word, correct: bool):
        try:
            query = """
                MATCH (u:%s{email:"%s"})-[r]-(w:Word{name:"%s"}) return r.correct, r.incorrect
            """ % (self._label, user.email, word.name)
            results = list(self._db.query(query))

            correct_stat = 1 if correct else 0
            incorrect_stat = 1 if not correct else 0

            if results:
                result_correct = results[0][0] + correct_stat
                result_incorrect = results[0][1] + incorrect_stat
                acc = self.get_accuracy(result_correct, result_incorrect)
                label = self.get_label(acc)

                q = """
                    MATCH (u:User{email:"%s"})-[r]-(w:Word{name:"%s"})
                    CREATE (u)-[newR:%s{correct:%d, incorrect:%d}]->(w)
                    delete r
                    return newR.correct, newR.incorrect
                """ % (user.email, word.name, label, result_correct,
                       result_incorrect)

                print(acc)
                new_seen = self._db.query(q)
                print(new_seen)
            else:
                user_node = self.get_node(user)
                word_node = WordModel().get_node(word)
                if correct:
                    user_node.relationships.create(self._seen,
                                                   word_node,
                                                   correct=correct_stat,
                                                   incorrect=incorrect_stat)
                else:
                    user_node.relationships.create(self._forgotten,
                                                   word_node,
                                                   correct=correct_stat,
                                                   incorrect=incorrect_stat)

        except Exception as e:
            print(e)
Beispiel #9
0
from API.WikipediaAPI import WikipediaAPI
from models.ExampleTwitterModel import ExampleTwitterModel
from models.WordModel import WordModel

if __name__ == '__main__':
    word_model = WordModel()
    words = word_model.get_words(12)

    # for word in words:
    #     exampleTwitterModel = ExampleTwitterModel()
    #     tweets = exampleTwitterModel.get_examples(word.name)
    #     for tweet in tweets:
    #         print(tweet)
    for word in words:
        contents = WikipediaAPI.get_content(word.name, 2)
        print("\n\nWORD:\t", word, "\n")
        if contents:
            for content in contents:
                print("\n")
                print("title:\t", content[0], "\n")
                print("categories:\t", content[1], "\n")
                print("content:\t", content[2], "\n")