Skip to content

Commit 0891d9a

Browse files
committed
Merge branch 'graph-work' into dev
2 parents a395c81 + a8676c4 commit 0891d9a

File tree

15 files changed

+283
-85
lines changed

15 files changed

+283
-85
lines changed

app/charts/LatencyChart.tsx

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useContext, useEffect, useState } from 'react';
22
import Plot from 'react-plotly.js';
3+
import moment from 'moment';
34
import { HealthContext } from '../context/HealthContext';
45
import { all, solo as soloStyle } from './sizeSwitch';
56

@@ -14,6 +15,40 @@ interface SoloStyles {
1415

1516
const LatencyChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) => {
1617
const { healthData } = useContext(HealthContext);
18+
const [data, setData] = useState<Array<Array<string | (string | number)[]>>>([]);
19+
20+
useEffect(() => {
21+
if (healthData.length) {
22+
const tempArr: ((string | number)[] | string)[][] = [];
23+
// loop over each
24+
healthData.forEach(
25+
(service: {
26+
time: string[];
27+
latency: (string | number)[];
28+
service: string[]
29+
}) => {
30+
let timeArr: string[] = [];
31+
// perform this when we 'setTime'
32+
if (service.time !== undefined) {
33+
timeArr = service.time.map((el: any) => moment(el).format('kk:mm:ss'));
34+
}
35+
36+
const temp: [string[], (string | number)[], string] = [
37+
timeArr,
38+
service.latency,
39+
service.service[0],
40+
];
41+
tempArr.push(temp);
42+
}
43+
);
44+
setData(tempArr);
45+
}
46+
}, [healthData]);
47+
48+
// FOR CHECKING
49+
// useEffect(() => {
50+
// console.log(data);
51+
// }, [data]);
1752

1853
const [solo, setSolo] = useState<SoloStyles | null>(null);
1954

@@ -26,21 +61,36 @@ const LatencyChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) =>
2661
const createChart = () => {
2762
const yAxis: Array<number> = healthData.latency;
2863

64+
let plotlyData: {
65+
name: any;
66+
x: any;
67+
y: any;
68+
type: any;
69+
mode: any;
70+
marker: { color: string };
71+
}[] = [];
72+
73+
plotlyData = data.map(dataArr => {
74+
// eslint-disable-next-line no-bitwise
75+
const randomColor = `#${(((1 << 24) * Math.random()) | 0).toString(16)}`;
76+
77+
return {
78+
name: dataArr[2],
79+
x: data[0][0],
80+
y: dataArr[1],
81+
type: 'scattergl',
82+
mode: 'lines',
83+
marker: { color: randomColor }
84+
};
85+
});
86+
87+
2988
const sizeSwitch = sizing === 'all' ? all : solo;
3089

31-
console.log(sizeSwitch);
3290

3391
return (
3492
<Plot
35-
data={[
36-
{
37-
name: 'CPU Latency',
38-
type: 'scattergl',
39-
y: yAxis,
40-
mode: 'lines',
41-
marker: { color: '#fc4039' },
42-
},
43-
]}
93+
data={[...plotlyData]}
4494
layout={{
4595
title: 'Latency',
4696
...sizeSwitch,
@@ -59,7 +109,7 @@ const LatencyChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) =>
59109
y: 5,
60110
},
61111
xaxis: {
62-
title: 'Time Elapsed (min)',
112+
title: 'Time',
63113
tickmode: 'linear',
64114
tick0: 0,
65115
dtick: 10,

app/charts/ProcessesChart.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/** FOR THE NEXT TEAM
2+
* You should probably take a look and fix the legend for the graph.
3+
* Can compare services, but hard to tell which points of data belong to which server.
4+
*/
5+
16
/* eslint-disable no-useless-concat */
27
import React, { useContext, useState, useEffect } from 'react';
38
import Plot from 'react-plotly.js';
@@ -32,6 +37,8 @@ const ProcessesChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) =
3237

3338
useEffect(() => {
3439
if (healthData.length) {
40+
const tempArr: [string, string[], string[], string[]][] = [];
41+
3542
// loop over each
3643
healthData.forEach(
3744
(service: {
@@ -46,12 +53,12 @@ const ProcessesChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) =
4653
service.blockedprocesses,
4754
service.sleepingprocesses,
4855
];
49-
setData(data.concat([temp]));
56+
tempArr.push(temp);
57+
58+
5059
}
5160
);
52-
// temp = [ string, [], [], [] ]
53-
// setTime(healthData[0].time); //push
54-
// setCpuSpeed(healthData[0].cpuspeed); //push
61+
setData(tempArr);
5562
}
5663
}, [healthData]);
5764

app/charts/SpeedChart.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/** FOR THE NEXT TEAM
2+
* Currently, data for multiple servers overlap, as we wanted. However, if using the dummy MongoDB data, the lines technically do not overlap since it only records speeds for one server at a time. However, we expect that, when running on a proper app, speeds from all servers will be recorded.
3+
*/
4+
15
import React, { useContext, useEffect, useState } from 'react';
26
import Plot from 'react-plotly.js';
37
import moment from 'moment';
@@ -25,10 +29,7 @@ const SpeedChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) => {
2529
let timeArr: string[] = [];
2630
// perform this when we 'setTime'
2731
if (service.time !== undefined) {
28-
timeArr = service.time.map((el: any) => moment(el).format('hh:mm:ss A'));
29-
service.time.forEach((el, i) => {
30-
// console.log(el, timeArr[i]);
31-
});
32+
timeArr = service.time.map((el: any) => moment(el).format('kk:mm:ss'));
3233
}
3334

3435
const temp: [string[], (string | number)[], string] = [
@@ -40,14 +41,12 @@ const SpeedChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) => {
4041
}
4142
);
4243
setData(tempArr);
43-
// setTime(healthData[0].time); //push
44-
// setCpuSpeed(healthData[0].cpuspeed); //push
4544
}
4645
}, [healthData]);
4746

