def values(tags, after): sd_id = dataseries.SeriesDef.select_id_or_insert( cd.report.report_id, tags, dataseries.guess_series_spec(cd.report, cd.instances[0], 0, 0)) sd = dataseries.SeriesDef.select(cd.report.report_id, tags, sd_id) res = dataseries.get_series_values_after(sd, cd.report, after) return [sv.value for sv in res]
def values(tags): sd_id = dataseries.SeriesDef.select_id_or_insert( cd.report.report_id, tags, dataseries.guess_series_spec(cd.report, cd.instances[0], 0, 0)) sd = dataseries.SeriesDef.select(cd.report.report_id, tags, sd_id) res = dataseries.get_series_values( sd, cd.report, datetime.datetime.utcnow() - datetime.timedelta(days=1), datetime.datetime.utcnow(), 1000) return [sv.value for sv in res]
def test_filling_default_options(self): rd = new_report_data('points', tags=['ip:192.168.1.1']) for tw_type in ('Range', 'Single'): ss1 = dataseries.SeriesSpec(2, 0, dict(op='eq', args=['mike'])) ss1.promote_colnos_to_headers(rd.instances[-1]) ss1.set_name('mikepoints') tile_config = { 'tw_type': tw_type, 'tags': ['ip:192.168.1.1'], 'series_spec_list': [ ss1, dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], 'tile_options': { 'colors': ['red', 'blue', 'pink', 'cyan'], 'seconds_back': 600, 'tile_title': 'Points by user', 'sscs': dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), } } tile = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config) dataseries.update_default_options(tile) data = tile.get_tile_data() self.assertEqual(['red', 'blue'], data['combined_colors']) tile_config2 = { 'tw_type': tw_type, 'tags': ['ip:192.168.1.1'], 'series_spec_list': [ dataseries.guess_series_spec(rd.report, rd.instances[-1], 1, 2), dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], } self.assertEqual('mikepoints', tile_config2['series_spec_list'][0].name()) tile2 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config) dataseries.update_default_options(tile2) data2 = tile2.get_tile_data() self.assertEqual('mikepoints', data2['series_data'][0]['name']) self.assertEqual(['red', 'blue'], data2['combined_colors'])
def compute_series_spec(): report_id = request.get_json()['report_id'] report_instance_id = request.get_json()['report_instance_id'] sample = request.get_json()['sample'] check_access(lambda: auth.access_report_instances(report_id)) report = Report.select(report_id) report_instance = report.fetch_single_instance(report_instance_id) series_spec = dataseries.guess_series_spec(report, report_instance, sample['rowno'], sample['colno']) if series_spec is None: return error() series_spec_html = get_template_attribute('m.html', 'series_spec')(series_spec, report_instance) return success(result=dict(series_spec=series_spec, series_spec_html=series_spec_html))
def test_guess_series_spec(self): ss = guess_series_spec( report_data('points').report, report_data('points').instances[0], 2, 2) ss_expected = SeriesSpec(2, 0, dict(op='eq', args=['monique'])) ss_expected.promote_colnos_to_headers( report_data('points').instances[0]) self.series_specs_equal(ss_expected, ss) ss = guess_series_spec( report_data('points').report, report_data('points').instances[0], 2, 0) ss_expected = SeriesSpec(0, -1, dict(op='eq', args=['2'])) ss_expected.promote_colnos_to_headers( report_data('points').instances[0]) self.series_specs_equal(ss_expected, ss) cd = CustomData([10, 20]) ss = guess_series_spec(cd.report, cd.instances[-1], 0, 0) ss_expected = SeriesSpec(0, -1, dict(op='eq', args=['0'])) ss_expected.promote_colnos_to_headers(cd.instances[-1]) self.series_specs_equal(ss_expected, ss) cd = CustomData([[1, 2, 3], [4, 5, 6]]) ss = guess_series_spec(cd.report, cd.instances[-1], 2, 0) ss_expected = SeriesSpec(0, -1, dict(op='eq', args=['2'])) ss_expected.promote_colnos_to_headers(cd.instances[-1]) self.series_specs_equal(ss_expected, ss) cd = CustomData([[["aaa", 10], ["bbb", 20]]]) ss = guess_series_spec(cd.report, cd.instances[-1], 1, 1) ss_expected = SeriesSpec(1, 0, dict(op='eq', args=['bbb'])) ss_expected.promote_colnos_to_headers(cd.instances[-1]) self.series_specs_equal(ss_expected, ss) cd = CustomData([[["aaa", 10]]]) ss = guess_series_spec(cd.report, cd.instances[-1], 0, 1) ss_expected = SeriesSpec(1, 0, dict(op='eq', args=['aaa'])) ss_expected.promote_colnos_to_headers(cd.instances[-1]) self.series_specs_equal(ss_expected, ss)
def test_get_series_values_multiple_inserts(self): cd = CustomData(range(20)) sd_id = dataseries.SeriesDef.select_id_or_insert( cd.report.report_id, [], dataseries.guess_series_spec(cd.report, cd.instances[0], 0, 0)) sd = dataseries.SeriesDef.select(cd.report.report_id, [], sd_id) res = dataseries.get_series_values( sd, cd.report, datetime.datetime.utcnow() - datetime.timedelta(days=1), datetime.datetime.utcnow(), 1000) self.assertEqual(range(20), [sv.value for sv in res]) cd.report.process_input('200') sd = dataseries.SeriesDef.select(cd.report.report_id, [], sd_id) res = dataseries.get_series_values( sd, cd.report, datetime.datetime.utcnow() - datetime.timedelta(days=1), datetime.datetime.utcnow(), 1000) self.assertEqual(range(20) + [200], [sv.value for sv in res]) cd.report.process_input('200') sd = dataseries.SeriesDef.select(cd.report.report_id, [], sd_id) res = dataseries.get_series_values( sd, cd.report, datetime.datetime.utcnow() - datetime.timedelta(days=1), datetime.datetime.utcnow(), 1000) self.assertEqual(range(20) + [200, 200], [sv.value for sv in res]) cd.report.process_input('80', created=datetime.datetime.utcnow() - datetime.timedelta(seconds=10)) sd = dataseries.SeriesDef.select(cd.report.report_id, [], sd_id) res = dataseries.get_series_values( sd, cd.report, datetime.datetime.utcnow() - datetime.timedelta(days=1), datetime.datetime.utcnow(), 1000) self.assertEqual([80] + range(20) + [200, 200], [sv.value for sv in res]) ri = cd.report.process_input('200').report_instance sd = dataseries.SeriesDef.select(cd.report.report_id, [], sd_id) res = dataseries.get_series_values( sd, cd.report, datetime.datetime.utcnow() - datetime.timedelta(days=1), datetime.datetime.utcnow(), 1000) self.assertEqual([80] + range(20) + [200, 200, 200], [sv.value for sv in res]) cd.report.process_input('300', created=ri.created - datetime.timedelta(milliseconds=1)) sd = dataseries.SeriesDef.select(cd.report.report_id, [], sd_id) res = dataseries.get_series_values( sd, cd.report, datetime.datetime.utcnow() - datetime.timedelta(days=1), datetime.datetime.utcnow(), 1000) self.assertEqual([80] + range(20) + [200, 200, 300, 200], [sv.value for sv in res]) # tags cd.report.process_input('400', created=ri.created - datetime.timedelta(milliseconds=2), tags=['aaa']) sd = dataseries.SeriesDef.select(cd.report.report_id, [], sd_id) res = dataseries.get_series_values( sd, cd.report, datetime.datetime.utcnow() - datetime.timedelta(days=1), datetime.datetime.utcnow(), 1000) self.assertEqual([80] + range(20) + [200, 200, 400, 300, 200], [sv.value for sv in res])