Ejemplo n.º 1
0
def index_page() -> response.Response:
    """Renders the overview page"""
    from ..config import data_sets

    return response.Response(html=[
        bootstrap.card(header_left='Entities & their relations',
                       body=html.asynchronous_content(
                           flask.url_for('mara_schema.overview_graph'))),
        bootstrap.card(
            header_left='Data sets',
            body=bootstrap.table(['Name', 'Description'], [
                _.tr[_.td[_.a(
                    href=flask.
                    url_for('mara_schema.data_set_page', id=data_set.id()
                            ))[escape(data_set.name)]],
                     _.td[_.i[escape(data_set.entity.description)]], ]
                for data_set in data_sets()
            ]),
        )
    ],
                             title='Data sets documentation',
                             css_files=[
                                 flask.url_for('mara_schema.static',
                                               filename='schema.css')
                             ])
Ejemplo n.º 2
0
def __(task: pipelines.ParallelTask):
    if not acl.current_user_has_permission(views.acl_resource):
        return bootstrap.card(
            header_left=acl.inline_permission_denied_message())
    else:
        return [
            bootstrap.card(header_left='Commands before',
                           fixed_header_height=True,
                           sections=[
                               _render_command(command)
                               for command in task.commands_before
                           ]) if task.commands_before else '',
            bootstrap.card(header_left='Sub task creation',
                           body=bootstrap.table([], [
                               _.tr[_.td[_.div[section]],
                                    _.td(style='width:90%')[content]]
                               for section, content in task.html_doc_items()
                           ])),
            bootstrap.card(header_left='Commands after',
                           fixed_header_height=True,
                           sections=[
                               _render_command(command)
                               for command in task.commands_after
                           ]) if task.commands_after else ''
        ]
Ejemplo n.º 3
0
def __(task: pipelines.Task):
    if not acl.current_user_has_permission(views.acl_resource):
        return bootstrap.card(header_left='Commands', body=acl.inline_permission_denied_message())
    else:
        return bootstrap.card(
            header_left='Commands',
            fixed_header_height=True,
            sections=[_render_command(command) for command in task.commands])
Ejemplo n.º 4
0
def configuration_page():
    config = get_config_for_display()
    current_user_has_permission = acl.current_user_has_permission(acl_resource)

    return response.Response(html=[(bootstrap.card(
        id=module_name,
        header_left=html.escape(module_name),
        body=[
            _.p[_.em[html.escape(str(module_content.doc))]],
            bootstrap.table([], [
                _.tr[_.td[
                    _.tt[html.escape(config_name).replace('_', '_<wbr/>')], [
                        _.br, ' ⟵ ', _.
                        tt[html.escape(config_function.func_desc).
                           replace('.', '<wbr/>.').replace('_', '_<wbr/>')]
                    ] if config_function.set_func else ''],
                     _.td[_.em[html.escape(config_function.doc)]], _.
                     td[_.pre[html.
                              escape(str(config_function)
                                     )] if current_user_has_permission else acl
                        .inline_permission_denied_message()]]
                for config_name, config_function in module_content.items()
            ])
        ]) if module_content.config_functions else '') for module_name,
                                   module_content in config.items()],
                             title='Mara Configuration')
Ejemplo n.º 5
0
def card(node: pipelines.Node) -> str:
    """A card that shows the system stats, the time line and output for the last runs or a node"""
    return bootstrap.card(
        id='last-runs-card',
        header_left=[
            'Last runs ',
            _.div(style='display:inline-block;margin-left:20px;')[
                html.asynchronous_content(
                    flask.url_for('mara_pipelines.last_runs_selector',
                                  path=node.url_path()))]
        ],
        body=[
            html.spinner_js_function(),
            html.asynchronous_content(url=flask.url_for(
                'mara_pipelines.system_stats',
                path=node.url_path(),
                run_id=None),
                                      div_id='system-stats'),
            html.asynchronous_content(url=flask.url_for(
                'mara_pipelines.timeline_chart',
                path=node.url_path(),
                run_id=None),
                                      div_id='timeline-chart'),
            html.asynchronous_content(url=flask.url_for(
                'mara_pipelines.run_output',
                path=node.url_path(),
                run_id=None,
                limit=True),
                                      div_id='run-output')
        ])
Ejemplo n.º 6
0
def __(pipeline: pipelines.Pipeline):
    return bootstrap.card(
        header_left='Nodes',
        header_right=[
            bootstrap.button(
                id='run-with-upstreams-button',
                label='Run with upstreams',
                icon='play',
                url=flask.url_for('data_integration.run_page',
                                  path=pipeline.url_path(),
                                  with_upstreams=True),
                title=
                f'Run selected nodes with all their upstreams in pipeline "{pipeline.id}"'
            ), '&nbsp;&nbsp;&nbsp;&nbsp;',
            bootstrap.button(id='run-button',
                             label='Run ',
                             icon='play',
                             url=flask.url_for('data_integration.run_page',
                                               path=pipeline.url_path(),
                                               with_upstreams=False),
                             title='Run selected nodes')
        ] if config.allow_run_from_web_ui() else [],
        body=html.asynchronous_content(
            url=flask.url_for('data_integration.pipeline_children_table',
                              path=pipeline.url_path())))
