def __init__(self, argv:[str]): trace(0, argv) self.args = CommandLineParser(argv) self.mxver = int(self.args.get_arg('mxver', '0')) if self.mxver == 6: self.help_file = 'trace-help.output' self.display_file = 'trace-display.output' self.print_file = 'trace-print-6x.output' elif self.mxver == 7: self.help_file = 'trace-help-7.x.output' self.display_file = 'trace-display-7.x.output' self.print_file = 'trace-print-6x.output' # TODO, change to 7 else: raise ValueError("Unknown MX-One version " + str(self.mxver)) display_args = self.args.display print_args = self.args.print_args if self.args.help: self.print_help() elif not display_args is None: self.print_display() elif not print_args is None: self.print_print(print_args) else: print_str("args: " + " ".join(sys.argv[1:])) pass
def test_display(self): with captured_output() as (out, err): trace_mockup.TraceMockup([u'fake_progname', u'-display', u'-mxver', u'7']) errout = err.getvalue() if not errout is None and len(errout) > 0: print_str(errout, f=sys.stderr) output = out.getvalue() print_str(u'#### output:') print_str(output) l = len(output) self.assertLess(10, l, u'Had expected more than len==10 for output') self.assertTrue(self.find_keyword(output, u"\n Version:"))
def test_print_indv_SIPLP(self): with captured_output() as (out, err): trace_mockup.TraceMockup([u'fake_progname', u'-print', u'1', u'-mxver', u'7']) errout = err.getvalue() if not errout is None and len(errout) > 0: print_str(errout, f=sys.stderr) self.fail(u"Something on stderr") output = out.getvalue() print_str(u'#### output:') print_str(output) self.assertTrue(self.find_keyword(output, u" Version:")) self.assertEqual(u"1", self.find_keyword(output, u"\n Trace ind:")) self.assertEqual(u"SIPLP", self.find_keyword(output, u" Unit name:"))
def test_print_id(self): with captured_output() as (out, err): trace_mockup.TraceMockup([u'fake_progname', u'-print', u'3', u'-mxver', u'7']) errout = err.getvalue() if not errout is None and len(errout) > 0: print_str(errout, f=sys.stderr) output = out.getvalue() print_str(u'#### output:') print_str(output) self.assertLess(10, len(output), u'Had expected more than len==10 for output') self.assertTrue(self.find_keyword(output, u" Version:")) self.assertEqual(u"3", self.find_keyword(output, u"\n Trace ind:")) self.assertEqual(u"CMP", self.find_keyword(output, u" Unit name:")) end_of_header = output.find(u"\n\n") or output.find(u"\r\n\r\n") pos_siplp = output.find(u"SIPLP") if pos_siplp > 0: self.assertLess(end_of_header, pos_siplp, u"Should not be any SIPLP keyword in output")
def __log_str(self, model_file=None): ''' ClinerModel::__log_str() Build a string of information about training for the model's log file. @param model_file. A path to optionally identify where the model was saved. @return A string of the model's training information ''' assert self._is_trained, 'ClinerModel not trained' with io.StringIO() as f: write(f, u'\n') write(f, '-' * 40) write(f, u'\n\n') if model_file: write(f, 'model : %s\n' % os.path.abspath(model_file)) write(f, u'\n') if self._use_lstm: write(f, u'modeltype: LSTM\n') else: write(f, u'modeltype: CRF\n') if 'hyperparams' in self._score: for name, value in self._score['hyperparams'].items(): write(f, u'\t%-10s: %s\n' % (name, value)) write(f, u'\n') print_str(f, 'features', self._features) write(f, u'\n') write(f, u'\n') write(f, 'training began: %s\n' % self._time_train_begin) write(f, 'training ended: %s\n' % self._time_train_end) write(f, u'\n') write(f, u'scores\n') print_vec(f, 'train precision', self._score['train']['precision']) print_vec(f, 'train recall ', self._score['train']['recall']) print_vec(f, 'train f1 ', self._score['train']['f1']) write(f, self._score['train']['conf']) if 'dev' in self._score: print_vec(f, u'dev precision ', self._score['dev']['precision']) print_vec(f, u'dev recall ', self._score['dev']['recall']) print_vec(f, u'dev f1 ', self._score['dev']['f1']) write(f, self._score['dev']['conf']) if 'test' in self._score: print_vec(f, u'test precision ', self._score['test']['precision']) print_vec(f, u'test recall ', self._score['test']['recall']) print_vec(f, u'test f1 ', self._score['test']['f1']) write(f, self._score['test']['conf']) if 'history' in self._score: for label, vec in self._score['history'].items(): print_vec(f, '%-16s' % label, vec) write(f, u'\n') if self._training_files: write(f, u'\n') write(f, u'Training Files\n') if len(self._training_files) < 200: print_files(f, self._training_files) else: write(f, '\t%d files\n' % len(self._training_files)) write(f, u'\n') write(f, u'-' * 40) write(f, u'\n\n') # get output as full string contents = f.getvalue() return contents
def print_display(self): disp_str = self.readfile(self.display_file) cc = self.args.get_arg('call-count', 0) if int(cc) < 3: sys.stdout.write(disp_str) return disp_str # add MADEUP as extra module key = 'State: idle/free' has_found = False for line in disp_str.splitlines(): if not has_found and line.endswith(key): print_str(line[:len(line)-len(key)] + 'State: stopped , Stored: 75, Size per lim: 5000') print_str(' First: 2019-01-22 16:16:01 (CET) Last: 2019-01-22 16:16:19 (CET)') print_str(' Type : unit-trace , Rotating: on , Textlevel: normal') print_str(' Lim no : 1, Unit no: 4711, Unit name: MADEUP') print_str(' Time mark: 2019-01-22 16:16:32 (CET), by user: mxone_admin') print_str(' Trace stopped by : command (manually stopped)') has_found = True else: print_str(line)