Ejemplo n.º 1
0
    def test_names(self):
        tile = call(tiles_test.TileTest.test_insert)
        self.assertNotIn(
            'name',
            select_default_series_spec_options(tile.report_id,
                                               tile.series_specs())[0])

        tile_config = tile.get_tile_config()
        for i, ss in enumerate(tile_config['series_spec_list']):
            ss.set_name('serie%d' % i)
        tile = tile.insert_similar(tile_config)
        update_default_options(tile)
        self.assertEqual(
            'serie0',
            select_default_series_spec_options(tile.report_id,
                                               tile.series_specs())[0]['name'])
        self.assertEqual(
            'serie1',
            select_default_series_spec_options(tile.report_id,
                                               tile.series_specs())[1]['name'])

        tile_config = tile.get_tile_config()
        for i, ss in enumerate(tile_config['series_spec_list']):
            ss.set_name('s%d' % i)
        tile = tile.insert_similar(tile_config)
        update_default_options(tile)
        self.assertEqual(
            's0',
            select_default_series_spec_options(tile.report_id,
                                               tile.series_specs())[0]['name'])
        self.assertEqual(
            's1',
            select_default_series_spec_options(tile.report_id,
                                               tile.series_specs())[1]['name'])
Ejemplo n.º 2
0
def replace_tile():
    dashboard_id = request.get_json()['dashboard_id']
    tile_id = request.get_json()['tile_id']
    report_id = request.get_json()['report_id']
    tile_config = request.get_json()['tile_config']
    for_layout_id = request.get_json()['for_layout_id']

    check_access(lambda: auth.access_dashboard(dashboard_id))
    check_access(lambda: auth.access_report_instances(report_id))

    tile = tiles.Tile.select(dashboard_id, tile_id)
    if not tile:
        return error(message='No tile found, please refresh the page')
    new_tile = tile.insert_similar(tile_config)

    repl_res = layouts.replace_tiles({tile: new_tile}, for_layout_id)
    if not repl_res:
        return error('A newer version of the dashboard is available, please refresh the page')
    log.info('Replaced tile %s with tile %s', tile_id, new_tile.tile_id)

    dataseries.update_default_options(new_tile)

    tpcreated_replacement = [[t1.tile_id, t2.tile_id]
                             for (t1, t2) in repl_res.tile_replacement.items()
                             if t2 != new_tile]

    return success(result=dict(new_tile=new_tile,
                               new_layout_id=repl_res.new_layout.layout_id,
                               tpcreated_replacement=tpcreated_replacement))
Ejemplo n.º 3
0
def create_tile():
    dashboard_id = request.get_json()['dashboard_id']
    report_id = request.get_json().get('report_id')
    report_instance_id = request.get_json().get('report_instance_id')
    tile_config = request.get_json()['tile_config']
    moveresize = request.get_json()['moveresize']
    for_layout_id = request.get_json()['for_layout_id']

    check_access(lambda: auth.access_dashboard(dashboard_id))
    check_access(lambda: auth.access_report_instances(report_id))

    if tile_config['tags']:
        tile_config['tile_options']['tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
            tile_config['tags'])

    tile = tiles.Tile.insert(auth.logged_owner_id(), report_id, dashboard_id, tile_config)
    mres = layouts.place_tile(tile, for_layout_id=for_layout_id)
    if not mres:
        return error(message='Could not place the new tile on the dashboard, a page refresh is needed')

    dataseries.update_default_options(tile)

    log.info('Created new tile report_id=%s dashboard_id=%s tile_id=%s', report_id, dashboard_id,
             tile.tile_id)

    tile_html = get_template_attribute('m.html', 'dashboard_tile')\
        (tile.tile_id, mres.new_tiles[tile], moveresize)
    return success(result=dict(
        tile_html=tile_html,
        new_layout_id=mres.new_layout.layout_id,
    ))
Ejemplo n.º 4
0
    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'])
Ejemplo n.º 5
0
    def test_colors(self):
        from mqe.tests import tiles_test

        tile = call(tiles_test.TileTest.test_insert,
                    tile_options_ext={'colors': ['red', 'blue']})
        update_default_options(tile)
        default_options = select_default_series_spec_options(
            tile.report_id, tile.series_specs())
        self.assertEqual([{
            'color': 'red'
        }, {
            'color': 'blue'
        }], default_options)

        tile2 = call(tiles_test.TileTest.test_insert)
        default_options = select_default_series_spec_options(
            tile2.report_id, tile2.series_specs())
        self.assertEqual([{
            'color': 'red'
        }, {
            'color': 'blue'
        }], default_options)

        tile3 = call(tiles_test.TileTest.test_insert,
                     tile_options_ext={'colors': ['pink']})
        update_default_options(tile3)

        default_options = select_default_series_spec_options(
            tile3.report_id, tile3.series_specs())
        self.assertEqual([{
            'color': 'pink'
        }, {
            'color': 'blue'
        }], default_options)

        tile4 = call(tiles_test.TileTest.test_insert)
        update_default_options(tile4)
        default_options = select_default_series_spec_options(
            tile4.report_id, tile4.series_specs())
        self.assertEqual([{
            'color': 'pink'
        }, {
            'color': 'blue'
        }], default_options)
