diff --git a/src/containers/statistics/AbnormalSituationContainer.js b/src/containers/statistics/AbnormalSituationContainer.js index 02d2534c..77c60074 100644 --- a/src/containers/statistics/AbnormalSituationContainer.js +++ b/src/containers/statistics/AbnormalSituationContainer.js @@ -13,14 +13,21 @@ import { Search } from 'react-feather'; import { FcAlarmClock, FcWorkflow, FcBarChart } from 'react-icons/fc'; import { Bar, Doughnut } from 'react-chartjs-2'; import { useCallback, useEffect, useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import * as StcsActions from '../../modules/statistics/actions'; export default function AbnormalSituationContainer({ tooltipShadow, gridLineColor, labelColor }) { + const dispatch = useDispatch(); + const { abnormal, abnormalSearch } = useSelector( + state => state.statisticsState + ); + const [searchType, setSearchType] = useState({ - abnormalType: '비행경로이탈', + category: 'PLAN', dateType: 'year', year: new Date().getFullYear(), month: new Date().getMonth() + 1, @@ -33,6 +40,10 @@ export default function AbnormalSituationContainer({ const titleName = '비정상상황 통계'; + useEffect(() => { + dispatch(StcsActions.ABNORMAL_STCS.request()); + }, []); + useEffect(() => { const { year, month } = searchType; const lastDay = new Date(year, month, 0).getDate(); @@ -41,18 +52,65 @@ export default function AbnormalSituationContainer({ setDateLists({ ...dateLists, day: dayList }); }, [searchType.month]); + useEffect(() => { + const { category, dateType, year, month, day } = searchType; + + const dateMapping = { + month: year, + day: `${year}-${month}`, + 'one-day': `${year}-${month}-${day}` + }; + const date = dateMapping[dateType] || ''; + + dispatch( + StcsActions.ABNORMAL_STCS_SEARCH.request({ + cate: category, + date, + type: dateType + }) + ); + }, [searchType]); + // 검색조건 handler const handleChangeSearchType = useCallback( (type, val) => { setSearchType({ ...searchType, - [type]: - type === 'dateType' || type === 'abnormalType' ? val : Number(val) + [type]: val }); }, [searchType] ); + // 그래프 타이틀 handler + const handlerTitleName = category => { + const categoryMappings = { + PLAN: '비행경로이탈', + ALTITUDE: '비정상고도', + CRASH: '충돌위험' + }; + return categoryMappings[category]; + }; + + // Bar Graph handler + const handlerBarTicks = () => { + const data = abnormalSearch.graphData.map(i => i.value); + const max = Math.ceil(Math.max(...data) / 10) * 10; + const stepSize = handlerStepSize(max); + + return { max, stepSize }; + }; + + const handlerStepSize = max => { + const exponent = Math.ceil(Math.log10(max)); + return 10 ** (exponent - 1); + }; + + const addCommasToNumber = number => { + if (number === 'noData') return 0; + return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); + }; + const options = { elements: { rectangle: { @@ -101,9 +159,8 @@ export default function AbnormalSituationContainer({ zeroLineColor: gridLineColor }, ticks: { - stepSize: 100, + ...handlerBarTicks(), min: 0, - max: 400, fontColor: labelColor } } @@ -111,22 +168,10 @@ export default function AbnormalSituationContainer({ } }, data = { - labels: [ - '7/12', - '8/12', - '9/12', - '10/12', - '11/12', - '12/12', - '13/12', - '14/12', - '15/12', - '16/12', - '17/12' - ], + labels: abnormalSearch.graphData.map(i => i.name), datasets: [ { - data: [275, 90, 190, 205, 125, 85, 55, 87, 127, 150, 230, 280, 190], + data: abnormalSearch.graphData.map(i => i.value), backgroundColor: '#00bcd4', borderColor: '#00bcd4', barThickness: 15 @@ -156,7 +201,7 @@ export default function AbnormalSituationContainer({ label(tooltipItem, data) { const label = data.datasets[0].labels[tooltipItem.index] || '', value = data.datasets[0].data[tooltipItem.index]; - const output = ` ${label} : ${value} %`; + const output = ` ${label} : ${value}건`; return output; } }, @@ -170,11 +215,11 @@ export default function AbnormalSituationContainer({ } }, data2 = { - labels: ['PA0001', 'PA0002', 'PA0003', 'PA0004', 'PA0005'], + labels: abnormalSearch.topData.map(i => i.name), datasets: [ { - labels: ['PA0001', 'PA0002', 'PA0003', 'PA0004', 'PA0005'], - data: [10, 20, 30, 40, 80], + labels: abnormalSearch.topData.map(i => i.name), + data: abnormalSearch.topData.map(i => i.value), //레드버전 // backgroundColor: [ // '#ffe8d1', @@ -202,7 +247,63 @@ export default function AbnormalSituationContainer({
+ {idx === 0 ? (
+ <>
+
+ |
+ + 년 + + {addCommasToNumber(i.year)}건 + + | +||
---|---|---|---|
+ 월 + + {addCommasToNumber(i.month)}건 + + | ++ 일 + + {addCommasToNumber(i.day)}건 + + | +