def test_expire_tiles_without_data(self): rd1 = new_report_data('points') rd2 = new_report_data('points') tile_config_1 = { 'tw_type': 'Range', 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], 'tile_options': { 'seconds_back': 86400, } } tile1 = tiles.Tile.insert(rd1.owner_id, rd1.report.report_id, rd1.dashboard_id, tile_config_1) place_tile(tile1) self.assertTrue(tile1.get_tile_data()['series_data'][0]['data_points']) tile_config_2 = { 'tw_type': 'Range', 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['john20'])), ], 'tile_options': { 'seconds_back': 86400, } } tile2 = tiles.Tile.insert(rd2.owner_id, rd2.report.report_id, rd2.dashboard_id, tile_config_2) place_tile(tile2) self.assertFalse( tile2.get_tile_data()['series_data'][0]['data_points']) res = tiles.expire_tiles_without_data([tile1, tile2], 3600, Layout.select( rd1.owner_id, rd1.dashboard_id).layout_id, optimize_check=True) self.assertIsNone(res) time.sleep(0.5) rd2.report.process_input('0') res = tiles.expire_tiles_without_data([tile1, tile2], 0.5, Layout.select( rd1.owner_id, rd1.dashboard_id).layout_id, optimize_check=True) self.assertTrue(res) self.assertFalse(Tile.select(rd1.dashboard_id, tile1.tile_id)) self.assertTrue(Tile.select(rd2.dashboard_id, tile2.tile_id))
def test_expire_tiles_without_data_losing_sscreated(self): rd = ReportData('r') ss = dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])) tile_config1 = { 'series_spec_list': [ss], 'tags': ['p1:10'], 'tile_options': { 'tpcreator_uispec': tpcreator.suggested_tpcreator_uispec(['p1:10']), 'sscs': ss } } tile1 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config1) place_tile(tile1) #rd.report.process_input('1', tags=['p1:10']) rd.report.process_input('1\n2\n', tags=['p1:11']) rd.report.process_input('1\n2\n3\n', tags=['p1:12']) self.assertEqual(3, len(rd.layout().layout_dict)) self.assertEqual(3, len(rd.get_tile_by_tags(['p1:12']).series_specs())) tile1_created_ago = datetime.datetime.utcnow( ) - util.datetime_from_uuid1(tile1.tile_id) tiles.expire_tiles_without_data( rd.layout().tile_dict.keys(), tile1_created_ago.total_seconds() - 0.00001, rd.layout().layout_id) self.assertEqual(2, len(rd.layout().layout_dict)) self.assertTrue(rd.layout_has_tags([['p1:11'], ['p1:12']])) master_tile = rd.get_tile_by_tags(['p1:11']) self.assertTrue(master_tile.is_master_tile()) self.assertEqual(master_tile.tile_id, rd.get_tile_by_tags(['p1:12']).get_master_tile_id()) self.assertEqual(3, len(rd.get_tile_by_tags(['p1:12']).series_specs()))
def test_removing_tiles_by_expiring(self): rd, master_tile = self.test_handle_tpcreator() tiles = Tile.select_multi(rd.dashboard_id, _select_tile_ids(rd.dashboard_id)).values() #print tpcreator.select_tpcreated_tile_ids(master_tile) #print select_tile_ids(rd.dashboard_id) #print rd.layout_data().layout_dict.keys() #tile = Tile.select(rd.dashboard_id, util.first(tile_id for tile_id in select_tile_ids(rd.dashboard_id) if tile_id not in rd.layout_data().layout_dict.keys())) #print tile self.assertTrue( expire_tiles_without_data(tiles, 0, rd.layout().layout_id)) self.assertEqual(0, len(tpcreator.select_tpcreated_tile_ids(master_tile))) self.assertEqual(1, len(_select_tile_ids(rd.dashboard_id)))
def request_expire_tiles_without_data(): dashboard_id = request.get_json()['dashboard_id'] tile_id_list = request.get_json()['tile_id_list'] check_access(lambda: auth.access_dashboard(dashboard_id)) dashboard = dashboards.Dashboard.select(auth.logged_owner_id(), dashboard_id) if not dashboard: return error('No dashboard') max_seconds_without_data = nestedget(dashboard.dashboard_options, 'max_without_data', 'seconds_back') if not max_seconds_without_data: log.warn('request_expire_tiles_without_data called with empty max_seconds_without_data') return tile_list = tiles.Tile.select_multi(dashboard_id, tile_id_list).values() new_layout_id = tiles.expire_tiles_without_data(tile_list, max_seconds_without_data, None) return success(result=dict(tiles_expired=bool(new_layout_id)))
def test_expire_tiles_without_data_two_masters(self): rd = new_report_data('points', ['p3:30']) tile_config1 = { 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], 'tile_options': { 'seconds_back': 1000, 'tile_title': 'tile1' } } tile1 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config1) place_tile(tile1) tile_config2 = { 'tags': ['p1:10'], 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], 'tile_options': { 'seconds_back': 1000, 'tile_title': 'tile2 [p1:10]', 'tpcreator_uispec': tpcreator.suggested_tpcreator_uispec(['p1:10']), } } tile2 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config2) place_tile(tile2) tile_config3 = { 'tags': ['p2:20'], 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], 'tile_options': { 'seconds_back': 1000, 'tile_title': 'tile3', 'tpcreator_uispec': tpcreator.suggested_tpcreator_uispec(['p2:20']), } } tile3 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config3) place_tile(tile3) #rd.report.process_input(json.dumps([dict(user_name='monique', is_active=True, points=128)]), tags=['p1:10']) #rd.report.process_input(json.dumps([dict(user_name='monique', is_active=True, points=128)]), tags=['p2:20']) time.sleep(1) rd.report.process_input(json.dumps([ OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 128)]) ]), tags=['p1:11']) rd.report.process_input(json.dumps([ OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 128)]) ]), tags=['p1:12']) rd.report.process_input(json.dumps([ OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 128)]) ]), tags=['p1:13']) rd.report.process_input(json.dumps([ OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 128)]) ]), tags=['p2:21']) rd.report.process_input(json.dumps([ OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 128)]) ]), tags=['p2:22']) lid = tiles.expire_tiles_without_data(rd.layout().tile_dict.keys(), 2000, rd.layout().layout_id) self.assertFalse(lid) lid = tiles.expire_tiles_without_data(rd.layout().tile_dict.keys(), 1, rd.layout().layout_id) self.assertTrue(lid) self.assertEqual(6, len(rd.layout().layout_dict)) self.assertEqual(6, len(_select_tile_ids(rd.dashboard_id))) tile_list = rd.layout().tile_dict.keys() self.assertEqual( sorted([[], ['p1:11'], ['p1:12'], ['p1:13'], ['p2:21'], ['p2:22']]), sorted([t.tags for t in tile_list])) master1 = first( t for t in tile_list if t.tags and t.tags[0].startswith('p1') and t.is_master_tile()) master2 = first( t for t in tile_list if t.tags and t.tags[0].startswith('p2') and t.is_master_tile()) self.assertEqual( 2, len(rd.layout().get_tpcreated_tile_ids(master1.tile_id))) self.assertEqual( 1, len(rd.layout().get_tpcreated_tile_ids(master2.tile_id))) self.assertEqual(['p1:11'], master1.tags) self.assertEqual(['p2:21'], master2.tags) self.assertEqual('tile2 [p1:11]', master1.tile_options['tile_title']) self.assertEqual('tile3', master2.tile_options['tile_title'])
def test_expire_tiles_without_data_master(self): rd = new_report_data('points', ['p1:10']) tile_config1 = { 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], 'tile_options': { 'seconds_back': 1000, 'tile_title': 'tile1' } } tile1 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config1) place_tile(tile1) tile_config2 = { 'tags': ['p1:10'], 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], 'tile_options': { 'seconds_back': 1000, 'tile_title': 'tile2', 'tpcreator_uispec': tpcreator.suggested_tpcreator_uispec(['p1:10']), } } tile2 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id, tile_config2) place_tile(tile2) d = [ OrderedDict([('user_name', 'robert'), ('is_active', True), ('points', 128)]), OrderedDict([('user_name', 'monique2'), ('is_active', True), ('points', 210)]), OrderedDict([('user_name', 'monique3'), ('is_active', True), ('points', 210)]), OrderedDict([('user_name', 'monique4'), ('is_active', True), ('points', 210)]), OrderedDict([('user_name', 'robert2'), ('is_active', True), ('points', 210)]), ] rd.report.process_input(json.dumps([ OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 128)]) ]), tags=['p1:11']) rd.report.process_input(json.dumps([ OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 128)]) ]), tags=['p1:12']) rd.report.process_input(json.dumps([ OrderedDict([('user_name', 'monique'), ('is_active', True), ('points', 128)]) ]), tags=['p1:13']) self.assertEqual(5, len(rd.layout().layout_dict)) lid = tiles.expire_tiles_without_data(rd.layout().tile_dict.keys(), 2000, rd.layout().layout_id) self.assertFalse(lid) self.assertEqual(5, len(rd.layout().layout_dict)) lid = tiles.expire_tiles_without_data(rd.layout().tile_dict.keys(), 0, rd.layout().layout_id) self.assertTrue(lid) self.assertEqual(1, len(rd.layout().layout_dict)) self.assertEqual(1, len(_select_tile_ids(rd.dashboard_id))) self.assertEqual(tile2.tile_id, rd.layout().tile_dict.keys()[0].tile_id)
def test_expire_tiles_without_data_optimize_check(self): owner_id = report_data('points').report.owner_id report_id = report_data('points').report.report_id dashboard_id = report_data('points').dashboard_id report_data('points').report.process_input( json.dumps([ OrderedDict([('user_name', 'xxx'), ('is_active', True), ('points', 1000)]), OrderedDict([('user_name', 'yy'), ('is_active', True), ('points', 2000)]), ]), created=datetime.datetime.utcnow() - datetime.timedelta(hours=8)) tile_config_1 = { 'tw_type': 'Range', 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])), ], 'tile_options': { 'seconds_back': 86400, } } tile1 = tiles.Tile.insert(owner_id, report_id, dashboard_id, tile_config_1) self.assertTrue(tile1.get_tile_data()['series_data'][0]['data_points']) tile_config_2 = { 'tw_type': 'Range', 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['john'])), ], 'tile_options': { 'seconds_back': 86400, } } tile2 = tiles.Tile.insert(owner_id, report_id, dashboard_id, tile_config_2) self.assertTrue(tile2.get_tile_data()['series_data'][0]['data_points']) tile_config_3 = { 'tw_type': 'Range', 'series_spec_list': [ dataseries.SeriesSpec(2, 0, dict(op='eq', args=['xxx'])), ], 'tile_options': { 'seconds_back': 86400, } } tile3 = tiles.Tile.insert(owner_id, report_id, dashboard_id, tile_config_3) self.assertTrue(tile3.get_tile_data()['series_data'][0]['data_points']) place_tile(tile1) place_tile(tile2) place_tile(tile3) res = tiles.expire_tiles_without_data([tile1, tile2, tile3], 3600, Layout.select( owner_id, dashboard_id).layout_id) self.assertTrue(res) tile1 = tiles.Tile.select(tile1.dashboard_id, tile1.tile_id) self.assertIsNotNone(tile1) tile2 = tiles.Tile.select(tile2.dashboard_id, tile2.tile_id) self.assertIsNotNone(tile2) tile3 = tiles.Tile.select(tile3.dashboard_id, tile3.tile_id) self.assertIsNone(tile3) res = tiles.expire_tiles_without_data([tile1, tile2], 3600, Layout.select( owner_id, dashboard_id).layout_id) self.assertFalse(res)