示例#1
0
    def fetch_widget_data(self):
        """
        Get widget data via query manager

        returns: {Dict} A dictionary of the pandas dataframe data from the query manager
        """
        # Create the widget name for the QueryManager
        cur_user = User.get_instance()
        user_id = cur_user.get_user_id()
        time_stamp_from = cur_user.get_time_stamp_from()
        time_stamp_to = cur_user.get_time_stamp_to()
        database_id = cur_user.get_user_database_id()
        widget_name = '%s-widget-%s-%s-%s-%s-user-%s' % (
            self.widget_type, self.config['title']['text'], time_stamp_from,
            time_stamp_to, database_id, user_id)
        # Define the MySQL query to run
        sql_query = "SELECT t_stamp, value, name FROM data WHERE name=\'" + self.config[
            'metric'] + "\' AND t_stamp BETWEEN \'%s 00:00:00\' AND \'%s 00:00:00\' order by t_stamp" % (
                time_stamp_from, time_stamp_to)

        # Fetch the data from the query manager
        self.widget_data = self.queryManager.getWidgetDataFromQueryManager(
            widget_name, time_stamp_from, time_stamp_to, database_id,
            sql_query, user_id, True)

        # return the fetched data
        return self.widget_data
示例#2
0
import dash
import dash_bootstrap_components as dbc
from classes.User import User

# get the current user instance
current_user = User.get_instance()

external_stylesheets = [
    dbc.themes.BOOTSTRAP,
    # '/assets/css/jquery.dataTables.min.css',
    # '/assets/css/scroller.dataTables.min.css',
]

external_scripts = [
    '/assets/js/jquery-3.3.1.min.js',
    '/assets/js/popper.min.js',
    # '/assets/js/jquery.dataTables.min.js',
    # '/assets/js/dataTables.scroller.min.js',
]

# Create dash app
app = dash.Dash(
    __name__,
    external_stylesheets=external_stylesheets,
    external_scripts=external_scripts,
    suppress_callback_exceptions=True,
    meta_tags=[{
        'name': 'viewport',
        'content': 'width=device-width, initial-scale=1.0'
    }]
)