Ejemplo n.º 7
0
def configuration_page():
    import pprint
    from . import app

    # gather all config functions by package

    current_user_has_permission = acl.current_user_has_permission(acl_resource)

    return response.Response(html=[(bootstrap.card(
        id=module_name,
        header_left=html.escape(module_name),
        body=[
            _.p[_.em[html.escape(str(config['doc']))]],
            bootstrap.table([], [
                _.tr[_.td[
                    _.tt[html.escape(function_name).replace('_', '_<wbr/>')], [
                        _.br, ' ⟵ ', _.
                        tt[html.escape(function['new_function']).
                           replace('.', '<wbr/>.').replace('_', '_<wbr/>')]
                    ] if function['new_function'] else ''],
                     _.td[_.em[html.escape(function['doc'])]], _.
                     td[_.pre[html.
                              escape(pprint.pformat(function['value'])
                                     )] if current_user_has_permission else acl
                        .inline_permission_denied_message()]]
                for function_name, function in config['functions'].items()
            ])
        ]) if config['functions'] else '') for module_name, config in sorted(
            _config_modules().items())],
                             title='Mara Configuration')
Ejemplo n.º 8
0
def configuration_page():
    config_modules = {}
    for configs in get_get_current_config():
        api_name, func = configs
        module_name = func.__module__
        module = sys.modules[module_name]
        if module_name not in config_modules:
            config_modules[module_name] = {
                'doc': module.__doc__,
                'functions': {}
            }
        try:
            value = func()
        except Exception:
            value = 'error calling function'
        config_modules[module_name]['functions'][api_name] \
            = {'doc': func.__doc__ or '', 'value': value}

    return response.Response(html=[(bootstrap.card(
        title_left=_.b[html.escape(module_name)],
        body=[
            _.p[html.escape(str(config['doc']))],
            bootstrap.table([], [
                _.tr[_.td[function_name.replace('_', '_<wbr/>')],
                     _.td[_.em[function['doc']]], _.
                     td[_.pre[html.escape(pprint.pformat(function['value']))]]]
                for function_name, function in config['functions'].items()
            ])
        ]) if config['functions'] else '') for module_name, config in sorted(
            config_modules.items())],
                             title='Mara Configuration')
Ejemplo n.º 9
0
def document(doc_id, folder_id=""):
    docs = all_docs()
    if folder_id:
        full_doc_id = folder_id + '/' + doc_id
    else:
        full_doc_id = doc_id
    if full_doc_id not in docs:
        raise flask.abort(404, f"Documentation {doc_id} is not known.")
    doc = docs[full_doc_id]
    if not doc.path.exists():
        raise flask.abort(404, f"Documentation {doc_id} is not found ({doc.path}).")
    with doc.path.open() as f:
        md_content = f.read()
        md_escaped = flask.escape(md_content)
        return response.Response(
            title=f'Doc "{doc.full_name}"',
            html=[bootstrap.card(
                body=[
                    _.div(style="display:none")[_.pre(id_='markdown-source')[md_escaped]],
                    _.div(id_='markdown-rendered-content')[
                        _.span(class_='fa fa-spinner fa-spin')[' ']
                    ],
                ]),
                _.script(type="text/javascript")[__render_code],
            ],
            js_files=[
                'https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.7.0/mermaid.min.js',
                'https://cdnjs.cloudflare.com/ajax/libs/markdown-it/11.0.0/markdown-it.min.js',
                'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/highlight.min.js',
                flask.url_for('docs.static', filename='markdown-it-naive-mermaid.js'),
            ],
            css_files=[
                'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.2/styles/default.min.css',
            ]
        )
Ejemplo n.º 10
0
def card(node: pipelines.Pipeline):
    return bootstrap.card(body=[
        _.p[_.em[node.description]],
        (_.p[views.format_labels(node)] if node.labels else ''),
        html.asynchronous_content(
            flask.url_for('data_integration.dependency_graph',
                          path=node.url_path()))
    ])
Ejemplo n.º 11
0
def index_page():
    return response.Response(
        html=[bootstrap.card(
            header_left=_.a(href=flask.url_for('mara_data_explorer.data_set_page', data_set_id=ds.id))[ds.name],
            body=[html.asynchronous_content(flask.url_for('mara_data_explorer.data_set_preview', data_set_id=ds.id))])
            for i, ds in enumerate(config.data_sets())],
        title='Data sets',
        js_files=[flask.url_for('mara_data_explorer.static', filename='data-sets.js')],
        css_files=[flask.url_for('mara_data_explorer.static', filename='data-sets.css')])
Ejemplo n.º 12
0
def start_page():
    links = []
    for full_doc_id, doc in all_docs().items():
        folder_id, doc_id = doc.ids
        links.append(_.li[_.a(href=flask.url_for('docs.document', doc_id=doc_id, folder_id=folder_id))[doc.full_name]])

    return response.Response(title='Docs', html=[
        bootstrap.card(header_left='Table of Content', body=[_.ul[links]])
    ])
Ejemplo n.º 13
0
 def error_handler(error):
     if not isinstance(error, exceptions.HTTPException):
         error = exceptions.InternalServerError()
     return response.Response(bootstrap.card(body=_.span[
         _.p(style='color:#888')[error.description or ''],
         _.img(src=flask.url_for('mara_app.static', filename='mara.jpg'
                                 ),
               style='margin-top:30px;max-width:100%;')]),
                              title=f'{error.code}  {error.name}',
                              status=error.code)
