-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path123
105 lines (93 loc) · 3.1 KB
/
123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React, { useEffect, useState } from "react";
import { CartesianGrid, Legend, Line, LineChart, Tooltip, XAxis, YAxis } from "recharts";
import "./styles.css";
// Function to generate data for the previous day
const getPreviousDayData = () => {
const baseTimestamp = new Date();
baseTimestamp.setDate(baseTimestamp.getDate() - 1); // Set to previous day
const timestamps = Array.from({ length: 63 }, (_, i) => {
const timestamp = new Date(baseTimestamp);
timestamp.setHours(8 + i * 2);
return timestamp.toISOString();
});
return timestamps.map(timestamp => ({
timestamp,
description: "Normal activity",
ipAddress: "10.83.129.233"
}));
};
const Anomaly = () => {
const [data, setData] = useState(getPreviousDayData());
useEffect(() => {
const fetchData = async () => {
// Add the "Location change detected" entry after 1 minute
const newEntry = {
timestamp: new Date().toISOString(),
description: "Location change detected",
ipAddress: "10.83.129.246"
};
setData(prevData => [...prevData, newEntry]);
};
// Add initial "Normal activity" entry for today
const initialEntry = {
timestamp: new Date().toISOString(),
description: "Normal activity",
ipAddress: "10.83.129.233"
};
setData(prevData => [...prevData, initialEntry]);
// Set up a timer to add the location change entry after 1 minute
const timerId = setTimeout(fetchData, 60000); // 60,000 milliseconds = 1 minute
return () => clearTimeout(timerId); // Cleanup on unmount
}, []);
const processDataForChart = () => {
return data.map((item, index) => ({
name: new Date(item.timestamp).toLocaleTimeString(),
anomaly: index + 1
}));
};
return (
<div className="anomaly-page">
<h1>Anomaly Dashboard</h1>
<div className="chart-container">
<div className="chart">
<h2>Anomalies Detected Over Time</h2>
<LineChart
width={600}
height={300}
data={processDataForChart()}
margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
>
<XAxis dataKey="name" />
<CartesianGrid strokeDasharray="3 3" />
<YAxis />
<Tooltip />
<Legend />
<Line type="monotone" dataKey="anomaly" stroke="#8884d8" activeDot={{ r: 8 }} />
</LineChart>
</div>
</div>
<h2>Anomaly Details</h2>
<div className="details">
<table>
<thead>
<tr>
<th>Date & Time</th>
<th>Description</th>
<th>IP Address</th>
</tr>
</thead>
<tbody>
{data.map((item, index) => (
<tr key={index} style={{ color: item.description === "Location change detected" ? "red" : "green" }}>
<td>{new Date(item.timestamp).toLocaleString()}</td>
<td>{item.description}</td>
<td>{item.ipAddress}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
};
export default Anomaly;