コード例 #1
0
def make_master_from_tpcreated(old_master, tpcreated):
    """Based on an old master |Tile| ``old_master``, creates a new master |Tile| from
    ``tpcreated`` |Tile| which must be a |Tile| tpcreated from ``old_master``."""
    assert old_master.is_master_tile()
    assert not tpcreated.is_master_tile()

    new_master_to = copy.deepcopy(tpcreated.tile_options)
    new_master_to['tpcreator_uispec'] = old_master.tile_options[
        'tpcreator_uispec']
    del new_master_to['tpcreator_data']

    if new_master_to.get('tile_title'):
        postfix = tpcreated.tilewidget.generate_tile_title_postfix()
        if postfix and postfix in new_master_to['tile_title']:
            new_master_to['tile_title'].replace(postfix, '').strip()

    old_master_title = old_master.tile_options.get('tile_title')
    if old_master_title and not new_master_to.get('tile_title'):
        # strip old postfix
        old_postfix = old_master.tilewidget.generate_tile_title_postfix()
        if old_postfix in old_master_title:
            new_postfix = tpcreated.tilewidget.generate_tile_title_postfix()
            old_master_title = old_master_title.replace(
                old_postfix, new_postfix)
        new_master_to['tile_title'] = old_master_title

    return Tile.insert_with_tile_options(old_master.dashboard_id,
                                         new_master_to)
コード例 #2
0
ファイル: tpcreator.py プロジェクト: goryszewskig/monique
def handle_tpcreator_row(row, report_instance):
    log.debug('Processing row %s', row)

    layout = layouts.Layout.select(row['owner_id'], row['dashboard_id'])
    if not layout:
        log.warn('No layout')
        return True

    layout_id = layout.layout_id

    tpcreator_spec_by_master_id, tpcreated_tags_by_master_id = _get_tpcreator_data(layout, row['report_id'])
    log.debug('tpcreator data: %s, %s', tpcreator_spec_by_master_id, tpcreated_tags_by_master_id)

    if not tpcreator_spec_by_master_id:
        log.info('Deleting obsoleted layout_by_report tpcreator row')
        c.dao.LayoutDAO.delete_layout_by_report(row['owner_id'], row['report_id'], row['tags'],
                                                row['label'], row['dashboard_id'], row['layout_id'])
        return True

    for master_id, tpcreator_spec in tpcreator_spec_by_master_id.items():
        log.debug('Processing master_id=%s tpcreator_spec=%s', master_id, tpcreator_spec)
        tpcreated_tags = tpcreated_tags_by_master_id[master_id]
        if len(tpcreated_tags) >= mqeconfig.MAX_TPCREATED:
            log.warn('Too many tpcreated for master_id=%s', master_id)
            continue

        matching_tags = tags_matching_tpcreator_spec(tpcreator_spec, report_instance.all_tags)
        if not matching_tags:
            log.debug('No tags match the tpcreator_spec')
            continue
        if tuple(matching_tags) in tpcreated_tags:
            log.debug('A tpcreated tile already exists for the matched tags %s', matching_tags)
            continue

        master_tile = Tile.select(row['dashboard_id'], master_id)
        if not master_tile:
            log.warn('No master_tile')
            continue

        new_tile_options = _tile_options_of_tpcreated(master_tile, tpcreator_spec, matching_tags)
        new_tile = Tile.insert_with_tile_options(master_tile.dashboard_id, new_tile_options)
        log.info('tpcreator created new tile with tags %s for report_id=%s', matching_tags,
                 row['report_id'])
        mres = layouts.place_tile(new_tile, size_of=master_tile.tile_id,
                                  for_layout_id=layout_id)
        if not mres:
            log.debug('Placing new tile failed')
            return False

        fire_signal(layout_modified,
                    reason='tpcreator',
                    layout_modification_result=mres)

        layout_id = mres.new_layout.layout_id

    return True
コード例 #3
0
ファイル: tpcreator.py プロジェクト: goryszewskig/monique
def make_master_from_tpcreated(old_master, tpcreated):
    """Based on an old master |Tile| ``old_master``, creates a new master |Tile| from
    ``tpcreated`` |Tile| which must be a |Tile| tpcreated from ``old_master``."""
    assert old_master.is_master_tile()
    assert not tpcreated.is_master_tile()

    new_master_tile_options = copy.deepcopy(tpcreated.tile_options)
    new_master_tile_options['tpcreator_uispec'] = old_master.tile_options['tpcreator_uispec']
    del new_master_tile_options['tpcreator_data']

    return Tile.insert_with_tile_options(old_master.dashboard_id, new_master_tile_options)
コード例 #4
0
def make_tpcreated_from_master(old_master, new_master):
    """Downgrades the master |Tile| ``old_master`` to a tpcreated tile of the
    |Tile| ``new_master``.
    """
    assert old_master.is_master_tile()
    assert new_master.is_master_tile()

    tpcreator_spec = tpcreator_spec_from_tpcreator_uispec(
        new_master.tile_options['tpcreator_uispec'])
    to = _tile_options_of_tpcreated(new_master, tpcreator_spec, old_master.tags, old_master)
    return Tile.insert_with_tile_options(old_master.dashboard_id, to)
コード例 #5
0
    def do_tpcreator_mod(layout_mod):
        tpcreator_spec_by_master_id, tpcreated_tags_by_master_id = _get_tpcreator_data(
            layout_mod, report_instance.report_id)
        log.debug('tpcreator data: %s, %s', tpcreator_spec_by_master_id,
                  tpcreated_tags_by_master_id)

        if not tpcreator_spec_by_master_id:
            log.info('Deleting obsoleted layout_by_report tpcreator row')
            c.dao.LayoutDAO.delete_layout_by_report(layout_row['owner_id'],
                                                    layout_row['report_id'],
                                                    layout_row['tags'],
                                                    layout_row['label'],
                                                    layout_row['dashboard_id'],
                                                    layout_row['layout_id'])
            return

        for master_id, tpcreator_spec in tpcreator_spec_by_master_id.items():
            log.debug('Processing master_id=%s tpcreator_spec=%s', master_id,
                      tpcreator_spec)
            tpcreated_tags = tpcreated_tags_by_master_id[master_id]
            if len(tpcreated_tags) >= max_tpcreated:
                log.warn('Too many tpcreated for master_id=%s: %s', master_id,
                         len(tpcreated_tags))
                continue

            matching_tags = tags_matching_tpcreator_spec(
                tpcreator_spec, report_instance.all_tags)
            if not matching_tags:
                log.debug('No tags match the tpcreator_spec')
                continue
            if tuple(matching_tags) in tpcreated_tags:
                log.debug(
                    'A tpcreated tile already exists for the matched tags %s',
                    matching_tags)
                continue

            master_tile = Tile.select(layout_row['dashboard_id'], master_id)
            if not master_tile:
                log.warn('No master_tile')
                continue

            new_tile_options = _tile_options_of_tpcreated(
                master_tile, tpcreator_spec, matching_tags)
            new_tile = Tile.insert_with_tile_options(master_tile.dashboard_id,
                                                     new_tile_options)
            log.info(
                'tpcreator created new tile with tags %s for report_id=%s',
                matching_tags, layout_row['report_id'])
            layouts.place_tile_mod(new_tile,
                                   size_of=master_tile.tile_id)(layout_mod)
コード例 #6
0
ファイル: tilewidgets.py プロジェクト: ighori/monique
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']