Ejemplo n.º 14
0
def index_page():
    """Overview page of mara_db"""
    return response.Response(
        title=f'Database schemas',
        html=bootstrap.card(body=[
            _.div(
                style=
                'display:inline-block; margin-top:15px; margin-bottom:15px; margin-right:50px;'
            )[_.a(href=flask.url_for('mara_db.schema_page', db_alias=db_alias)
                  )[_.span(class_='fa fa-database')[''], ' ', db_alias], _.br,
              _.span(style='color:#888')[escape(str(type(db).__name__))]]
            for db_alias, db in config.databases().items()
        ]),
        js_files=[flask.url_for('mara_db.static', filename='schema-page.js')])
Ejemplo n.º 15
0
def index_page(db_alias: str):
    """A page that visiualizes the schemas of a database"""
    if db_alias not in config.databases():
        flask.abort(404, f'unkown database {db_alias}')

    return response.Response(
        title=f'Schema of database {db_alias}',
        html=[bootstrap.card(sections=[
            html.asynchronous_content(flask.url_for('mara_db.schema_selection', db_alias=db_alias)),
            [_.div(id='schema-container')]]),
            html.spinner_js_function()],
        js_files=[flask.url_for('mara_db.static', filename='schema-page.js')],
        action_buttons=[response.ActionButton(
            action='javascript:schemaPage.downloadSvg()', label='SVG',
            title='Save current chart as SVG file', icon='download')]
    )
