def get_model_details()

in apps/cloudwatch-dashboard/lambdas/model-details/handler.py [0:0]


def get_model_details(event, context):
    """
    Extract the model attributes from the model passed as an argument
    """
    # Get attributes from both the model and the associated dataset:
    model_name       = event['model_name']

    model_response   = l4e_client.describe_model(ModelName=model_name)
    dataset_response = l4e_client.describe_dataset(DatasetName=model_response['DatasetName'])
    date_format      = '%Y-%m-%d %H:%M:%S'
    
    try:
        # Build a dictionnary with all the model 
        # parameters we want to expose in the widget:
        model_infos = dict()
        input_configuration = dataset_response['IngestionInputConfiguration']['S3InputConfiguration']
        model_infos.update({
            'Dataset': model_response['DatasetName'],
            'Training start': datetime.strftime(
                model_response['TrainingDataStartTime'], date_format
            ),
            'Training end': datetime.strftime(
                model_response['TrainingDataEndTime'], date_format
            ),
            'Evaluation start': datetime.strftime(
                model_response['EvaluationDataStartTime'], date_format
            ),
            'Evaluation end': datetime.strftime(
                model_response['EvaluationDataEndTime'], date_format
            )
        })
        
        # Generates the HTML of the widget:
        html = model_info_widget(model_infos)
        
    # Some older model / dataset won't include all the fields we're looking
    # for: catching these error and information the user.
    except KeyError as e:
        error_msg = f'Model or dataset attribute not found: {e}'
        html = f'<span style="color: #CC0000">{error_msg}</span>'

    except:
        error_msg = "Unexpected error:", sys.exc_info()[0]
        html = f'<span style="color: #CC0000">{error_msg}</span>'
        
    return html