def get_plot_image(name, components): # plot the latest forecast with mara_db.postgresql.postgres_cursor_context('mara') as cursor: cursor.execute( f''' SELECT metric_name, forecasts_df, source_df, components_figure FROM forecasts WHERE metric_name = {'%s'} ORDER BY forecast_ts DESC LIMIT 1''', (name, )) result = cursor.fetchone() png_bytes = None if result: forecast_df = pickle.loads(result[1]) source_df = pickle.loads(result[2]) components_figure = pickle.loads(result[3]) png_bytes = components_figure if components != 'True': # get main forecast plot figure figure = get_main_plot_figure(name, source_df, forecast_df) output = io.BytesIO() FigureCanvas(figure).print_png(output) png_bytes = str( base64.b64encode(output.getvalue()).decode("utf-8")) return str(_.img(src="data:image/png;base64," + png_bytes)) if result else 'No data yet.'
def page_header(response: mara_page.response.Response): """Renders the fixed top part of the page""" return _.nav(id='mara-page-header', _class='navbar fixed-top')[ _.a(_class='navigation-toggle-button fa fa-lg fa-reorder', onclick='toggleNavigation()')[' '], _.h1()[response.title], _.img(src=config.logo_url()), _.span(_class='action-buttons')[map(action_button, response. action_buttons)]]
def page_header(response: mara_page.response.Response): """Renders the fixed top part of the page""" return _.nav(id='mara-page-header', class_='navbar fixed-top')[ _.a(class_='navigation-toggle-button fa fa-lg fa-reorder', onclick='toggleNavigation()')[' '], _.img(src=config.logo_url() + '?' + _current_git_commit()), _.h1[response.title], _.div(class_='action-buttons')[map(action_button, response. action_buttons)], ]
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)