Ejemplo n.º 16
0
def data_set_page(data_set_id, query_id):
    from .data_set import find_data_set
    ds = find_data_set(data_set_id)
    if not ds:
        flask.flash(f'Data set "{data_set_id}" does not exist anymore', category='danger')
        return flask.redirect(flask.url_for('mara_data_explorer.index_page'))

    action_buttons = []

    action_buttons.append(response.ActionButton(action='javascript:dataSetPage.downloadCSV()',
                                                icon='download',
                                                label='CSV', title='Download as CSV'))
    if config.google_sheet_oauth2_client_config():
        action_buttons.append(response.ActionButton(action='javascript:dataSetPage.exportToGoogleSheet()',
                                                    icon='cloud-upload',
                                                    label='Google sheet', title='Export to a Google sheet'))
    action_buttons.append(response.ActionButton(action='javascript:dataSetPage.load()',
                                                icon='folder-open',
                                                label='Load', title='Load previously saved query'))
    action_buttons.append(response.ActionButton(action='javascript:dataSetPage.save()',
                                                icon='save',
                                                label='Save', title='Save query'))
    action_buttons.append(response.ActionButton(action='javascript:dataSetPage.displayQuery()',
                                                icon='eye',
                                                label='SQL', title='Display query'))

    if query_id:
        action_buttons.insert(1, response.ActionButton(
            action=flask.url_for('mara_data_explorer._delete_query', data_set_id=data_set_id, query_id=query_id),
            icon='trash', label='Delete', title='Delete query'))

    return response.Response(
        title=f'Query "{query_id}" on "{ds.name}"' if query_id else f'New query on "{ds.name}"',
        html=[_.div(class_='row')[
                  _.div(class_='col-md-3')[
                      bootstrap.card(header_left='Query', body=_.div(id='query-details')[html.spinner()]),
                      bootstrap.card(header_left='Columns',
                                     header_right=_.a(id='select-all', href='#')[' Select all'],
                                     body=[_.div(class_="form-group")[
                                               _.input(type="search", class_="columns-search form-control",
                                                       value="", placeholder="Filter")],
                                           _.div(id='columns-list')[html.spinner()]])],
                  _.div(class_='col-md-9')[
                      bootstrap.card(
                          id='filter-card',
                          header_left=[_.div(class_="dropdown")[
                                           _.a(**{'class': 'dropdown-toggle', 'data-toggle': 'dropdown', 'href': '#'})[
                                               _.span(class_='fa fa-plus')[' '], ' Add filter'],
                                           _.div(class_="dropdown-menu", id='filter-menu')[
                                               _.div(class_="dropdown-item")[
                                                   _.input(type="text", class_="columns-search form-control", value="",
                                                           placeholder="Filter")]]]],
                          fixed_header_height=False,
                          body=_.div(id='filters')[html.spinner()]),
                      bootstrap.card(header_left=_.div(id='row-counts')[html.spinner()],
                                     header_right=_.div(id='pagination')[html.spinner()],
                                     body=_.div(id='preview')[html.spinner()]),
                      _.div(class_='row', id='distribution-charts')['']
                  ]], _.script[f"""
var dataSetPage = null;                  
document.addEventListener('DOMContentLoaded', function() {{
    dataSetPage = DataSetPage('{flask.url_for('mara_data_explorer.index_page')}', 
                              {json.dumps(
            {'data_set_id': data_set_id, 'query_id': query_id, 'query': flask.request.get_json()})},
                              15, '{config.charts_color()}');
}});
            """],
              html.spinner_js_function(),
              _.div(class_='col-xl-4 col-lg-6', id='distribution-chart-template', style='display: none')[
                  bootstrap.card(header_left=html.spinner(), body=_.div(class_='chart-container google-chart')[
                      html.spinner()])],
              _.div(class_='modal fade', id='load-query-dialog', tabindex="-1")[
                  _.div(class_='modal-dialog', role='document')[
                      _.div(class_='modal-content')[
                          _.div(class_='modal-header')[
                              _.h5(class_='modal-title')['Load query'],
                              _.button(**{'type': "button", 'class': "close", 'data-dismiss': "modal",
                                          'aria-label': "Close"})[
                                  _.span(**{'aria-hidden': 'true'})['&times']]],
                          _.div(class_='modal-body', id='query-list')['']
                      ]
                  ]
              ],
              _.div(class_='modal fade', id='display-query-dialog', tabindex="-1")[
                  _.div(class_='modal-dialog', role='document')[
                      _.div(class_='modal-content')[
                          _.div(class_='modal-header')[
                              _.h5(class_='modal-title')['Query statement'],
                              _.button(**{'type': "button", 'class': "close", 'data-dismiss': "modal",
                                          'aria-label': "Close"})[
                                  _.span(**{'aria-hidden': 'true'})['&times']]],
                          _.div(class_='modal-body', id='query-display')['']
                      ]
                  ]
              ],
              _.form(action=flask.url_for('mara_data_explorer.download_csv', data_set_id=data_set_id), method='post')[
                  _.div(class_="modal fade", id="download-csv-dialog", tabindex="-1")[
                      _.div(class_="modal-dialog", role='document')[
                          _.div(class_="modal-content")[
                              _.div(class_="modal-header")[
                                  _.h5(class_='modal-title')['Download as CSV'],
                                  _.button(**{'type': "button", 'class': "close", 'data-dismiss': "modal",
                                              'aria-label': "Close"})[
                                      _.span(**{'aria-hidden': 'true'})['&times']]],
                              _.div(class_="modal-body")[
                                  'Delimiter: &nbsp',
                                  _.input(type="radio", value="\t", name="delimiter",
                                          checked="checked"), ' tab &nbsp&nbsp',

                                  _.input(type="radio", value=";", name="delimiter"), ' semicolon &nbsp&nbsp',
                                  _.input(type="radio", value=",", name="delimiter"), ' comma &nbsp&nbsp',
                                  _.hr,
                                  'Number format: &nbsp',
                                  _.input(type="radio", value=".", name="decimal-mark",
                                          checked="checked"), ' 42.7 &nbsp&nbsp',
                                  _.input(type="radio", value=",", name="decimal-mark"), ' 42,7 &nbsp&nbsp',
                                  _.input(type="hidden", name="query")],
                              _.div(class_="modal-footer")[
                                  _.button(id="csv-download-button", type="submit", class_="btn btn-primary")[
                                      'Download']]]]]],

              _.form(action=flask.url_for('mara_data_explorer.oauth2_export_to_google_sheet', data_set_id=data_set_id),
                     method='post',
                     target="_blank")[
                  _.div(class_="modal fade", id="google-sheet-export-dialog", tabindex="-1")[
                      _.div(class_="modal-dialog", role='document')[
                          _.div(class_="modal-content")[
                              _.div(class_="modal-header")[
                                  _.h5(class_='modal-title')['Google sheet export'],
                                  _.button(**{'type': "button", 'class': "close", 'data-dismiss': "modal",
                                              'aria-label': "Close"})[
                                      _.span(**{'aria-hidden': 'true'})['&times']]],
                              _.div(class_="modal-body")[
                                  'Number format: &nbsp',
                                  _.input(type="radio", value=".", name="decimal-mark",
                                          checked="checked"), ' 42.7 &nbsp&nbsp',
                                  _.input(type="radio", value=",", name="decimal-mark"), ' 42,7 &nbsp&nbsp',
                                  _.hr,
                                  'Array format: &nbsp',
                                  _.input(type="radio", value="curly", name="array-format",
                                          checked="checked"), ' {"a", "b"} &nbsp&nbsp',
                                  _.input(type="radio", value="normal", name="array-format"), ' ["a", "b"] &nbsp&nbsp',
                                  _.input(type="radio", value="tuple", name="array-format"), ' ("a", "b") &nbsp&nbsp',
                                  _.hr,
                                  'By clicking Export below:',
                                  _.br,
                                  _.ul[
                                      _.li['Google authentication will be required.'],
                                      _.li['A maximum limit of 100.000 rows will be applied.'],
                                      _.li['A maximum limit of 50.000 characters per cell will be applied.'],
                                      _.li['A Google sheet with the selected data will be available in a new tab.']
                                  ],
                                  _.input(type="hidden", name="query")
                              ],
                              _.div(class_="modal-footer")[
                                  _.button(id="export-to-google-sheet", type="submit", class_="btn btn-primary")[
                                      'Export']]]]]]

              ],
        action_buttons=action_buttons,
        js_files=['https://www.gstatic.com/charts/loader.js',
                  flask.url_for('mara_data_explorer.static', filename='tagsinput.js'),
                  flask.url_for('mara_data_explorer.static', filename='typeahead.js'),
                  flask.url_for('mara_data_explorer.static', filename='data-sets.js')],
        css_files=[flask.url_for('mara_data_explorer.static', filename='tagsinput.css'),
                   flask.url_for('mara_data_explorer.static', filename='data-sets.css')])
