def gen_single_page(
    state,
    page_id,
    *,
    inner_only=False,
):
    single_page = page_id
    config = state.config

    remote = state.get_mongo()
    from bson.objectid import ObjectId
    page_id = ObjectId(single_page)
    remote_pages = remote.ndtest.pages.find({'_id': page_id})
    try:
        raw_page = next(remote_pages)
    except StopIteration:
        print("page not found")
        return {'data': 'page not found'}

    series_id = ObjectId(raw_page['series'])
    raw_series = remote.ndtest.series.find({'_id': series_id})
    raw_series = next(raw_series)
    series = Series(raw_series, config)

    root = Page(series=series)
    path = []
    root.add_page(path, raw_page)

    return {'data': root.render(inner_only=inner_only)}
Beispiel #2
0
def Storage(params=None):
    handle_params(params)

    data = []
    with pg_connection(*current_user.get_config()) as (con, cur, err):
        with pg_log_err('list storage query'):
            cur.execute(query('list-storage'))
            data = cur.fetchall()

    display_schemas = params.getlist('schema')
    schemas = set()
    treemap_data = {'name': 'root', 'children': []}
    for (schema_name, table_name, t_size, t_tuples) in data:
        schemas.add(schema_name)
        if schema_name in display_schemas or len(display_schemas) == 0:
            treemap_data['children'].append({'schema_name': schema_name, 'name': table_name,
                                             'size': int(t_size), 'rows': int(t_tuples)})

    p = Page()

    # Header
    p.add_page(Header(title='Storage',
                      js=['static/pages/storage.js',
                          'static/lib/d3/d3.js',
                          'static/lib/d3/lib/colorbrewer/colorbrewer.js'],
                      css=['static/pages/storage.css']))
    p.add_page(Navigation(page='storage'))
    with p.div({'class': 'container-fluid'}):
        with p.div({'class': 'row form-row'}):
            with p.div({'class': 'col-md-10'}):
                with p.form({'id': 'schema-form', 'class': 'form-inline'}):
                    for schema in schemas:
                        with p.label({'class': 'checkbox-inline'}):
                            checked = (schema in display_schemas or len(display_schemas) == 0) and 'checked' or ''
                            with p.input({'type': 'checkbox', 'name': 'schema', 'value': '%s' % schema}, args=[checked]):
                                p.content(schema)

            with p.div({'class': 'col-md-2'}):
                with p.form({'id': 'mode-form', 'class': 'form-inline'}):
                    with p.label({'class': 'radio-inline'}):
                        with p.input({'type': 'radio', 'name': 'mode', 'value': 'size'}, args=['checked']):
                            p.content('Size')
                    with p.label({'class': 'radio-inline'}):
                        with p.input({'type': 'radio', 'name': 'mode', 'value': 'rows'}):
                            p.content('Rows (est.)')

        with p.div({'class': 'row'}):
            with p.div({'class': 'col-md-12'}):
                with p.div({'id': 'treemap-chart'}): pass
                with p.script():
                    p.content('PGUI.STORAGE.mk_treemap_chart(%s);' % json.dumps(treemap_data))

    p.add_page(Footer())

    return p
Beispiel #3
0
def Query(params=None):
    handle_params(params)
    p = Page()

    # Header
    p.add_page(Header(title='Query',
                      js=['static/pages/query.js',
                          'static/pages/query_completion.js',
                          'static/pages/keywords.js',
                          'static/lib/springy/springy.js',
                          'static/lib/springy/springyui.js'],
                      css=['static/pages/query.css']))
    with p.script():
        p.content('PGUI.QUERY.keymap = "%s";' % current_user.keymap)
    p.add_page(Navigation(page='query'))

    with p.div({'class': 'container-fluid'}):
        # Modal dialog for displaying previous queries
        with p.div({'class': 'modal fade', 'id': 'query-history-dialog', 'tabindex': '-1', 'role': 'dialog', 'aria-labelledby': 'Query History'}):
            with p.div({'class': 'modal-dialog', 'role': 'document'}):
                with p.div({'class': 'modal-content'}):
                    with p.div({'class': 'modal-header'}):
                        with p.button({'type': 'button', 'class': 'close', 'data-dismiss': 'modal', 'aria-label': 'Close'}):
                            with p.span({'aria-hidden': 'true'}):
                                p.content('×')
                        with p.h4({'class': 'modal-title', 'id': 'query-history-label'}):
                            p.content('Query history')

                    with p.div({'clas': 'modal-body'}):
                        with p.div({'id': 'query-history'}): pass

        # Tab bar controls
        with p.div({'id': 'query-panel', 'role': 'tabpanel'}):
            with p.ul({'id': 'query-nav-tabs', 'class': 'nav nav-tabs', 'role': 'tablist'}):
                with p.li({'role': 'presentation'}):
                    with p.a({'id': 'show-query-history', 'href': 'javascript:void(0);'}):
                        with p.span({'class': 'add-tab glyphicon glyphicon-camera', 'aria-hidden': 'true'}): pass
                with p.li({'role': 'presentation'}):
                    with p.a({'id': 'add-tab', 'href': 'javascript:void(0);'}):
                        with p.span({'class': 'add-tab glyphicon glyphicon-plus', 'aria-hidden': 'true'}): pass
            # Tab bar contents
            with p.div({'id': 'query-tab-panes', 'class': 'tab-content'}): pass

    # Footer
    p.add_page(Footer())

    return p
