Beispiel #1
0
 def __init__(self):
     self.initLogger()
     self.examiner = Examiner()
     self.sec = Secretary()
     self.clr = Cleaner()
     self.login()
     self.init()
Beispiel #2
0
 def __init__(self):
     self.initLogger()
     self.examiner = Examiner()
     self.sec = Secretary()
     self.clr = Cleaner()
     self.questionsDb = QuestionsDb('XFQuestionsLib.db')
     self.login()
     self.init()
Beispiel #3
0
class Experiment():
    def __init__(self, cnt_department,
                exp_period):
        self.cnt_department = cnt_department
        self.experiment_period = exp_period
        self.departments = [Department(i +1) 
                            for i in range(self.cnt_department)]

    def start_experiment(self):
        self.secretary = Secretary(cnt_department=self.cnt_department,
                                    experiment_period=self.experiment_period,
                                    departments=self.departments)
        self.secretary.generate_init_events()
        return self.secretary.schedule


    def step(self, cnt_step=1):
        self.secretary.step(cnt_step)
        return self.secretary.schedule, self.secretary.cur_time

    def add_event(self, day, time, duration, room, name, participants):
        warning = self.secretary.add_event((day, time),
                                            duration=(duration // 24, duration % 24),
                                            room=room,
                                            participants=participants,
                                            priority=1,
                                            frequency=0,
                                            name=name)

        return self.secretary.schedule, warning 

    def delete_event(self, event_id):
        warning = self.secretary.delete_event(event_id)
        return self.secretary.schedule, warning
Beispiel #4
0
class Assistant(object):
    def __init__(self):
        self.initLogger()
        self.examiner = Examiner()
        self.sec = Secretary()
        self.clr = Cleaner()
        self.login()
        self.init()

    def init(self):
        self.proc = 'ProcNull'
        self.examiner.init()
        self.sec.clear()
        self.sendYq('System init!')

    def login(self):
        itchat.auto_login()
        #itchat.auto_login(hotReload=True)
        self.yq = itchat.search_friends(name='陈有钱')[0]

    def initLogger(self):
        self.logger = logging.getLogger('Assistant')
        self.logger.setLevel(level=logging.INFO)
        handler = logging.FileHandler("log.txt")
        handler.setLevel(logging.INFO)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(filename)s - %(levelname)s - %(funcName)s - %(message)s'
        )
        handler.setFormatter(formatter)
        console = logging.StreamHandler()
        console.setLevel(logging.INFO)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(filename)s - %(levelname)s - %(funcName)s - %(message)s'
        )
        console.setFormatter(formatter)
        self.logger.addHandler(console)
        self.logger.addHandler(handler)

    def sendYq(self, msg):
        if msg != '':
            self.logger.info('sendYq: ' + msg)
            self.yq.send(msg)

    def command(self, cmd):
        self.logger.info('rec cmd: ' + cmd)
        if cmd == 'exam':
            self.proc = 'ProcExam'  #开始测试
            self.sendYq('Begin exam:')
            self.sendYq(self.examiner.ask())
        elif cmd == 'createQuestions':
            self.sendYq('Begin creating questions')
            self.proc = 'ProcCreateQuestions'  #编辑问题
        elif cmd == 'init':
            self.init()
        elif cmd.startswith('deleteQuestions '):
            self.clr.deleteAQuestion(cmd.replace('deleteQuestions ', ''))
        elif cmd.startswith('questionRecord '):
            self.sendYq(self.clr.quesRecord(cmd.replace('questionRecord ',
                                                        '')))
        else:
            self.logger.error('Sorry, I don`t known the meaning of: ' + cmd)
            self.yq.send('Sorry, I don`t known the meaning of: ' + cmd)

    def exam(self):
        q = self.examiner.ask()
        if 'Examiner: There is NO question to ask!' != q:
            self.sendYq(self.examiner.ask())
            self.status = 'EXAM'
        else:
            self.status = 'NULL'

    def process(self, msg):
        if self.proc == 'ProcExam':
            self.sendYq(self.examiner.recMsg(msg))
        elif self.proc == 'ProcCreateQuestions':
            self.sendYq(self.sec.recMsg(msg))
Beispiel #5
0
def main():
    secretary = Secretary()
    secretary.start()
Beispiel #6
0
 def start_experiment(self):
     self.secretary = Secretary(cnt_department=self.cnt_department,
                                 experiment_period=self.experiment_period,
                                 departments=self.departments)
     self.secretary.generate_init_events()
     return self.secretary.schedule