Ejemplo n.º 17
0
def start_page():
    import mara_pipelines.config

    from mara_data_explorer.data_set import find_data_set
    data_set_for_preview = find_data_set('order_items')
    assert (data_set_for_preview)

    return response.Response(
        title='MyCompany BI',
        html=_.div(class_='row')[_.div(
            class_='col-lg-6'
        )[bootstrap.
          card(header_left=_.b['Welcome'],
               body=[
                   _.
                   p['This is the first thing that users of your data warehouse will see. ',
                     'Please add links to relevant documentation, tutorials & other ',
                     'data tools in your organization.'], _.p[
                         _.a(href='https://github.com/mara/mara-example-project-1/blob/master/app/ui/start_page.py'
                             )[
                                 'Here'],
                         ' is the source code for this page, and here is a picture of a ',
                         _.a(href='https://en.wikipedia.org/wiki/Mara_(mammal)'
                             )[
                                 'mara'], ':'],
                   _.
                   img(src=flask.url_for('ui.static', filename='mara.jpg'),
                       style
                       ='width:40%; margin-left: auto; margin-right:auto; display:block;'
                       )
               ]),
          bootstrap.card(header_left=[
              _.b[_.a(href=flask.url_for('mara_metabase.metabase'))[_.span(
                  class_='fa fa-bar-chart')[''], ' Metabase']], ' &amp; ', _.
              b[_.a(href=flask.url_for('mara_mondrian.saiku'))[_.span(
                  class_='fa fa-bar-chart')[''], ' Saiku']],
              ': Company wide dashboards, pivoting & ad hoc analysis'
          ],
                         body=[
                             _.
                             p['Metabase tutorial: ',
                               _.
                               a(href=
                                 'https://www.metabase.com/docs/latest/getting-started.html'
                                 )
                               ['https://www.metabase.com/docs/latest/getting-started.html']],
                             _.
                             p['Saiku introduction: ',
                               _.
                               a(href=
                                 'https://saiku-documentation.readthedocs.io/en/latest/'
                                 )
                               ['https://saiku-documentation.readthedocs.io/en/latest/']]
                         ]),
          bootstrap.card(header_left=[
              _.b[_.a(href=flask.url_for('mara_data_explorer.index_page'))[
                  _.span(class_='fa fa-table')[''],
                  ' Explore']], ': Raw data access & segmentation'
          ],
                         body=[
                             _.p[_.a(
                                 href=flask.
                                 url_for('mara_data_explorer.data_set_page',
                                         data_set_id=data_set_for_preview.id
                                         ))[data_set_for_preview.name], ':',
                                 html.asynchronous_content(
                                     flask.url_for(
                                         'mara_data_explorer.data_set_preview',
                                         data_set_id=data_set_for_preview.id)
                                 )], _.
                             p['Other data sets: ', ', '.join([
                                 str(
                                     _.a(href=flask.url_for(
                                         'mara_data_explorer.data_set_page',
                                         data_set_id=ds.id))[ds.name])
                                 for ds in mara_data_explorer.config.data_sets(
                                 ) if ds.id != data_set_for_preview.id
                             ])]
                         ])],
                                 _.div(class_='col-lg-6')
                                 [bootstrap.
                                  card(header_left=[
                                      _.b[_.a(href=flask.url_for(
                                          'mara_schema.index_page'))[_.span(
                                              class_='fa fa-book'
                                          )[''], ' Data sets']],
                                      ': Documentation of attributes and metrics of all data sets'
                                  ],
                                       body=html.asynchronous_content(
                                           url=flask.
                                           url_for('mara_schema.overview_graph'
                                                   ))),
                                  bootstrap.card(header_left=[
                                      _.b[_.a(
                                          href=flask.
                                          url_for('mara_pipelines.node_page')
                                      )[_.span(class_='fa fa-wrench')[''],
                                        ' Pipelines']],
                                      ': The data integration pipelines that create the DWH'
                                  ],
                                                 body=html.
                                                 asynchronous_content(
                                                     flask.url_for(
                                                         'mara_pipelines.dependency_graph',
                                                         path='/'))),
                                  bootstrap.card(header_left=[
                                      _.b[_.a(href=flask.
                                              url_for('mara_db.index_page')
                                              )[_.span(
                                                  class_='fa fa-database')[''],
                                                ' Database Schemas']],
                                      ': Schemas of all databases connections'
                                  ],
                                                 body=[
                                                     html.asynchronous_content(
                                                         flask.url_for(
                                                             'mara_db.draw_schema',
                                                             db_alias=
                                                             mara_pipelines.
                                                             config.
                                                             default_db_alias(
                                                             ),
                                                             schemas='ec_dim'
                                                         ) +
                                                         '?hide-columns=True')
                                                 ])]])
