def create_model_dashboard()

in apps/cloudwatch-dashboard/lambdas/list-models/handler.py [0:0]


def create_model_dashboard(event, context):
    """
    Entry point of the list models custom widgets. This function build
    an HTML table with all the Amazon Lookout for Equipment models found in 
    this account. The user can also create a dedicated dashboard for each
    model.
    
    Returns:
        html (string): an HTML formatted string with the table to be displayed
    """
    # If a model action is requested, we perform it
    # before displaying the dashboard:
    if 'dashboard_name' in event:
        process_dashboard_actions(event)
    
    # Get all the existing dashboard once and for all:
    global all_dashboards
    all_dashboards = build_dashboard_list()

    # Get time extent to show model from:    
    widget_context = event['widgetContext']
    start = widget_context['timeRange']['start']
    end = widget_context['timeRange']['end']
    start = datetime.datetime.fromtimestamp(start/1000, datetime.timezone.utc)
    end = datetime.datetime.fromtimestamp(end/1000, datetime.timezone.utc)

    # Get all the models in this account and display then in an HTML table:
    list_models = l4e_client.list_models()['ModelSummaries']
    
    # We only keep models created in the timeframe selected by the user:
    filtered_list_models = []
    for m in list_models:
        created = m['CreatedAt']
        if (created >= start) and (created <= end):
            filtered_list_models.append(m)

    html = generate_html_table(filtered_list_models)
    
    return html