Beispiel #4
0
def Storage(params=None):
    handle_params(params)

    data = []
    with pg_connection(*current_user.get_config()) as (con, cur, err):
        with pg_log_err('list storage query'):
            cur.execute(query('list-storage'))
            data = cur.fetchall()

    display_schemas = params.getlist('schema')
    schemas = set()
    treemap_data = {'name': 'root', 'children': []}
    for (schema_name, table_name, t_size, t_tuples) in data:
        schemas.add(schema_name)
        if schema_name in display_schemas or len(display_schemas) == 0:
            treemap_data['children'].append({
                'schema_name': schema_name,
                'name': table_name,
                'size': int(t_size),
                'rows': int(t_tuples)
            })

    p = Page()

    # Header
    p.add_page(
        Header(title='Storage',
               js=[
                   'static/pages/storage.js', 'static/lib/d3/d3.js',
                   'static/lib/d3/lib/colorbrewer/colorbrewer.js'
               ],
               css=['static/pages/storage.css']))
    p.add_page(Navigation(page='storage'))
    with p.div({'class': 'container-fluid'}):
        with p.div({'class': 'row form-row'}):
            with p.div({'class': 'col-md-10'}):
                with p.form({'id': 'schema-form', 'class': 'form-inline'}):
                    for schema in schemas:
                        with p.label({'class': 'checkbox-inline'}):
                            checked = (schema in display_schemas
                                       or len(display_schemas)
                                       == 0) and 'checked' or ''
                            with p.input(
                                {
                                    'type': 'checkbox',
                                    'name': 'schema',
                                    'value': '%s' % schema
                                },
                                    args=[checked]):
                                p.content(schema)

            with p.div({'class': 'col-md-2'}):
                with p.form({'id': 'mode-form', 'class': 'form-inline'}):
                    with p.label({'class': 'radio-inline'}):
                        with p.input(
                            {
                                'type': 'radio',
                                'name': 'mode',
                                'value': 'size'
                            },
                                args=['checked']):
                            p.content('Size')
                    with p.label({'class': 'radio-inline'}):
                        with p.input({
                                'type': 'radio',
                                'name': 'mode',
                                'value': 'rows'
                        }):
                            p.content('Rows (est.)')

        with p.div({'class': 'row'}):
            with p.div({'class': 'col-md-12'}):
                with p.div({'id': 'treemap-chart'}):
                    pass
                with p.script():
                    p.content('PGUI.STORAGE.mk_treemap_chart(%s);' %
                              json.dumps(treemap_data))

    p.add_page(Footer())

    return p
