コード例 #1
0
def update(attr, old, new):
    if old == new:
        return
    t0 = time.time()
    timer = Paragraph()
    timer.text = '(Executing query...)'
    test_name_para = Paragraph()
    test_name_para.text = 'Metrics for: {}'.format(test_select.value)
    curdoc().clear()
    base_rows = [row(test_name_para), row(test_select, metric_select, timer)]
    curdoc().add_root(column(children=base_rows, ))
    test_name = test_select.value
    if test_name not in test_names:
        timer.text = 'Invalid test_name: {}'.format(test_name)
        return
    metric_substr = metric_select.value
    cutoff_timestamp = (
        datetime.datetime.now() -
        datetime.timedelta(days=30)).strftime('%Y-%m-%d %H:%M:%S UTC')
    data = metric_history.fetch_data(test_name, cutoff_timestamp)
    plots = metric_history.make_plots(test_name, metric_substr, data)
    plot_rows = [row(p) for p in plots] if plots else []
    curdoc().clear()
    curdoc().add_root(column(children=base_rows + plot_rows, ))
    t1 = time.time()
    timer.text = '(Execution time: %s seconds)' % round(t1 - t0, 4)
コード例 #2
0
 def test_make_plots_with_oob(self):
     input_df = pd.DataFrame({
         'test_name':
         pd.Series(['test1', 'test1', 'test1', 'test1']),
         'metric_name':
         pd.Series(['acc', 'loss', 'acc', 'loss']),
         'run_date':
         pd.Series(['2020-04-21', '2020-04-20', '2020-04-20',
                    '2020-04-21']),
         'metric_value':
         pd.Series([98.1, 0.5, 99.2, 0.6]),
         'metric_upper_bound':
         pd.Series([np.nan, 1.0, np.nan, 1.0]),
         'metric_lower_bound':
         pd.Series([99.0, np.nan, 99.0, np.nan]),
         'logs_link':
         pd.Series([SAMPLE_LOGS_LINK] * 4),
         'job_status':
         pd.Series(['success', 'success', 'success', 'success']),
     })
     # There should be 2 plots: 1 per metric.
     plots = metric_history.make_plots('test1', '', input_df)
     self.assertEqual(len(plots), 2)
     # 'acc' should come first since it is oob. It should be outlined in red.
     self.assertEqual([plot.title.text for plot in plots], ['acc', 'loss'])
     self.assertEqual(plots[0].outline_line_color, 'red')
     self.assertNotEqual(plots[1].outline_line_color, 'red')
コード例 #3
0
 def test_make_plots_with_oob_on_old_date(self):
     input_df = pd.DataFrame({
         'test_name':
         pd.Series(['test1', 'test1', 'test1', 'test1']),
         'metric_name':
         pd.Series(['acc', 'loss', 'acc', 'loss']),
         'run_date':
         pd.Series(['2020-04-21', '2020-04-20', '2020-04-20',
                    '2020-04-21']),
         'metric_value':
         pd.Series([99.1, 0.5, 98.2, 0.6]),
         'metric_upper_bound':
         pd.Series([np.nan, 1.0, np.nan, 1.0]),
         'metric_lower_bound':
         pd.Series([99.0, np.nan, 99.0, np.nan]),
         'logs_link':
         pd.Series([SAMPLE_LOGS_LINK] * 4),
         'job_status':
         pd.Series(['success', 'success', 'success', 'success']),
     })
     # There should be 2 plots: 1 per metric.
     plots = metric_history.make_plots('test1', '', input_df)
     self.assertEqual(len(plots), 2)
     # 'acc' was oob 2 runs ago but most recent run was OK, so it should not
     # be given a red outline.
     self.assertItemsEqual([plot.title.text for plot in plots],
                           ['acc', 'loss'])
     self.assertNotEqual(plots[0].outline_line_color, 'red')
     self.assertNotEqual(plots[1].outline_line_color, 'red')
コード例 #4
0
 def test_make_plots_with_metric_substr(self):
     input_df = pd.DataFrame({
         'test_name':
         pd.Series(['test1', 'test1', 'test1', 'test1']),
         'metric_name':
         pd.Series(['acc', 'loss', 'acc', 'loss']),
         'run_date':
         pd.Series(['2020-04-21', '2020-04-20', '2020-04-20',
                    '2020-04-21']),
         'metric_value':
         pd.Series([99.1, 0.5, 98.2, 0.6]),
         'metric_upper_bound':
         pd.Series([np.nan, 1.0, np.nan, 1.0]),
         'metric_lower_bound':
         pd.Series([99.0, np.nan, 99.0, np.nan]),
         'logs_link':
         pd.Series([SAMPLE_LOGS_LINK] * 4),
         'job_status':
         pd.Series(['success', 'success', 'success', 'success']),
     })
     # There should be only 1 plot since we're using 'loss' as search substr.
     plots = metric_history.make_plots('test1', 'loss', input_df)
     self.assertEqual(len(plots), 1)
     self.assertItemsEqual([plot.title.text for plot in plots], ['loss'])
     self.assertNotEqual(plots[0].outline_line_color, 'red')