From b5a62c5c96f95b78c3c4350943c477e4070818c3 Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Sun, 24 Sep 2017 23:41:44 +0100 Subject: [PATCH] - fixed code to run with networkx 2.0 --- BUGS.md | 1 + app.py | 5 ++--- knowledge.py | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/BUGS.md b/BUGS.md index 44b2ed3..8c60ef2 100644 --- a/BUGS.md +++ b/BUGS.md @@ -24,6 +24,7 @@ TODO: FIXED: +- ver documentacao de migracao para networkx 2.0 https://networkx.github.io/documentation/stable/release/migration_guide_from_1.x_to_2.0.html - script para adicionar users/reset passwords. - os topicos locked devem estar inactivos no sidebar. - enter faz GET /question, que responde com json no ecran. (solution: disabled enter) diff --git a/app.py b/app.py index dacb47e..1b0c610 100644 --- a/app.py +++ b/app.py @@ -39,7 +39,6 @@ class LearnApp(object): self.depgraph = build_dependency_graph(conffile) - # connect to database and check registered students self.db_setup(self.depgraph.graph['database']) @@ -153,7 +152,7 @@ class LearnApp(object): def db_add_topics(self): with self.db_session() as s: tt = [t[0] for t in s.query(Topic.id)] # db list of topics - nn = self.depgraph.nodes_iter() # topics in the graph + nn = self.depgraph.nodes() # topics in the graph s.add_all([Topic(id=n) for n in nn if n not in tt]) # ------------------------------------------------------------------------ @@ -276,7 +275,7 @@ def build_dependency_graph(config_file): # iterate over topics and create question factories logger.info('Loading:') - for tref in g.nodes_iter(): + for tref in g.nodes(): tnode = g.node[tref] # current node (topic) fullpath = path.expanduser(path.join(prefix, tref)) filename = path.join(fullpath, 'questions.yaml') diff --git a/knowledge.py b/knowledge.py index 180eb9a..9f30a46 100644 --- a/knowledge.py +++ b/knowledge.py @@ -33,8 +33,8 @@ class Knowledge(object): self.state = state # {'topic_id': {'level':0.5, 'date': datetime}, ...} - # compute recommended sequence of topics ['a', 'b',...] - self.topic_sequence = nx.topological_sort(self.depgraph) + # compute recommended sequence of topics ['a', 'b', ...] + self.topic_sequence = list(nx.topological_sort(self.depgraph)) # select a topic to do and initialize questions self.start_topic() @@ -44,15 +44,15 @@ class Knowledge(object): # If all levels > 0.8, will stay in the last one forever... # ------------------------------------------------------------------------ def start_topic(self, topic=''): - # unlock topics that have satisfied dependencies - unlock_topics = [] + # unlock topics whose dependencies are done + unlocked_topics = [] for t in self.topic_sequence: if t not in self.state: # is locked deps = self.depgraph.predecessors(t) if all(d in self.state and self.state[d]['level'] > 0.01 for d in deps): # dependencies done - unlock_topics.append(t) + unlocked_topics.append(t) - for t in unlock_topics: + for t in unlocked_topics: self.state[t] = {'level': 0.0, 'date': datetime.now()} logger.info(f'User "{self.student}" unlocked "{t}"') -- libgit2 0.21.2