Beispiel #5
0
def Index(params=None):
    """
    Renders the index page which displays some generic connections
    information and links to all the activated modules.
    """
    handle_params(params)
    p = Page()

    # Header
    p.add_page(Header(title='Index'))
    p.add_page(Navigation(page='index'))

    with p.div({'class': 'container-fluid'}):
        # Connection information
        data, params = [], defaultdict(str)
        param_keys = ('server_version', 'server_encoding', 'client_encoding', 'is_superuser', 'TimeZone')
        with pg_connection(*current_user.get_config()) as (con, cur, err):
            for k in param_keys:
                params[k] = con.get_parameter_status(k)
            with pg_log_err('list databases'):
                cur.execute(query('list-databases'))
                data = cur.fetchall()

        with p.div({'class': 'row'}):
            with p.div({'class': 'col-md-2'}):
                with p.div({'class': 'btn-group'}):
                    with p.button({'class': 'btn btn-default dropdown-toggle', 'data-toggle': 'dropdown', 'aria-expanded': 'false'}):
                        p.content('Switch database <span class="caret"></span>')
                    with p.ul({'class': 'dropdown-menu', 'role': 'menu'}):
                        for n, d in enumerate(data):
                            with p.li():
                                with p.a({'href': 'index?database=%s' % d[0]}):
                                    p.content(d[0])
                            if n < len(data) - 1:
                                with p.li({'class': 'divider'}): pass

            with p.div({'class': 'col-md-4 small'}):
                p.content('<strong>%s</strong>' % current_user.database)
                p.content('<br>%s@%s:%s' % (current_user.name, current_user.host, current_user.port))

            with p.div({'class': 'col-md-6 small'}):
                with p.ul({'class': 'list-inline'}):
                    for k, v in sorted(params.items()):
                        with p.li():
                            p.content('%s: %s' % (k, v))

        with p.hr(): pass

        # Modules
        cols = 12
        col_size = 4
        col = 0
        for page in PAGES[1:]:
            if col == 0:
                with p.div({'class': 'row'}, close=False): pass

            with p.div({'class': 'col-md-%s' % col_size}):
                with p.a({'href': '/%s' % page['name']}):
                    with p.div({'class': 'page-link'}):
                        with p.span({'class': 'page-icon glyphicon glyphicon-%s' % page['icon']}): pass
                        with p.h3():
                            p.content(page['caption'])
                        p.content(page['desc'])

            col = (col + col_size) % cols
            if col == 0:
                p.close('div')

    p.add_page(Footer())

    return p
Beispiel #6
0
def Structure(params=None):
    handle_params(params)
    p = Page()

    # Header
    p.add_page(Header(title='Structure',
                      js=['static/pages/structure.js'],
                      css=['static/pages/structure.css']))
    p.add_page(Navigation(page='structure'))

    with p.div({'class': 'container-fluid'}):
        schemas, schema_cols, table_data, table_cols = get_data()

        with p.ul():
            for schema in schemas:
                with p.div({'class': 'panel panel-default'}):
                    with p.div({'class': 'panel-heading'}):
                        with p.div({'class': 'row'}):
                            with p.div({'class': 'col-md-2'}):
                                with p.a({'class': 'btn btn-success btn-xs schema-btn',
                                          'data-toggle': 'collapse',
                                          'href': '#%s' % schema[0],
                                          'aria-expanded': 'false',
                                          'aria-controls': schema[0]}):
                                    p.content('%s - %s' % (schema[0], schema[1]))

                            with p.div({'class': 'col-md-10'}):
                                with p.ul({'class': 'list-inline'}):
                                    for i, col in enumerate(schema_cols, 2):
                                        with p.li():
                                            p.content('<strong>%s</strong> %s' % (schema[i], col))

                    with p.div({'class': 'panel-body'}):
                        with p.div({'class': 'row collapse', 'id': schema[0]}):
                            with p.div({'class': 'col-md-2'}):
                                with p.div({'class': 'well'}):
                                    with p.b():
                                        p.content('Tables')

                                    with p.ul():
                                        for table in table_data[schema[0]]:
                                            with p.li():
                                                with p.a({'href': '#', 'onclick': 'PGUI.STRUCTURE.show_table_details(\'%s\', \'%s\'); return false;' % (schema[0], table)}):
                                                    p.content(table)

                            with p.div({'class': 'col-md-10'}):
                                for table in table_data[schema[0]]:
                                    with p.div({'id': 'table-details-%s-%s' % (schema[0], table), 'class': 'table-details table-details-%s' % schema[0]}):
                                        data = table_data[schema[0]][table]
                                        with p.p():
                                            p.content('Table size: ')
                                            with p.b():
                                                p.content(data['table-size'])

                                        with p.table({'class': 'table table-condensed'}):
                                            with p.tr():
                                                for tc in table_cols:
                                                    with p.th():
                                                        p.content(tc)
                                                with p.th({'id': 'col-size-header-%s-%s' % (schema[0], table)}):
                                                    with p.a({'href': '#',
                                                              'onclick': 'PGUI.STRUCTURE.get_col_size(\'%s\', \'%s\'); return false;' % (schema[0], table)}):
                                                        p.content('Get column sizes')

                                            for row in zip(*data['column-data'].values()):
                                                with p.tr():
                                                    for col in row:
                                                        with p.td():
                                                            p.content(col)
                                                    with p.td({'id': 'col-size-%s-%s-%s' % (schema[0], table, row[0])}):
                                                        pass

    p.add_page(Footer())

    return p