Ejemplo n.º 18
0
def data_set_page(id: str) -> response.Response:
    """Renders the pages for individual data sets"""
    from ..config import data_sets

    data_set = next(
        (data_set for data_set in data_sets() if data_set.id() == id), None)
    if not data_set:
        flask.flash(f'Could not find data set "{id}"', category='warning')
        return flask.redirect(flask.url_for('mara_schema.index_page'))

    base_url = flask.url_for('mara_schema.data_set_sql_query',
                             id=data_set.id())

    def attribute_rows(data_set: DataSet) -> []:
        rows = []
        for path, attributes in data_set.connected_attributes().items():
            if path:
                rows.append(_.tr[_.td(
                    colspan=3, style='border-top:none; padding-top: 20px;'
                )[[[
                    '→ ',
                    _.a(
                        href=data_set_url(entity.data_set)
                    )[link_title] if entity.data_set else link_title, ' &nbsp;'
                ] for entity, link_title in [(
                    entity_link.target_entity,
                    entity_link.prefix or entity_link.target_entity.name)
                                             for entity_link in path]],
                  [' &nbsp;&nbsp;', _.
                   i[path[-1].description]] if path[-1].description else '']])
            for prefixed_name, attribute in attributes.items():
                rows.append(_.tr[_.td[escape(prefixed_name)], _.td[_.i[escape(
                    attribute.description
                )]], _.td[_.tt[escape(
                    f'{path[-1].target_entity.table_name + "." if path else ""}{attribute.column_name}'
                )]]])
        return rows

    return response.Response(
        html=[
            bootstrap.card(
                header_left=_.i[escape(data_set.entity.description)],
                body=[
                    _.p['Entity table: ', _.code[escape(
                        f'{data_set.entity.schema_name}.{data_set.entity.table_name}'
                    )]],
                    html.asynchronous_content(
                        flask.url_for('mara_schema.data_set_graph',
                                      id=data_set.id())),
                ]),
            bootstrap.card(
                header_left='Metrics',
                body=[
                    html.asynchronous_content(
                        flask.url_for('mara_schema.metrics_graph',
                                      id=data_set.id())),
                    bootstrap.table(['Name', 'Description', 'Computation'], [[
                        _.tr[_.td[escape(metric.name)],
                             _.td[_.i[escape(metric.description)]],
                             _.td[_.code[escape(metric.display_formula())]]]
                        for metric in data_set.metrics.values()
                    ]]),
                ]),
            bootstrap.card(header_left='Attributes',
                           body=bootstrap.table(
                               ["Name", "Description", "Column name"],
                               attribute_rows(data_set))),
            bootstrap.card(
                header_left=[
                    'Data set sql query: &nbsp;',
                    [
                        _.div(class_='form-check form-check-inline')
                        ["&nbsp;&nbsp; ",
                         _.label(class_='form-check-label')[
                             _.input(class_="form-check-input param-checkbox",
                                     type="checkbox",
                                     value=param)[''], ' ', param]]
                        for param in [
                            'human readable columns',
                            'pre-computed metrics',
                            'star schema',
                            'personal data',
                            'high cardinality attributes',
                        ]
                    ]
                ],
                body=[
                    _.div(id='sql-container')[html.asynchronous_content(
                        base_url, 'sql-container')], _.script['''
document.addEventListener('DOMContentLoaded', function() {
    DataSetSqlQuery("''' + base_url + '''");
});
''']
                ])
        ],
        title=f'Data set "{data_set.name}"',
        js_files=[
            flask.url_for('mara_schema.static',
                          filename='data-set-sql-query.js')
        ],
    )
