1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# -*- coding: utf-8 -*-
import os
import pprint
import pickle
from settings import Settings
from display import Display
from exercise import Exercise
from exaddsimp import ExAddSimp
from expassten import ExPassTen
from extimesdiv import ExTimesDiv
class Coach:
"""determines Settings which might come from Display.
Thus Coach is an observer (!design pattern!) of Display,
and consequently Session is an observer (!design pattern!) of Coach
"""
print("DEL import Coach")
def __init__(self):
print("DEL do Coach.__init__")
self._setts = Settings()
self._key = ''
# self._dis = sess._dis # see sequence of creation in Session
# --->???self._curr_sett = None - Coach has only 1 current setting
# self._exs = self.create_exs()
self._ex = None
def register(self, sess, dis, learner):
self._sess = sess
self._dis = dis
self._learner = learner
def create_exercises(self):
self._exs = self.create_exs()
def create_exs(self):
"""TODO version preliminary until exs are stored on disk"""
['addsub_simp', 'passten', 'times_div']
_ex1 = ExAddSimp(self._dis)
_ex2 = ExPassTen(self._dis)
_ex3 = ExTimesDiv(self._dis)
return[_ex1, _ex2, _ex3]
def _update_exs(self, ex):
"""update one of the examples known to Coach by topic.
TODO after exs are stored on disk: take ID instead topic
"""
# print('in Coach.update_ex: ex.topic=', ex.get_topic())
_exs = []
for _e in self._exs:
if _e.get_topic() == ex.get_topic():
_exs.append(ex)
else:
_exs.append(_e)
self._exs = _exs
def request_exercise(self):
""" This preliminary version just lets the Learner select. """
#print("in coach.request_exercise")
self._dis.offer_coll_to_learner([t.get_topic() for t in self._exs])
# calls back with notify('setting-done'...
def notify(self, (msg, data)):
"""called by the observed objects"""
print("in Coach.notify: msg=, data=", (msg, data))
if msg == 'setting-done': # from
# + self._setts.save_last_sett(self._key, data)
self._ex.update_setting(data)
self._update_exs(self._ex)
self._learner.notify((msg, self._ex))
elif msg == 'new-topic':
self._ex = self.get_ex(data)
print('in Coach.notify(new-topic), 93 self._ex._sett=',
self._ex._sett)
self._dis.offer_setting(self._ex)
def get_ex(self, tpc):
"""Get an Exercise by topic. TODO get by ID if exs are stored on disk.
"""
for _t in self._exs:
if _t.get_topic() == tpc:
return _t
|