Beispiel #7
0
def Index(params=None):
    """
    Renders the index page which displays some generic connections
    information and links to all the activated modules.
    """
    handle_params(params)
    p = Page()

    # Header
    p.add_page(Header(title='Index'))
    p.add_page(Navigation(page='index'))

    with p.div({'class': 'container-fluid'}):
        # Connection information
        data, params = [], defaultdict(str)
        param_keys = ('server_version', 'server_encoding', 'client_encoding',
                      'is_superuser', 'TimeZone')
        with pg_connection(*current_user.get_config()) as (con, cur, err):
            for k in param_keys:
                params[k] = con.get_parameter_status(k)
            with pg_log_err('list databases'):
                cur.execute(query('list-databases'))
                data = cur.fetchall()

        with p.div({'class': 'row'}):
            with p.div({'class': 'col-md-2'}):
                with p.div({'class': 'btn-group'}):
                    with p.button({
                            'class': 'btn btn-default dropdown-toggle',
                            'data-toggle': 'dropdown',
                            'aria-expanded': 'false'
                    }):
                        p.content(
                            'Switch database <span class="caret"></span>')
                    with p.ul({'class': 'dropdown-menu', 'role': 'menu'}):
                        for n, d in enumerate(data):
                            with p.li():
                                with p.a({'href': 'index?database=%s' % d[0]}):
                                    p.content(d[0])
                            if n < len(data) - 1:
                                with p.li({'class': 'divider'}):
                                    pass

            with p.div({'class': 'col-md-4 small'}):
                p.content('<strong>%s</strong>' % current_user.database)
                p.content(
                    '<br>%s@%s:%s' %
                    (current_user.name, current_user.host, current_user.port))

            with p.div({'class': 'col-md-6 small'}):
                with p.ul({'class': 'list-inline'}):
                    for k, v in sorted(params.items()):
                        with p.li():
                            p.content('%s: %s' % (k, v))

        with p.hr():
            pass

        # Modules
        cols = 12
        col_size = 4
        col = 0
        for page in PAGES[1:]:
            if col == 0:
                with p.div({'class': 'row'}, close=False):
                    pass

            with p.div({'class': 'col-md-%s' % col_size}):
                with p.a({'href': '/%s' % page['name']}):
                    with p.div({'class': 'page-link'}):
                        with p.span({
                                'class':
                                'page-icon glyphicon glyphicon-%s' %
                                page['icon']
                        }):
                            pass
                        with p.h3():
                            p.content(page['caption'])
                        p.content(page['desc'])

            col = (col + col_size) % cols
            if col == 0:
                p.close('div')

    p.add_page(Footer())

    return p
Beispiel #8
0
        st.write(emotion)
        response = requests.get(
            "https://api.giphy.com/v1/gifs/random?api_key=u5zI8PiTKx0y7b6Csh5GmUdhgD0hZ315&tag={}&rating=g"
            .format(emotion))
        image_url = response.json()["data"]["image_original_url"]
        st.image(image_url)


###
# MAIN
###
st.sidebar.markdown("### 🤖 Emotions Detector")
start_time = time.time()
kaggle, dataworld = load_data()
app = Page()
app.add_page("Data Analyse", page_data)
app.add_page("Detector", page_search)
app.add_page("TabNet", make_tabnet)
app.add_page("FastText", make_ft)
app.add_page("Linear Support Vector", make_svc)
app.add_page("Naive Bayes", make_nb)
app.add_page("Logistic Regression", make_log)
# app.add_page("KNN", make_knn)
app.add_page("Random Forest", make_rf)

current_dataset_name = st.sidebar.radio('Data', ("Dataworld", "Kaggle"))
if current_dataset_name == "Kaggle":
    current_dataset = kaggle
else:
    current_dataset = dataworld
