-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from boostcampwm2023/develop
[Deploy] week5 목요일 배포
- Loading branch information
Showing
65 changed files
with
1,343 additions
and
301 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/admin/src/components/ExceptionStatistics/ExceptionChart/ExceptionChart.styles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export const Select = styled.select` | ||
margin-top: 20px; | ||
margin-bottom: 20px; | ||
padding: 5px; | ||
`; |
126 changes: 126 additions & 0 deletions
126
packages/admin/src/components/ExceptionStatistics/ExceptionChart/ExceptionChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { Exception, ExceptionConditions } from '../exception.interface.ts'; | ||
import { Bar } from 'react-chartjs-2'; | ||
import { CategoryScale } from 'chart.js'; | ||
import Chart from 'chart.js/auto'; | ||
import React, { useState } from 'react'; | ||
import { Select } from './ExceptionChart.styles.tsx'; | ||
Chart.register(CategoryScale); | ||
|
||
interface PropsType { | ||
exceptionData: Exception[]; | ||
condition: ExceptionConditions; | ||
} | ||
|
||
export default function ExceptionChart({ | ||
exceptionData, | ||
condition, | ||
}: PropsType) { | ||
const filteredExceptionData = filter(exceptionData, condition); | ||
const uniqueDate = getUniqueDate(filteredExceptionData); | ||
|
||
const [option, setOption] = useState('path'); | ||
|
||
const handleChangeOption = (event: React.ChangeEvent<HTMLSelectElement>) => { | ||
setOption(event.target.value); | ||
}; | ||
|
||
return ( | ||
<div style={{ width: '1024px' }}> | ||
<Select onChange={handleChangeOption}> | ||
<option value="path">경로 기준으로 보기</option> | ||
<option value="error">에러 기준으로 보기</option> | ||
</Select> | ||
<Bar | ||
data={{ | ||
labels: uniqueDate, | ||
datasets: getDatasets(filteredExceptionData, uniqueDate, option), | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
function filter( | ||
exceptionData: Exception[], | ||
condition: ExceptionConditions, | ||
): Exception[] { | ||
const filterdData = exceptionData.filter((exception: Exception) => { | ||
const { startDate, endDate } = condition; | ||
const timestamp = new Date(exception.timestamp); | ||
if (!startDate && !endDate) return true; | ||
if (startDate && !endDate) return timestamp >= startDate; | ||
if (!startDate && endDate) return timestamp <= endDate; | ||
if (startDate && endDate) | ||
return timestamp >= startDate && timestamp <= endDate; | ||
}); | ||
return filterdData; | ||
} | ||
|
||
function getUniqueDate(exceptionData: Exception[]) { | ||
const uniqueDate = new Set( | ||
exceptionData.map((exception: Exception) => { | ||
return exception.timestamp.toLocaleString().slice(0, 10); | ||
}), | ||
); | ||
return [...uniqueDate]; | ||
} | ||
|
||
function getDatasets( | ||
exceptionData: Exception[], | ||
uniqueDate: string[], | ||
option: string, | ||
) { | ||
if (option === 'path') { | ||
const uniquePathList = new Set( | ||
exceptionData.map((exception: Exception) => exception.path), | ||
); | ||
const datasets = [...uniquePathList].map((path: string) => { | ||
const filteredData = uniqueDate.map((date: string) => { | ||
return exceptionData.filter( | ||
(exception: Exception) => | ||
exception.path === path && | ||
exception.timestamp.toLocaleString().slice(0, 10) === date, | ||
); | ||
}); | ||
const randomColor = getRandomColor(); | ||
return { | ||
label: path, | ||
data: filteredData.map((data: Exception[]) => data.length), | ||
backgroundColor: randomColor, | ||
borderColor: randomColor, | ||
borderWidth: 1, | ||
}; | ||
}); | ||
return datasets; | ||
} | ||
|
||
const uniqueErrorList = new Set( | ||
exceptionData.map((exception: Exception) => exception.error), | ||
); | ||
const datasets = [...uniqueErrorList].map((error: string) => { | ||
const filteredData = uniqueDate.map((date: string) => { | ||
return exceptionData.filter( | ||
(exception: Exception) => | ||
exception.error === error && | ||
exception.timestamp.toLocaleString().slice(0, 10) === date, | ||
); | ||
}); | ||
const randomColor = getRandomColor(); | ||
return { | ||
label: error, | ||
data: filteredData.map((data: Exception[]) => data.length), | ||
backgroundColor: randomColor, | ||
borderColor: randomColor, | ||
borderWidth: 1, | ||
}; | ||
}); | ||
return datasets; | ||
} | ||
|
||
function getRandomColor() { | ||
const r = Math.floor(Math.random() * 256); | ||
const g = Math.floor(Math.random() * 256); | ||
const b = Math.floor(Math.random() * 256); | ||
|
||
return `rgb(${r}, ${g}, ${b})`; | ||
} |
Oops, something went wrong.