@@ -36,13 +36,16 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
36
36
37
37
/*
38
38
This function filters the selectedMetrics array down to only metrics that match the category of this instance of HealthContainer.
39
- Once that has finished, it then filters the healthData down to the current category and only the filteredMetrics.
39
+ Once that has finished, it then filters the healthData down to the current category and the filteredMetrics.
40
40
*/
41
41
const filterSelectedMetricsAndHealthData = ( ) : DataObject => {
42
- // filtered health data for output
42
+ // define a filtered health data object for output
43
+ // define an array of filteredMetricNames
43
44
const filteredHealthData = { } ;
44
45
const filteredMetricNames : string [ ] = [ ] ;
46
+ // iterate over the selectedMetrics from QueryContext
45
47
selectedMetrics . forEach ( metricObj => {
48
+ // due to the way the data is stored, the metricObj only has one key on it; thus [0] is tacked onto the end
46
49
const metricCategory = Object . keys ( metricObj ) [ 0 ] ;
47
50
// if the current metric's category matches our category, add its array content to the filteredHealthData array
48
51
if ( metricCategory === category ) {
@@ -51,30 +54,32 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
51
54
} ) ;
52
55
}
53
56
} ) ;
54
- // iterate over the healthData object
57
+ /*
58
+ Now that we've defined which of the user's selected metrics belong in this category, iterate over the healthData object
59
+ and filter it down to the selected category and metrics.
60
+ */
55
61
for ( const service in healthData ) {
62
+ filteredHealthData [ service ] = { } ;
56
63
const categoryObjects = healthData [ service ] ;
57
64
for ( const categoryName in categoryObjects ) {
58
65
// if the category in healthData matches the category passed down to this HealthContainer, iterate over the related metrics
59
66
if ( categoryName === category ) {
60
67
const metricObjects = categoryObjects [ categoryName ] ;
61
68
for ( const metric in metricObjects ) {
62
- // if the metric title matches any element in the filtered metrics array, add the metric object to the filteredHealthData object
69
+ // if the metric title matches any element in the filtered metrics array, add the metric serviceName to the filteredHealthData object, then add the metrics for that service
63
70
if ( filteredMetricNames . includes ( metric ) ) {
64
- filteredHealthData [ metric ] = metricObjects [ metric ] ;
71
+ filteredHealthData [ service ] [ metric ] = metricObjects [ metric ] ;
65
72
}
66
73
}
67
74
}
68
75
}
69
76
}
70
- // console.log('filteredMetricNames: ', filteredMetricNames);
71
- // console.log('filteredHealthData: ', filteredHealthData);
72
77
return filteredHealthData ;
73
78
} ;
74
79
75
80
// function to create a version of the healthData based on the value type
81
+ // current healthData value types: GHz, bytes, temperature, percent, ticks, processes, num, latency
76
82
const defineDataValueType = ( metricName : string ) : string => {
77
- // current healthData value types: GHz, bytes, temperature, percent, ticks, processes, num, latency
78
83
/*
79
84
define a dictionary of data types where the key is the expected chars to be found in the parameter
80
85
and the value is the desired data type label
@@ -91,7 +96,7 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
91
96
latency : 'Latency' ,
92
97
} ;
93
98
// iterate through the dictionary and check if the key matches any part of the metricName
94
- // if true assign type to the value of the matching key and return
99
+ // if they match, update type variable to the value of the matching key and return
95
100
let type : string = '' ; // type will store the result for returning
96
101
for ( const [ key , value ] of Object . entries ( typeDictionary ) ) {
97
102
if ( metricName . includes ( key ) ) {
@@ -104,32 +109,33 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
104
109
return type ;
105
110
} ;
106
111
107
- // function to sort the filtered healthData by data type to use for building graphs with same data label
112
+ // function to sort the filteredHealthData by data type to build graphs based on the same data label
108
113
const healthDataGroupedByDataType = ( filteredHealthData : object ) : DataObject => {
109
- const groupedObject : DataObject = { } ;
110
- // charts need to be separated first by service and then each metric needs to be separated by value type
114
+ const typeGroupedObject = { } ;
111
115
// iterate over the services in the healthData object
112
116
for ( const serviceName in filteredHealthData ) {
113
- // save the metrics of the current service to a variable
114
- // note: 'category' allows direct access to the list of metrics since we've already filtered to the current category
115
- const metrics = healthData [ serviceName ] [ category ] ;
116
- // iterate over the current service's metrics
117
- for ( const metricName in metrics ) {
118
- // define the data type of the current metric
119
- const type : string = defineDataValueType ( metricName ) ;
120
- // save the value type as a key on an object
121
- // save the value of that key as an empty object
122
- groupedObject [ type ] = { } ;
123
- // save the serviceName as a key and assign it an empty object as value
124
- groupedObject [ type ] [ serviceName ] = { } ;
125
- // define the metric's value (an object containing two keys of `data` and `time`, whose values are arrays of data/timestamps)
126
- const metricValue : object = metrics [ metricName ] ;
127
- // assign the object at that type key a new entry with the key of our current metric object's name and its value as the values
128
- groupedObject [ type ] [ serviceName ] [ metricName ] = metricValue ;
117
+ // save the filtered metrics of the current service to a variable
118
+ // define the types of each metric in the metrics object as an array
119
+ const metrics : object = filteredHealthData [ serviceName ] ;
120
+ const typesArray : string [ ] = Object . keys ( metrics ) . map ( ( metricName : string ) : string => {
121
+ return defineDataValueType ( metricName ) ;
122
+ } ) ;
123
+ // iterate over the types array and assign the typeGroupedObject a key of type, with a value of an object
124
+ // then assign that newly created object a key of the current service and a value of an object
125
+ typesArray . forEach ( ( metricType : string ) => {
126
+ typeGroupedObject [ metricType ] = { } ;
127
+ typeGroupedObject [ metricType ] [ serviceName ] = { } ;
128
+ } )
129
+ // iterate over the metrics object
130
+ for ( const metric in metrics ) {
131
+ // define the current metric's type
132
+ const metricType : string = defineDataValueType ( metric ) ;
133
+ // store the current metric and its value in the typeGrouped object at the appropriate type and serviceName
134
+ typeGroupedObject [ metricType ] [ serviceName ] [ metric ] = metrics [ metric ] ;
129
135
}
130
136
}
131
-
132
- return groupedObject ;
137
+ console . log ( 'typeGroupedObject: ' , typeGroupedObject ) ;
138
+ return typeGroupedObject ;
133
139
} ;
134
140
135
141
// function to generate charts using the type-sorted data
@@ -139,9 +145,11 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
139
145
// iterate over the sortedData and create a chart for each data type
140
146
for ( const dataType in sortedData ) {
141
147
// pass down the value of the current data type object
148
+ const chartData = sortedData [ dataType ] ;
149
+ console . log ( 'dataType: ' , dataType , 'chartData: ' , chartData ) ;
142
150
chartsArray . push (
143
151
< HealthChart
144
- key = { `Chart${ keymaker } ` }
152
+ key = { `Chart${ keymaker ++ } ` }
145
153
dataType = { dataType }
146
154
chartData = { sortedData [ dataType ] }
147
155
categoryName = { `${ category } ` }
@@ -152,17 +160,18 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
152
160
}
153
161
setHealthChartsArr ( chartsArray ) ;
154
162
} ;
155
-
163
+
156
164
useEffect ( ( ) => {
157
165
// returns an object containing only the healthData for the current category and the metrics the User selected
158
166
const filteredHealthData = filterSelectedMetricsAndHealthData ( ) ;
159
- console . log ( 'filtered health data : ' , filteredHealthData ) ;
167
+ console . log ( 'filteredHealthData : ' , filteredHealthData )
160
168
// returns an object containing the filtered data sorted by data type
161
169
const typeSortedHealthData = healthDataGroupedByDataType ( filteredHealthData ) ;
162
- console . log ( 'metrics sorted by data type : ' , typeSortedHealthData ) ;
170
+ console . log ( 'typeSortedHealthData : ' , typeSortedHealthData ) ;
163
171
// invoking generateCharts with the sorted data will update healthChartsArr in state with the list of charts to be rendered
164
172
generateCharts ( typeSortedHealthData ) ;
165
- } , [ healthData , category ] ) ;
173
+ console . log ( healthChartsArr )
174
+ } , [ category ] ) ;
166
175
167
176
// return <div>{service !== 'kafkametrics' ? healthChartsArr : []}</div>;
168
177
// JJ-ADDITION
0 commit comments