13
13
"""This module the wrapper class for data quality dashboard. To be used to aid dashboard
14
14
creation in ModelMonitor.
15
15
"""
16
+ from __future__ import absolute_import
16
17
17
18
import json
18
19
from sagemaker .dashboard .dashboard_variables import DashboardVariable
19
20
from sagemaker .dashboard .dashboard_widgets import DashboardWidget , DashboardWidgetProperties
20
- from sagemaker .model_monitor .model_monitoring import EndpointInput
21
21
22
22
23
23
class AutomaticDataQualityDashboard :
24
+ """A wrapper class for creating a data quality dashboard to aid ModelMonitor dashboard creation.
25
+
26
+ This class generates dashboard variables and widgets based on the endpoint and monitoring
27
+ schedule provided.
28
+
29
+ Attributes:
30
+ DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE (str): Namespace for endpoint data quality metrics.
31
+ DATA_QUALITY_METRICS_BATCH_NAMESPACE (str): Namespace for batch transform data quality metrics.
32
+
33
+ Methods:
34
+ __init__(self, endpoint_name, monitoring_schedule_name, batch_transform_input, region_name):
35
+ Initializes the AutomaticDataQualityDashboard instance.
36
+
37
+ _generate_variables(self):
38
+ Generates variables for the dashboard based on whether batch transform is used or not.
39
+
40
+ _generate_type_counts_widget(self):
41
+ Generates a widget for displaying type counts based on endpoint or batch transform.
42
+
43
+ _generate_null_counts_widget(self):
44
+ Generates a widget for displaying null and non-null counts based on endpoint or batch transform.
45
+
46
+ _generate_estimated_unique_values_widget(self):
47
+ Generates a widget for displaying estimated unique values based on endpoint or batch transform.
48
+
49
+ _generate_completeness_widget(self):
50
+ Generates a widget for displaying completeness based on endpoint or batch transform.
51
+
52
+ _generate_baseline_drift_widget(self):
53
+ Generates a widget for displaying baseline drift based on endpoint or batch transform.
54
+
55
+ to_dict(self):
56
+ Converts the dashboard configuration to a dictionary representation.
57
+
58
+ to_json(self):
59
+ Converts the dashboard configuration to a JSON formatted string.
60
+
61
+ """
62
+
24
63
DATA_QUALITY_METRICS_ENDPOINT_NAMESPACE = (
25
64
"{aws/sagemaker/Endpoints/data-metrics,Endpoint,Feature,MonitoringSchedule}"
26
65
)
@@ -29,11 +68,19 @@ class AutomaticDataQualityDashboard:
29
68
)
30
69
31
70
def __init__ (self , endpoint_name , monitoring_schedule_name , batch_transform_input , region_name ):
32
- if type (endpoint_name ) == EndpointInput :
33
- self .endpoint = endpoint_name .endpoint_name
34
- else :
35
- self .endpoint = endpoint_name
71
+ """Initializes an instance of AutomaticDataQualityDashboard.
72
+
73
+ Args:
74
+ endpoint_name (str or EndpointInput): Name of the endpoint or EndpointInput object.
75
+ monitoring_schedule_name (str): Name of the monitoring schedule.
76
+ batch_transform_input (str): Name of the batch transform input.
77
+ region_name (str): AWS region name.
78
+
79
+ If endpoint_name is of type EndpointInput, it extracts endpoint_name from it.
80
+
81
+ """
36
82
83
+ self .endpoint = endpoint_name
37
84
self .monitoring_schedule = monitoring_schedule_name
38
85
self .batch_transform = batch_transform_input
39
86
self .region = region_name
@@ -57,6 +104,12 @@ def __init__(self, endpoint_name, monitoring_schedule_name, batch_transform_inpu
57
104
}
58
105
59
106
def _generate_variables (self ):
107
+ """Generates dashboard variables based on the presence of batch transform.
108
+
109
+ Returns:
110
+ list: List of DashboardVariable objects.
111
+
112
+ """
60
113
if self .batch_transform is not None :
61
114
return [
62
115
DashboardVariable (
@@ -83,6 +136,12 @@ def _generate_variables(self):
83
136
]
84
137
85
138
def _generate_type_counts_widget (self ):
139
+ """Generates a widget for displaying type counts based on endpoint or batch transform.
140
+
141
+ Returns:
142
+ DashboardWidget: A DashboardWidget object configured for type counts.
143
+
144
+ """
86
145
if self .batch_transform is not None :
87
146
type_counts_widget_properties = DashboardWidgetProperties (
88
147
view = "timeSeries" ,
@@ -139,6 +198,12 @@ def _generate_type_counts_widget(self):
139
198
)
140
199
141
200
def _generate_null_counts_widget (self ):
201
+ """Generates a widget for displaying null and non-null counts based on endpoint or batch transform.
202
+
203
+ Returns:
204
+ DashboardWidget: A DashboardWidget object configured for null counts.
205
+
206
+ """
142
207
if self .batch_transform is not None :
143
208
null_counts_widget_properties = DashboardWidgetProperties (
144
209
view = "timeSeries" ,
@@ -186,6 +251,12 @@ def _generate_null_counts_widget(self):
186
251
)
187
252
188
253
def _generate_estimated_unique_values_widget (self ):
254
+ """Generates a widget for displaying estimated unique values based on endpoint or batch transform.
255
+
256
+ Returns:
257
+ DashboardWidget: A DashboardWidget object configured for estimated unique values.
258
+
259
+ """
189
260
if self .batch_transform is not None :
190
261
estimated_unique_vals_widget_properties = DashboardWidgetProperties (
191
262
view = "timeSeries" ,
@@ -237,6 +308,12 @@ def _generate_estimated_unique_values_widget(self):
237
308
)
238
309
239
310
def _generate_completeness_widget (self ):
311
+ """Generates a widget for displaying completeness based on endpoint or batch transform.
312
+
313
+ Returns:
314
+ DashboardWidget: A DashboardWidget object configured for completeness.
315
+
316
+ """
240
317
if self .batch_transform is not None :
241
318
completeness_widget_properties = DashboardWidgetProperties (
242
319
view = "timeSeries" ,
@@ -285,6 +362,12 @@ def _generate_completeness_widget(self):
285
362
)
286
363
287
364
def _generate_baseline_drift_widget (self ):
365
+ """Generates a widget for displaying baseline drift based on endpoint or batch transform.
366
+
367
+ Returns:
368
+ DashboardWidget: A DashboardWidget object configured for baseline drift.
369
+
370
+ """
288
371
if self .batch_transform is not None :
289
372
baseline_drift_widget_properties = DashboardWidgetProperties (
290
373
view = "timeSeries" ,
@@ -332,10 +415,22 @@ def _generate_baseline_drift_widget(self):
332
415
)
333
416
334
417
def to_dict (self ):
418
+ """Converts the AutomaticDataQualityDashboard configuration to a dictionary representation.
419
+
420
+ Returns:
421
+ dict: A dictionary containing variables and widgets configurations.
422
+
423
+ """
335
424
return {
336
425
"variables" : [var .to_dict () for var in self .dashboard ["variables" ]],
337
426
"widgets" : [widget .to_dict () for widget in self .dashboard ["widgets" ]],
338
427
}
339
428
340
429
def to_json (self ):
430
+ """Converts the AutomaticDataQualityDashboard configuration to a JSON formatted string.
431
+
432
+ Returns:
433
+ str: A JSON formatted string representation of the dashboard configuration.
434
+
435
+ """
341
436
return json .dumps (self .to_dict (), indent = 4 )
0 commit comments