Ejemplo n.º 19
0
def data_set_page(data_set_id, query_id):
    ds = find_data_set(data_set_id)
    if not ds:
        flask.flash(f'Data set "{data_set_id}" does not exist anymore',
                    category='danger')
        return flask.redirect(flask.url_for('data_sets.index_page'))

    action_buttons = [
        response.ActionButton(action='javascript:dataSetPage.downloadCSV()',
                              icon='download',
                              label='CSV',
                              title='Download as CSV'),
        response.ActionButton(action='javascript:dataSetPage.load()',
                              icon='folder-open',
                              label='Load',
                              title='Load previously saved query'),
        response.ActionButton(action='javascript:dataSetPage.save()',
                              icon='save',
                              label='Save',
                              title='Save query')
    ]

    if query_id:
        action_buttons.insert(
            1,
            response.ActionButton(action=flask.url_for(
                'data_sets._delete_query',
                data_set_id=data_set_id,
                query_id=query_id),
                                  icon='trash',
                                  label='Delete',
                                  title='Delete query'))

    return response.Response(
        title=f'Query "{query_id}" on "{ds.name}"'
        if query_id else f'New query on "{ds.name}"',
        html=[
            _.div(
                class_='row')[_.div(
                    class_='col-md-3'
                )[bootstrap.card(header_left='Query',
                                 body=_.div(
                                     id='query-details')[html.spinner()]),
                  bootstrap.
                  card(header_left='Columns',
                       body=[
                           _.div(
                               class_="form-group"
                           )[_.input(type="search",
                                     class_="columns-search form-control",
                                     value="",
                                     placeholder="Filter")],
                           _.div(id='columns-list')[html.spinner()]
                       ])],
                              _.div(class_='col-md-9')[bootstrap.card(
                                  id='filter-card',
                                  header_left=[
                                      _.div(class_="dropdown")[_.a(
                                          **{
                                              'class': 'dropdown-toggle',
                                              'data-toggle': 'dropdown',
                                              'href': '#'
                                          }
                                      )[_.span(
                                          class_='fa fa-plus')[' '],
                                        ' Add filter'],
                                                               _.
                                                               div(class_=
                                                                   "dropdown-menu",
                                                                   id=
                                                                   'filter-menu'
                                                                   )
                                                               [_.div(
                                                                   class_
                                                                   ="dropdown-item"
                                                               )[_.input(
                                                                   type
                                                                   ="text",
                                                                   class_=
                                                                   "columns-search form-control",
                                                                   value="",
                                                                   placeholder=
                                                                   "Filter")]]]
                                  ],
                                  fixed_header_height=False,
                                  body=_.div(id='filters')[html.spinner()]),
                                                       bootstrap.
                                                       card(header_left=_.div(
                                                           id='row-counts'
                                                       )[html.spinner()],
                                                            header_right=_.div(
                                                                id='pagination'
                                                            )[html.spinner()],
                                                            body=_.div(
                                                                id='preview'
                                                            )[html.spinner()]),
                                                       _.
                                                       div(class_='row',
                                                           id=
                                                           'distribution-charts'
                                                           )['']]],
            _.script[f"""
var dataSetPage = null;                  
document.addEventListener('DOMContentLoaded', function() {{
    dataSetPage = DataSetPage('{flask.url_for('data_sets.index_page')}', 
                              {json.dumps({'data_set_id': data_set_id, 'query_id': query_id, 'query': flask.request.get_json()})},
                              15, '{config.charts_color()}');
}});
            """],
            html.spinner_js_function(),
            _.div(class_='col-xl-4 col-lg-6',
                  id='distribution-chart-template',
                  style='display: none')[bootstrap.card(
                      header_left=html.spinner(),
                      body=_.div(class_='chart-container google-chart')[
                          html.spinner()])],
            _.div(
                class_='modal fade', id='load-query-dialog',
                tabindex="-1")[_.div(
                    class_='modal-dialog', role='document')[_.div(
                        class_='modal-content')[_.div(class_='modal-header')[
                            _.h5(class_='modal-title')['Load query'],
                            _.button(
                                **{
                                    'type': "button",
                                    'class': "close",
                                    'data-dismiss': "modal",
                                    'aria-label': "Close"
                                })[_.span(
                                    **{'aria-hidden': 'true'})['&times']]],
                                                _.div(class_='modal-body',
                                                      id='query-list')['']]]],
            _.form(
                action=flask.url_for('data_sets.download_csv'),
                method='post')[_.div(
                    class_="modal fade",
                    id="download-csv-dialog",
                    tabindex="-1"
                )[_.div(class_="modal-dialog", role='document')[_.div(
                    class_="modal-content"
                )[_.div(class_="modal-header")
                  [_.h5(class_='modal-title')['Download as CSV'],
                   _.button(
                       **{
                           'type': "button",
                           'class': "close",
                           'data-dismiss': "modal",
                           'aria-label': "Close"
                       })[_.span(
                           **{'aria-hidden': 'true'})['&times']]],
                  _.div(class_="modal-body")[
                      'Delimiter: &nbsp',
                      _.input(type="radio",
                              value="\t",
                              name="delimiter",
                              checked="checked"),
                      ' tab &nbsp&nbsp',
                      _.input(type="radio", value=";", name="delimiter"),
                      ' semicolon &nbsp&nbsp',
                      _.input(type="radio", value=",", name="delimiter"),
                      ' comma &nbsp&nbsp', _.hr, 'Number format: &nbsp',
                      _.input(type="radio",
                              value=".",
                              name="decimal-mark",
                              checked="checked"), ' 42.7 &nbsp&nbsp',
                      _.input(type="radio", value=",", name="decimal-mark"),
                      ' 42,7 &nbsp&nbsp',
                      _.input(type="hidden", name="query")],
                  _.div(class_="modal-footer"
                        )[_.button(id="csv-download-button",
                                   type="submit",
                                   class_="btn btn-primary")['Download']]]]]]
        ],
        action_buttons=action_buttons,
        js_files=[
            'https://www.gstatic.com/charts/loader.js',
            flask.url_for('data_sets.static', filename='tagsinput.js'),
            flask.url_for('data_sets.static', filename='typeahead.js'),
            flask.url_for('data_sets.static', filename='data-sets.js')
        ],
        css_files=[
            flask.url_for('data_sets.static', filename='tagsinput.css'),
            flask.url_for('data_sets.static', filename='data-sets.css')
        ])
Ejemplo n.º 20
0
def card(node: pipelines.Node):
    """A card that shows the duration of the node and its top children over time"""
    return bootstrap.card(header_left='Run times',
                          body=html.asynchronous_content(
                              flask.url_for('mara_pipelines.run_time_chart',
                                            path=node.url_path())))
