Browse Source

value 없는 데이터 필터링

pull/2/head
hhjk00 10 months ago
parent
commit
86a8e8bc7a
  1. 35
      src/components/statistics/StatisticsSearch.js
  2. 4
      src/containers/statistics/FlightContainer.js

35
src/components/statistics/StatisticsSearch.js

@ -32,7 +32,7 @@ export default function StatisticsSearch({
chartInit(); chartInit();
}, [searchData]); }, [searchData]);
const convertToSeconds = timeArr => { const parseTimeToSeconds = timeArr => {
return timeArr.map(time => { return timeArr.map(time => {
const [hours, minutes, seconds] = String(time).split(':').map(Number); const [hours, minutes, seconds] = String(time).split(':').map(Number);
return hours * 3600 + minutes * 60 + seconds; return hours * 3600 + minutes * 60 + seconds;
@ -40,35 +40,34 @@ export default function StatisticsSearch({
}; };
const chartInit = () => { const chartInit = () => {
const { topData, graphData } = searchData;
const filteredData = data =>
data.filter(i => i && !['nodata', 'NoData'].includes(i));
if (searchType.category === 'TIME') { if (searchType.category === 'TIME') {
// ['00:00:00', '12:34:56'] -> [0,45296] 초 단위로 변경 // ['00:00:00', '12:34:56'] -> [0,45296] 초 단위로 변경
const timeGraph = searchData.graphData.map(i => i.value).filter(i => i); const timeGraph = filteredData(graphData.map(i => i.value));
const timeTop = searchData.topData.map(i => i.value).filter(i => i); const timeTop = filteredData(topData.map(i => i.value));
const totalValue = convertToSeconds(timeGraph); const totalValue = parseTimeToSeconds(timeGraph);
const topValue = convertToSeconds(timeTop); const topValue = parseTimeToSeconds(timeTop);
setTotal(totalValue); setTotal(totalValue);
setTop(topValue); setTop(topValue);
} else if (searchType.category === 'DISTANCE') { } else if (searchType.category === 'DISTANCE') {
// [0.0, 0.1] -> [0, 0] // [0.1234, 0.5678] -> [0.1, 0.5]
const distanceTotal = searchData.graphData const distanceTotal = filteredData(graphData.map(i => i.value));
.map(i => i.value) const distanceTop = filteredData(topData.map(i => i.value));
.filter(i => i);
const distanceTop = searchData.topData.map(i => i.value).filter(i => i);
const totalValue = distanceTotal.map(distance => { const totalValue = distanceTotal.map(i => i.toFixed(1));
return distance.toFixed(1); const topValue = distanceTop.map(i => i.toFixed(1));
});
const topValue = distanceTop.map(distance => {
return distance.toFixed(1);
});
setTotal(totalValue); setTotal(totalValue);
setTop(topValue); setTop(topValue);
} else { } else {
setTotal(searchData.graphData.map(i => i.value)); setTotal(filteredData(graphData.map(i => i.value)));
setTop(searchData.topData.map(i => i.value)); setTop(filteredData(topData.map(i => i.value)));
} }
}; };

4
src/containers/statistics/FlightContainer.js

@ -141,8 +141,8 @@ export default function FlightContainer() {
}; };
const secondsToDHMS = time => { const secondsToDHMS = time => {
const days = Math.floor(time / 86400); const days = Math.floor(time / (24 * 3600));
const hours = Math.floor((time % 86400) / 3600); const hours = Math.floor((time % (24 * 3600)) / 3600);
const minutes = Math.floor((time % 3600) / 60); const minutes = Math.floor((time % 3600) / 60);
const seconds = time % 60; const seconds = time % 60;

Loading…
Cancel
Save