Commit b5a62c5c96f95b78c3c4350943c477e4070818c3

Authored by Miguel Barão
1 parent 7838cd47
Exists in master and in 1 other branch dev

- fixed code to run with networkx 2.0

Showing 3 changed files with 9 additions and 9 deletions   Show diff stats
BUGS.md
... ... @@ -24,6 +24,7 @@ TODO:
24 24  
25 25 FIXED:
26 26  
  27 +- ver documentacao de migracao para networkx 2.0 https://networkx.github.io/documentation/stable/release/migration_guide_from_1.x_to_2.0.html
27 28 - script para adicionar users/reset passwords.
28 29 - os topicos locked devem estar inactivos no sidebar.
29 30 - enter faz GET /question, que responde com json no ecran. (solution: disabled enter)
... ...
app.py
... ... @@ -39,7 +39,6 @@ class LearnApp(object):
39 39  
40 40 self.depgraph = build_dependency_graph(conffile)
41 41  
42   -
43 42 # connect to database and check registered students
44 43 self.db_setup(self.depgraph.graph['database'])
45 44  
... ... @@ -153,7 +152,7 @@ class LearnApp(object):
153 152 def db_add_topics(self):
154 153 with self.db_session() as s:
155 154 tt = [t[0] for t in s.query(Topic.id)] # db list of topics
156   - nn = self.depgraph.nodes_iter() # topics in the graph
  155 + nn = self.depgraph.nodes() # topics in the graph
157 156 s.add_all([Topic(id=n) for n in nn if n not in tt])
158 157  
159 158 # ------------------------------------------------------------------------
... ... @@ -276,7 +275,7 @@ def build_dependency_graph(config_file):
276 275  
277 276 # iterate over topics and create question factories
278 277 logger.info('Loading:')
279   - for tref in g.nodes_iter():
  278 + for tref in g.nodes():
280 279 tnode = g.node[tref] # current node (topic)
281 280 fullpath = path.expanduser(path.join(prefix, tref))
282 281 filename = path.join(fullpath, 'questions.yaml')
... ...
knowledge.py
... ... @@ -33,8 +33,8 @@ class Knowledge(object):
33 33  
34 34 self.state = state # {'topic_id': {'level':0.5, 'date': datetime}, ...}
35 35  
36   - # compute recommended sequence of topics ['a', 'b',...]
37   - self.topic_sequence = nx.topological_sort(self.depgraph)
  36 + # compute recommended sequence of topics ['a', 'b', ...]
  37 + self.topic_sequence = list(nx.topological_sort(self.depgraph))
38 38  
39 39 # select a topic to do and initialize questions
40 40 self.start_topic()
... ... @@ -44,15 +44,15 @@ class Knowledge(object):
44 44 # If all levels > 0.8, will stay in the last one forever...
45 45 # ------------------------------------------------------------------------
46 46 def start_topic(self, topic=''):
47   - # unlock topics that have satisfied dependencies
48   - unlock_topics = []
  47 + # unlock topics whose dependencies are done
  48 + unlocked_topics = []
49 49 for t in self.topic_sequence:
50 50 if t not in self.state: # is locked
51 51 deps = self.depgraph.predecessors(t)
52 52 if all(d in self.state and self.state[d]['level'] > 0.01 for d in deps): # dependencies done
53   - unlock_topics.append(t)
  53 + unlocked_topics.append(t)
54 54  
55   - for t in unlock_topics:
  55 + for t in unlocked_topics:
56 56 self.state[t] = {'level': 0.0, 'date': datetime.now()}
57 57 logger.info(f'User "{self.student}" unlocked "{t}"')
58 58  
... ...