Ejemplo n.º 6
0
def main():
    vars = tutorial.main()
    points_report = vars['points_report']
    owner_id = vars['owner_id']
    owner_dashboards = vars['owner_dashboards']
    dashboard = vars['dashboard']

    SECTION('Tile_config and tile_options')

    from mqe.dataseries import SeriesSpec
    from mqe.tiles import Tile

    tile_config = {
        'series_spec_list': [
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['john']
            }),
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['monique']
            }),
        ],
        'tile_options': {
            'tile_title': 'Points by user',
        }
    }
    tile = Tile.insert(owner_id, points_report.report_id,
                       dashboard.dashboard_id, tile_config)
    pprint(tile.tile_options)

    tile_options2 = tile.tile_options.copy()
    tile_options2['owner_id'] = uuid.uuid4()
    tile2 = Tile.insert_with_tile_options(dashboard.dashboard_id,
                                          tile_options2)

    SECTION('Updating tile\'s config')

    from mqe.layouts import Layout, replace_tiles

    layout = Layout.select(owner_id, dashboard.dashboard_id)
    tile = layout.tile_dict.keys()[0]

    tile_config = tile.get_tile_config()
    tile_config['tile_options']['seconds_back'] = 3600

    repl_tile = tile.insert_similar(tile_config)
    replace_tiles({tile: repl_tile}, for_layout_id=layout.layout_id)

    SECTION('Formatting tile data - tilewidgets and drawers')

    tile_config = {
        'tw_type':
        'Range',
        'series_spec_list': [
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['john']
            }),
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['monique']
            }),
        ],
        'tile_options': {
            'tile_title': 'Points by user',
            'drawer_type': 'ChartRangeDrawer',
            'colors': ['red', 'blue'],
            'seconds_back': 3600,
        }
    }

    SECTION('Updating tile data')

    tile_data = tile.get_tile_data()

    input = """\
    user_name is_active points
    john      true      144
    monique   true      241
    """
    res = points_report.process_input(input)

    last_report_instance_id = tile_data['series_data'][0]['data_points'][
        -1].rid
    new_tile_data = tile.get_new_tile_data(last_report_instance_id)

    SECTION('Managing colors')

    from mqe.dataseries import update_default_options

    tile_config = {
        'series_spec_list': [
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['john']
            }),
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['monique']
            }),
        ],
        'tile_options': {
            'colors': ['blue', 'red'],
        }
    }
    tile = Tile.insert(owner_id, points_report.report_id,
                       dashboard.dashboard_id, tile_config)
    print tile.get_tile_data()['combined_colors']

    update_default_options(tile)

    tile_config_2 = {
        'series_spec_list': [
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['monique']
            }),
        ],
    }
    tile_2 = Tile.insert(owner_id, points_report.report_id,
                         dashboard.dashboard_id, tile_config_2)
    print tile_2.get_tile_data()['combined_colors']

    SECTION('Data series names')

    series_spec = SeriesSpec(2, 0, {'op': 'eq', 'args': ['monique']})
    series_spec.set_name("monique's points")
    tile_config = {'series_spec_list': [series_spec]}
    tile = Tile.insert(owner_id, points_report.report_id,
                       dashboard.dashboard_id, tile_config)
    print tile.get_tile_data()['series_data'][0]['name']

    SECTION('Creating custom tilewidgets and drawers')

    from mqe.tilewidgets import register_drawer_class, Drawer

    @register_drawer_class
    class MaxNumberDrawer(Drawer):

        drawer_type = 'MaxNumberDrawer'

        def process_tile_data(self, tile_data):
            max_number = 0
            for series_data in tile_data['series_data']:
                for point in series_data['data_points']:
                    if int(point.value) > max_number:
                        max_number = int(point.value)

            tile_data['max_number'] = max_number

    tile_config = {
        'series_spec_list': [
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['john']
            }),
            SeriesSpec(2, 0, {
                'op': 'eq',
                'args': ['monique']
            }),
        ],
        'tile_options': {
            'drawer_type': 'MaxNumberDrawer',
        }
    }
    tile = Tile.insert(owner_id, points_report.report_id,
                       dashboard.dashboard_id, tile_config)
    print tile.get_tile_data()['max_number']