Ejemplo n.º 21
0
def view_plots():
    return response.Response(
        html=[
            _.div(id='forecast-container')[_.div(class_="")[[
                [
                    _.div(class_='row')[_.div(class_='col-xl-12')[_.div(
                        class_='section-header')[forecast.metric_name]]],
                    _.div(class_='row')[_.div(class_='col-xl-12')[
                        _.p()['Number of days: ' +
                              str(forecast.number_of_days),
                              _.br(), 'Time-series query: ',
                              html.highlight_syntax(forecast.time_series_query,
                                                    language='postgresql')],
                        bootstrap.card(
                            header_left='Forecast plot of "' +
                            forecast.metric_name + '"',
                            header_right=_.div()[
                                # config.forecast_table_name
                                # _.a(class_='query-control', style='margin-right: 10px',
                                #     href='#')[
                                #     _.span(class_='fa fa-download')[' ']],
                                _.
                                a(class_='query-control',
                                  href=f"javascript:showQueryDetails('"
                                  f"{flask.url_for('forecasts.query_details', name=forecast.metric_name)}')"
                                  )[_.span(class_='fa fa-eye')[' ']]],
                            body=[
                                html.asynchronous_content(
                                    flask.url_for('forecasts.get_plot_image',
                                                  name=forecast.metric_name.
                                                  lower().replace(' ', '_').
                                                  replace('-', '_'),
                                                  components='False')),
                                _.br(),
                                _.br(),
                                _.div(class_='modal fade',
                                      id='query-details-dialog',
                                      tabindex="-1"
                                      )[_.div(class_='modal-dialog modal-lg',
                                              role='document')[_.div(
                                                  class_='modal-content'
                                              )[_.div(
                                                  class_='modal-header'
                                              )[_.h5(class_='modal-title'
                                                     )['Time-series query'],
                                                _.button(
                                                    **{
                                                        'type': "button",
                                                        'class': "close",
                                                        'data-dismiss': "modal",
                                                        'aria-label': "Close"
                                                    }
                                                )[_.span(
                                                    **{'aria-hidden': 'true'}
                                                )['&times']]],
                                                _.div(class_='modal-body',
                                                      id='query-details'
                                                      )['']]]],
                            ])],
                                        _.
                                        div(class_='col-xl-12')[bootstrap.card(
                                            header_left=
                                            'Forecast components (trend, holidays, seasonality) of "{}"'
                                            .format(forecast.metric_name),
                                            header_right='',
                                            body=[
                                                html.asynchronous_content(
                                                    flask.url_for(
                                                        'forecasts.get_plot_image',
                                                        name=forecast.
                                                        metric_name.lower(
                                                        ).replace(' ', '_').
                                                        replace('-', '_'),
                                                        components='True')),
                                            ])],
                                        _.hr()]
                ] for forecast in config.forecasts()
            ]]],
            _.script['''''']
        ],
        title='Forecasts',
        css_files=[
            'https://fonts.googleapis.com/css?family=Open+Sans:300,400,700',
            flask.url_for('forecasts.static', filename='forecast.css')
        ],
        js_files=[
            flask.url_for('forecasts.static', filename='forecast.js'),
            'https://www.gstatic.com/charts/loader.js'
        ])
Ejemplo n.º 22
0
def run_page(path: str, with_upstreams: bool, ids: str):
    if not config.allow_run_from_web_ui():
        flask.abort(
            403,
            'Running piplelines from web ui is disabled for this instance')

    # the pipeline to run
    pipeline, found = pipelines.find_node(path.split('/'))
    if not found:
        flask.abort(404, f'Pipeline "{path}" not found')
    assert (isinstance(pipeline, pipelines.Pipeline))

    # a list of nodes to run selectively in the pipeline
    nodes = []
    for id in (ids.split('/') if ids else []):
        node = pipeline.nodes.get(id)
        if not node:
            flask.abort(404, f'Node "{id}" not found in pipeline "{path}"')
        else:
            nodes.append(node)

    stream_url = flask.url_for('mara_pipelines.do_run',
                               path=path,
                               with_upstreams=with_upstreams,
                               ids=ids)

    title = [
        'Run ', 'with upstreams ' if with_upstreams else '', ' / '.join([
            str(_.a(href=views.node_url(parent))[parent.id])
            for parent in pipeline.parents()[1:]
        ])
    ]
    if nodes:
        title += [
            ' / [', ', '.join([
                str(_.a(href=views.node_url(node))[node.id]) for node in nodes
            ]), ']'
        ]

    return response.Response(
        html=[
            _.script['''
document.addEventListener('DOMContentLoaded', function() {
     processRunEvents(''' + json.dumps(
                flask.url_for('mara_pipelines.node_page', path='')) + ', ' +
                     json.dumps(stream_url) + ', ' +
                     json.dumps(pipeline.path()) + ''');
});'''],
            _.style[
                'span.action-buttons > * {display:none}'],  # hide reload button until run finishes
            _.div(class_='row')
            [_.div(class_='col-lg-7')[bootstrap.card(body=_.div(
                id='main-output-area', class_='run-output')[''])],
             _.div(class_='col-lg-5 scroll-container')[
                 bootstrap.
                 card(header_left='Timeline',
                      body=[
                          _.div(id='system-stats-chart', class_='google-chart'
                                )[' '],
                          _.div(id='timeline-chart')[' ']
                      ]),
                 _.div(id='failed-tasks-container')[''],
                 _.div(id='running-tasks-container')[''],
                 _.div(id='succeeded-tasks-container')[''],
                 bootstrap.card(id='card-template',
                                header_left=' ',
                                header_right=' ',
                                body=[_.div(class_='run-output')['']])]]
        ],
        js_files=[
            'https://www.gstatic.com/charts/loader.js',
            flask.url_for('mara_pipelines.static',
                          filename='timeline-chart.js'),
            flask.url_for('mara_pipelines.static',
                          filename='system-stats-chart.js'),
            flask.url_for('mara_pipelines.static', filename='utils.js'),
            flask.url_for('mara_pipelines.static', filename='run-page.js')
        ],
        css_files=[
            flask.url_for('mara_pipelines.static',
                          filename='timeline-chart.css'),
            flask.url_for('mara_pipelines.static', filename='run-page.css'),
            flask.url_for('mara_pipelines.static', filename='common.css')
        ],
        action_buttons=[
            response.ActionButton(
                action='javascript:location.reload()',
                label='Run again',
                icon='play',
                title='Run pipeline again with same parameters as before')
        ],
        title=title,
    )