Skip to content

Commit 65b2f97

Browse files
authored
Merge pull request #78 from oslabs-beta/Sam/Linting
Fix: handles linting errors
2 parents de6d961 + 9e34959 commit 65b2f97

File tree

3 files changed

+95
-6
lines changed

3 files changed

+95
-6
lines changed

client/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ const App: React.FC = () => {
2323
<Routes>
2424
<Route path="/login" element={<Login setUser={setUser} />} />
2525
<Route path="/signup" element={<SignUp />} />
26-
{user !== null && <>
26+
{/* {user !== null && <> */}
2727
<Route path="/" element={<Home isDarkMode={isDarkMode} />} />
2828
<Route path="/profile" element={<Profile isDarkMode={isDarkMode} user={user} />} />
2929
<Route
3030
path="/events-dashboard"
3131
element={<EventsDashboard isDarkMode={isDarkMode} />}
3232
/>
33-
</>}
33+
{/* </>} */}
3434
</Routes>
3535
</Router>
3636
);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react';
2+
import {
3+
ScatterChart,
4+
Scatter,
5+
XAxis,
6+
YAxis,
7+
CartesianGrid,
8+
Tooltip,
9+
ResponsiveContainer,
10+
Legend,
11+
} from 'recharts';
12+
13+
interface DataPoint {
14+
timestamp: string;
15+
count: number;
16+
}
17+
18+
const dummyData: DataPoint[] = [
19+
{ timestamp: '2024-10-29T09:00:00Z', count: 30 },
20+
{ timestamp: '2024-10-29T09:10:00Z', count: 25 },
21+
{ timestamp: '2024-10-29T09:20:00Z', count: 80 },
22+
{ timestamp: '2024-10-29T09:30:00Z', count: 40 },
23+
{ timestamp: '2024-10-29T09:40:00Z', count: 50 },
24+
{ timestamp: '2024-10-29T09:50:00Z', count: 90 },
25+
{ timestamp: '2024-10-29T10:00:00Z', count: 45 },
26+
];
27+
28+
const isAnomaly = (count: number): boolean => count > 70; // Define a threshold for anomalies
29+
30+
const AnomalyChart: React.FC = () => {
31+
return (
32+
<ResponsiveContainer width="100%" height={300}>
33+
<ScatterChart margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
34+
<CartesianGrid strokeDasharray="3 3" />
35+
<XAxis
36+
dataKey="timestamp"
37+
name="Time"
38+
tickFormatter={(time: string) => new Date(time).toLocaleTimeString()}
39+
/>
40+
<YAxis dataKey="count" name="Event Count" />
41+
<Tooltip cursor={{ strokeDasharray: '3 3' }} />
42+
<Legend />
43+
<Scatter
44+
name="Event Counts"
45+
data={dummyData}
46+
fill="#8884d8"
47+
shape="circle"
48+
>
49+
{dummyData.map((entry, index) => {
50+
const x = new Date(entry.timestamp).getTime();
51+
const y = entry.count;
52+
return (
53+
<circle
54+
key={`dot-${index}`}
55+
cx={x}
56+
cy={y}
57+
r={isAnomaly(entry.count) ? 8 : 4}
58+
fill={isAnomaly(entry.count) ? '#FF0000' : '#0088FE'}
59+
/>
60+
);
61+
})}
62+
</Scatter>
63+
</ScatterChart>
64+
</ResponsiveContainer>
65+
);
66+
};
67+
68+
export default AnomalyChart;

client/src/pages/Home.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
import React, { lazy, useState } from 'react';
2-
import { DragDropContext, Droppable, Draggable, DropResult } from '@hello-pangea/dnd';
2+
import {
3+
DragDropContext,
4+
Droppable,
5+
Draggable,
6+
DropResult,
7+
} from '@hello-pangea/dnd';
38
import { CardState } from '../types';
49

510
const Card = lazy(() => import('../components/Card'));
6-
const UserActivityChart = lazy(() => import('../components/charts/UserActivity'));
11+
const UserActivityChart = lazy(
12+
() => import('../components/charts/UserActivity')
13+
);
714
const HeatMap = lazy(() => import('../components/charts/HeatMap'));
815
const IpAccessCombined = lazy(() => import('../components/IpAccessCombined'));
916
const EventTypeChart = lazy(() => import('../components/charts/EventType'));
1017
const EventSourceChart = lazy(() => import('../components/charts/EventSource'));
18+
const AnomalyChart = lazy(() => import('../components/charts/AnomalyChart'));
1119

1220
const Home: React.FC<{ isDarkMode: boolean }> = ({ isDarkMode }) => {
1321
// State to track the current IP (null means no IP selected)
1422
const [currentIp, setCurrentIp] = useState<string | undefined>();
1523

1624
const [cards, setCards] = useState<CardState[]>([
17-
{ id: 'userActivity', title: 'User Activity', component: <UserActivityChart /> },
25+
{
26+
id: 'userActivity',
27+
title: 'User Activity',
28+
component: <UserActivityChart />,
29+
},
1830
{ id: 'eventTypes', title: 'Event Types', component: <EventTypeChart /> },
19-
{ id: 'eventSources', title: 'Event Sources', component: <EventSourceChart /> },
31+
{
32+
id: 'eventSources',
33+
title: 'Event Sources',
34+
component: <EventSourceChart />,
35+
},
2036
{ id: 'heatMap', title: 'IP Address Heat Map', component: <HeatMap /> },
2137
{
2238
id: 'ipAccess',
@@ -28,6 +44,11 @@ const Home: React.FC<{ isDarkMode: boolean }> = ({ isDarkMode }) => {
2844
/>
2945
),
3046
},
47+
{
48+
id: 'anomalyDetection',
49+
title: 'Anomaly Detection',
50+
component: <AnomalyChart />,
51+
},
3152
]);
3253

3354
const handleDragEnd = (result: DropResult) => {

0 commit comments

Comments
 (0)