Skip to content

Commit 83661cf

Browse files
Sushanth Sathish Kumarsushanthkumar2004
authored andcommitted
feat: Add ability to create a model monitoring dashboard and refactor code
1 parent cfeb219 commit 83661cf

File tree

7 files changed

+935
-423
lines changed

7 files changed

+935
-423
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""This module contains code containing wrapper classes for dashboard variables in CloudWatch.
14+
15+
These classes assist with creating dashboards in Python3 and then using boto3 CloudWatch client
16+
to publish the generated dashboards. To be used to aid dashboard creation in ClarifyModelMonitor
17+
and ModelMonitor.
18+
"""
19+
20+
import json
21+
22+
class DashboardVariable:
23+
def __init__(
24+
self, variable_type, variable_property, inputType, variable_id, label, search, populateFrom
25+
):
26+
self.variable_type = variable_type
27+
self.variable_property = variable_property
28+
self.inputType = inputType
29+
self.id = variable_id
30+
self.label = label
31+
self.search = search
32+
self.populateFrom = populateFrom
33+
34+
def to_dict(self):
35+
variable_properties_dict = {}
36+
if self.variable_type is not None:
37+
variable_properties_dict["type"] = self.variable_type
38+
if self.variable_property is not None:
39+
variable_properties_dict["property"] = self.variable_property
40+
if self.inputType is not None:
41+
variable_properties_dict["inputType"] = self.inputType
42+
if self.id is not None:
43+
variable_properties_dict["id"] = self.id
44+
if self.label is not None:
45+
variable_properties_dict["label"] = self.label
46+
if self.search is not None:
47+
variable_properties_dict["search"] = self.search
48+
if self.populateFrom is not None:
49+
variable_properties_dict["populateFrom"] = self.populateFrom
50+
return variable_properties_dict
51+
52+
def to_json(self):
53+
json.dumps(self.to_dict(), indent=4)
54+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""This module contains code containing wrapper classes for dashboard widgets in CloudWatch.
14+
15+
These classes assist with creating dashboards in Python3 and then using boto3 CloudWatch client
16+
to publish the generated dashboards. To be used to aid dashboard creation in ClarifyModelMonitor
17+
and ModelMonitor.
18+
"""
19+
20+
import json
21+
22+
class DashboardWidgetProperties:
23+
def __init__(
24+
self,
25+
view=None,
26+
stacked=None,
27+
metrics=None,
28+
region=None,
29+
period=None,
30+
title=None,
31+
markdown=None,
32+
):
33+
self.view = view
34+
self.stacked = stacked
35+
self.metrics = metrics
36+
self.region = region
37+
self.period = period
38+
self.title = title
39+
self.markdown = markdown
40+
41+
def to_dict(self):
42+
widget_properties_dict = {}
43+
if self.view is not None:
44+
widget_properties_dict["view"] = self.view
45+
if self.period is not None:
46+
widget_properties_dict["period"] = self.period
47+
if self.markdown is not None:
48+
widget_properties_dict["markdown"] = self.markdown
49+
if self.stacked is not None:
50+
widget_properties_dict["stacked"] = self.stacked
51+
if self.region is not None:
52+
widget_properties_dict["region"] = self.region
53+
if self.metrics is not None:
54+
widget_properties_dict["metrics"] = self.metrics
55+
if self.title is not None:
56+
widget_properties_dict["title"] = self.title
57+
return widget_properties_dict
58+
59+
def to_json(self):
60+
json.dumps(self.to_dict(), indent=4)
61+
62+
63+
class DashboardWidget:
64+
def __init__(self, height, width, widget_type, properties=None):
65+
self.height = height
66+
self.width = width
67+
self.type = widget_type
68+
self.properties = (
69+
properties
70+
if properties
71+
else DashboardWidgetProperties(None, False, [], None, None, None)
72+
)
73+
74+
def to_dict(self):
75+
return {
76+
"height": self.height,
77+
"width": self.width,
78+
"type": self.type,
79+
"properties": self.properties.to_dict(),
80+
}
81+
82+
def to_json(self):
83+
return json.dumps(self.to_dict(), indent=4)

0 commit comments

Comments
 (0)