Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/ReckonPrimer.activity/coach.py
blob: c6123ca75719eafa5330157f40f0ffbe202803cd (plain)
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
# -*- coding: utf-8 -*-

import os
import pprint
import pickle
from settings import Settings
from display import Display
#WN.LV remove these after new collection
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, collect, learner):
        self._sess = sess
        self._dis = dis
        self._collect = collect
        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, None)
#        _ex2 = ExPassTen(self._dis, None)
#        _ex3 = ExTimesDiv(self._dis, None)
#        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(self._collect)
        # calls back with notify('exerc-selected'...

    def notify(self, (msg, data)):
        """called by the observed objects"""
        print("in coach.notify: msg=, data=", (msg, data))
        if msg == 'setting-done': # from display
            self._ex.update_setting(data)
            #self._update_exs(self._ex)
            self._learner.notify((msg, self._ex))
        elif msg == 'exerc-selected':
            self._ex = self._collect.select(data)
            print('in coach.notify(exerc-selected), 93 self._ex._sett=',
                  self._ex._sett)
            self._dis.offer_setting(self._ex)

#    def get_ex(self, tpc):
#        """ Get an Exercise by topic. """
#        for _t in self._exs:
#            if _t.get_topic() == tpc:
#                return _t