app.run()
Beispiel #9
0
def Query(params=None):
    handle_params(params)
    p = Page()

    # Header
    p.add_page(
        Header(title='Query',
               js=[
                   'static/pages/query.js', 'static/pages/query_completion.js',
                   'static/pages/keywords.js', 'static/lib/springy/springy.js',
                   'static/lib/springy/springyui.js'
               ],
               css=['static/pages/query.css']))
    with p.script():
        p.content('PGUI.QUERY.keymap = "%s";' % current_user.keymap)
    p.add_page(Navigation(page='query'))

    with p.div({'class': 'container-fluid'}):
        # Modal dialog for displaying previous queries
        with p.div({
                'class': 'modal fade',
                'id': 'query-history-dialog',
                'tabindex': '-1',
                'role': 'dialog',
                'aria-labelledby': 'Query History'
        }):
            with p.div({'class': 'modal-dialog', 'role': 'document'}):
                with p.div({'class': 'modal-content'}):
                    with p.div({'class': 'modal-header'}):
                        with p.button({
                                'type': 'button',
                                'class': 'close',
                                'data-dismiss': 'modal',
                                'aria-label': 'Close'
                        }):
                            with p.span({'aria-hidden': 'true'}):
                                p.content('&times;')
                        with p.h4({
                                'class': 'modal-title',
                                'id': 'query-history-label'
                        }):
                            p.content('Query history')

                    with p.div({'clas': 'modal-body'}):
                        with p.div({'id': 'query-history'}):
                            pass

        # Tab bar controls
        with p.div({'id': 'query-panel', 'role': 'tabpanel'}):
            with p.ul({
                    'id': 'query-nav-tabs',
                    'class': 'nav nav-tabs',
                    'role': 'tablist'
            }):
                with p.li({'role': 'presentation'}):
                    with p.a({
                            'id': 'show-query-history',
                            'href': 'javascript:void(0);'
                    }):
                        with p.span({
                                'class': 'add-tab glyphicon glyphicon-camera',
                                'aria-hidden': 'true'
                        }):
                            pass
                with p.li({'role': 'presentation'}):
                    with p.a({'id': 'add-tab', 'href': 'javascript:void(0);'}):
                        with p.span({
                                'class': 'add-tab glyphicon glyphicon-plus',
                                'aria-hidden': 'true'
                        }):
                            pass
            # Tab bar contents
            with p.div({'id': 'query-tab-panes', 'class': 'tab-content'}):
                pass

    # Footer
    p.add_page(Footer())

    return p
def retrieve_pages(state, series_list, present_series={}):
    config = state.config
    remote = state.get_mongo()

    return_series = series_list

    series_ids = [s.id for s in return_series]
    page_query = {
        'series': {
            '$in': series_ids
        },
    }
    if config['min-status'] is not None:
        page_query['meta.status'] = {'$gte': config['min-status']}

    series_uuids = {s.id: s.uuid for s in series_list}

    remote_uuids = remote.ndtest.pages.find(page_query, {
        'series': 1,
        'uuid': 1,
        '_id': 0
    })
    remote_uuids = sorted(remote_uuids, key=lambda x: x.get('series') or "")

    uuid_hashes = {}
    for series_id, pages in groupby(remote_uuids, lambda x: x.get('series')):
        m = hashlib.sha256()
        m.update(series_uuids.get(series_id, '').encode())
        for uuid in (p.get('uuid') for p in pages):
            if not uuid:
                uuid = "8"
            m.update(uuid.encode())
        uuid_hashes[series_id] = m.hexdigest()

    needed_series = [
        s for s in return_series if s.id not in present_series
        or uuid_hashes[s.id] != present_series[s.id]
    ]

    page_query = {
        **page_query,  # include meta.status part of the query
        'series': {
            '$in': [s.id for s in needed_series]
        },
    }

    if not needed_series:
        remote_pages = []
    else:
        remote_pages = remote.ndtest.pages.find(page_query)
    remote_pages = list(remote_pages)

    blog_pages = [p for p in remote_pages if p['meta'].get('blog')]
    blog_pages = [p for p in blog_pages if not p['meta'].get('deleted')]

    remote_pages = [p for p in remote_pages if not p['meta'].get('deleted')]
    remote_pages = [p for p in remote_pages if not p['meta'].get('blog')]

    all_pages = {}

    for series in needed_series:
        hier = series.hier
        series_id = series.id
        pages = [p for p in remote_pages if p['series'] == series_id]
        series_blog_pages = [p for p in blog_pages if p['series'] == series_id]

        root = Page(series=series)
        all_pages[series.id] = root

        for page in pages:
            path = [page.get('meta', {}).get(h) for h in hier]
            path = [p for p in path if p not in [None, '', 0]]
            path = [0 if p == '_0' else p for p in path]
            path = [try_int(p, p) for p in path]

            path_postfix = page['meta'].get('path')
            if path_postfix:
                path.append(path_postfix)

            root.add_page(path, page)

        if series.blog_path is not None:
            for path, page in blog.process_blog_posts(series_blog_pages,
                                                      series):
                if path == []:
                    for child in root:
                        child.change_root(page)
                    page.children = root.children
                    root = page
                    all_pages[series.id] = root
                else:
                    root.add_page_obj(path, page)

    return all_pages, return_series, uuid_hashes