48-
useEffect(() => {
49-
console.log(data);
50-
}, [data]);
47+
// useEffect(() => {
48+
// console.log(data);
49+
// }, [data]);
5150

5251
const [solo, setSolo] = useState<SoloStyles | null>(null);
5352

app/charts/TemperatureChart.tsx

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,79 @@ interface SoloStyles {
1515

1616
const TemperatureChart: React.FC<GraphsContainerProps> = React.memo(({ sizing }) => {
1717
const { healthData } = useContext(HealthContext);
18-
const { time, cputemp } = healthData;
18+
const [data, setData] = useState<Array<Array<string | (string | number)[]>>>([]);
19+
20+
useEffect(() => {
21+
if (healthData.length) {
22+
const tempArr: ((string | number)[] | string)[][] = [];
23+
// loop over each
24+
healthData.forEach(
25+
(service: {
26+
time: string[];
27+
cputemp: (string | number)[];
28+
service: string[]
29+
}) => {
30+
let timeArr: string[] = [];
31+
// perform this when we 'setTime'
32+
if (service.time !== undefined) {
33+
timeArr = service.time.map((el: any) => moment(el).format('kk:mm:ss'));
34+
}
1935

20-
const createChart = () => {
21-
const yAxis = cputemp;
22-
let month: undefined | string;
23-
let timeArr: undefined | [number];
24-
if (time !== undefined && cputemp !== undefined) {
25-
timeArr = time.map((el: string) => moment(el).format('hh:mm A'));
26-
month = moment(time[0]).format('MMM Do');
36+
const temp: [string[], (string | number)[], string] = [
37+
timeArr,
38+
service.cputemp,
39+
service.service[0],
40+
];
41+
tempArr.push(temp);
42+
}
43+
);
44+
setData(tempArr);
2745
}
46+
}, [healthData]);
2847

29-
const [solo, setSolo] = useState<SoloStyles | null>(null);
48+
const [solo, setSolo] = useState<SoloStyles | null>(null);
3049

3150
setInterval(() => {
3251
if (solo != soloStyle) {
3352
setSolo(soloStyle);
3453
}
3554
}, 20);
3655

56+
57+
const createChart = () => {
58+
59+
60+
let plotlyData: {
61+
name: any;
62+
x: any;
63+
y: any;
64+
type: any;
65+
fillcolor: any;
66+
mode: any;
67+
showlegend: any;
68+
}[] = [];
69+
70+
plotlyData = data.map(dataArr => {
71+
// eslint-disable-next-line no-bitwise
72+
const randomColor = `#${(((1 << 24) * Math.random()) | 0).toString(16)}`;
73+
74+
return {
75+
name: dataArr[2],
76+
x: data[0][0],
77+
y: dataArr[1],
78+
fillcolor: randomColor,
79+
type: 'scatter',
80+
mode: 'lines',
81+
showlegend: true,
82+
};
83+
});
84+
3785
const sizeSwitch = sizing === 'all' ? all : solo;
3886

3987
return (
4088
<Plot
4189
data={[
42-
{
43-
type: 'scatter',
44-
fill: 'tozeroy',
45-
mode: 'lines',
46-
fillcolor: '#4b54ea',
47-
x: timeArr,
48-
y: yAxis,
49-
name: 'CPU Temperature',
50-
showlegend: true,
51-
},
90+
...plotlyData
5291
]}
5392
config={{ responsive: true }}
5493
layout={{

app/components/Applications.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const Applications: React.FC = React.memo(() => {
103103
ref={element => {
104104
delRef.current[i] = element;
105105
}}
106-
className={classes.iconbutton}
106+
className={classes.iconbutton + "deleteBtn"}
107107
aria-label="Delete"
108108
onClick={event => confirmDelete(event, application[0], i)}
109109
>

app/components/Header.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const Header: React.FC<HeaderProps> = React.memo(({ app, service, setLive, live
7272
<div className={selectModal ? 'dropdown active' : 'dropdown'}>
7373
<div
7474
className={selectModal ? 'select disabled' : 'select'}
75-
onClick={() => !selectModal ? dropdownClickHandler : () => {}}
75+
onClick={() => (!selectModal ? dropdownClickHandler() : () => {})}
7676
>
7777
{service}
7878
</div>
@@ -91,16 +91,7 @@ const Header: React.FC<HeaderProps> = React.memo(({ app, service, setLive, live
9191
/>
9292
</label>
9393
))}
94-
<label htmlFor="communications" className="select">
95-
communications
96-
<input
97-
type="checkbox"
98-
value={'communications'}
99-
id={'communications'}
100-
name={'communications'}
101-
onChange={() => history.replace('communications')}
102-
/>
103-
</label>
94+
10495
<button className="service-button" onClick={handleServices}>
10596
{selectedServices.length === 0 && 'Select Service'}
10697
{selectedServices.length === 1 && 'Display Single'}

0 commit comments

Comments
 (0)