From 80816006f5afe45fe4ce015fd5fbfa1d914fff63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sanguu=28=EB=B0=95=EC=83=81=ED=98=84=29?= Date: Thu, 3 Nov 2022 10:56:15 +0900 Subject: [PATCH] =?UTF-8?q?=EB=93=9C=EB=A1=A0=EA=B4=80=EC=A0=9C=20?= =?UTF-8?q?=EB=82=A0=EC=94=A8=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../control/gp/models/controlGpModel.ts | 7 +- .../control/gp/reducers/controlGpReducer.ts | 1 - src/modules/control/gp/sagas/controlGpSaga.ts | 19 ++- .../control/report/ControlReportDetail.js | 161 ++++++++++-------- test/pav-warning.js | 106 ++++++------ 5 files changed, 161 insertions(+), 133 deletions(-) diff --git a/src/modules/control/gp/models/controlGpModel.ts b/src/modules/control/gp/models/controlGpModel.ts index 95ad85a..fbd3dbe 100644 --- a/src/modules/control/gp/models/controlGpModel.ts +++ b/src/modules/control/gp/models/controlGpModel.ts @@ -54,6 +54,7 @@ export interface ControlDetailData { ownerNm: string; hpno: string; telno: string; + items: []; } export interface ControlGpDtlData { @@ -100,12 +101,6 @@ export interface ControlGpData { controlWarnNotyCd: boolean; } export interface ControlweatherData { - serviceKey: string; - numOfRows: string; - pageNo: string; - dataType: string; - base_date: string; - base_time: string; nx: string; ny: string; } diff --git a/src/modules/control/gp/reducers/controlGpReducer.ts b/src/modules/control/gp/reducers/controlGpReducer.ts index 772e838..2817ff6 100644 --- a/src/modules/control/gp/reducers/controlGpReducer.ts +++ b/src/modules/control/gp/reducers/controlGpReducer.ts @@ -113,7 +113,6 @@ export const controlGpDtlReducer = createReducer< .handleAction(controlGpDtlAction.success, (state, action) => produce(state, draft => { const data: ControlDetailData = action.payload; - draft.controlDetail = data; }) ); diff --git a/src/modules/control/gp/sagas/controlGpSaga.ts b/src/modules/control/gp/sagas/controlGpSaga.ts index 759f459..ddc58b9 100644 --- a/src/modules/control/gp/sagas/controlGpSaga.ts +++ b/src/modules/control/gp/sagas/controlGpSaga.ts @@ -119,9 +119,26 @@ function* controlDtlSaga( ) { try { const controlId = action.payload; + const state = yield select(); + const { controlGpList } = state.controlGpState; + const a = controlGpList.filter(i => i.controlId === controlId); + const lat = a[0].lat; + const lng = a[0].lng; + + const rq = { + nx: lat, + ny: lng + }; + //날씨 api 호출 + const res = yield call(controlGpApi.apiweather, rq); const { data } = yield call(controlGpApi.getDetail, controlId); - yield put(Actions.controlGpDtlAction.success(data)); + yield put( + Actions.controlGpDtlAction.success({ + ...data, + items: res.response.body.items + }) + ); } catch (error) { yield put(Actions.controlGpDtlAction.failure(error)); } diff --git a/src/views/control/report/ControlReportDetail.js b/src/views/control/report/ControlReportDetail.js index e6b4172..81f0563 100644 --- a/src/views/control/report/ControlReportDetail.js +++ b/src/views/control/report/ControlReportDetail.js @@ -1,5 +1,5 @@ import moment from 'moment'; -import React from 'react'; +import React, { useMemo } from 'react'; import { useState, useEffect } from 'react'; import { X } from 'react-feather'; import { useDispatch, useSelector } from 'react-redux'; @@ -33,77 +33,94 @@ const ControlReportDetail = props => { const { controlGpDetail, controlDetail } = useSelector( state => state.controlGpDtlState ); - const { controlWheather } = useSelector(state => state.ControlGpWeatherState); + //const { controlWheather } = useSelector(state => state.ControlGpWeatherState); const { controlGpWarnLog } = useSelector(state => state.controlGpLogState); - useEffect(() => { - if (controlGpDetail) { - const rs = dfsxyconv("toXY", controlGpDetail?.lat, controlGpDetail?.lng); - let now = new Date(); - let year = now.getFullYear(); // 년도 - let month = now.getMonth() + 1; // 월 - let day = ('0' + now.getDate()).slice(-2); // 날짜 - const today = `${year}${month}${day}`; - let hours = now.getHours(); - let minutes = now.getMinutes(); - let basetime = "2300"; - if ((hours >= 2 && minutes > 9) && hours <= 5) { - basetime = "0200"; - } - else if ((hours >= 5 && minutes > 9) && hours < 8) { - basetime = "0500"; - } - else if (hours >= 8 && minutes < 10) { - basetime = "0500"; - } - else if ((hours >= 8 && minutes > 9) && hours < 11) { - basetime = "0800"; - } - else if (hours >= 11 && minutes < 10) { - basetime = "0800"; - } - else if (hours >= 11 && hours < 14) { - basetime = "1100"; - } - else if (hours >= 14 && minutes < 10) { - basetime = "1100"; - } - else if ((hours >= 14 && minutes > 9) && hours < 17) { - basetime = "1400"; - } - else if (hours >= 17 && minutes < 10) { - basetime = "1400"; - } - else if ((hours >= 17 && minutes > 9) && hours < 20) { - basetime = "1700"; - } - else if (hours >= 20 && minutes < 10) { - basetime = "2000"; - } - else if ((hours >= 20 && minutes > 9) && hours < 23) { - basetime = "2000"; - } - else if (hours >= 23 && minutes < 10) { - basetime = "2300"; - } - else if (hours >= 23 && minutes > 9) { - basetime = "2300"; - } - const apidata = { - serviceKey: "r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4%2F45y0uVNw6BaYbgpKmL%2BLUDFVTfIYUmEe4K%2FaniEjdV9mg5t82Q%3D%3D", - numOfRows: 14, - pageNo: 1, - dataType: "JSON", - base_date: today, - base_time: basetime, - nx: rs.x, - ny: rs.y, - } - dispatch(controlweatherAction.request(apidata)); + function a() { + if (controlDetail) { + let wheatherDetail = controlDetail.items.item; + let skyDetail = wheatherDetail[6].fcstValue; + if (skyDetail == 1 || skyDetail == 2 || skyDetail == 4) { + return ; + } else if (skyDetail == 4) { + return ; + } else if (skyDetail == 0 || wheatherDetail[5].fcstValue == 1) { + return ; + } else + return ; } + } + // console.log("time", time); + // useEffect(() => { + // if (controlGpDetail) { + // const rs = dfsxyconv("toXY", controlGpDetail?.lat, controlGpDetail?.lng); + // let now = new Date(); + // let year = now.getFullYear(); // 년도 + // let month = now.getMonth() + 1; // 월 + // let day = ('0' + now.getDate()).slice(-2); // 날짜 + // const today = `${year}${month}${day}`; + + // let hours = now.getHours(); + // let minutes = now.getMinutes(); + // let basetime = "2300"; + + // if ((hours >= 2 && minutes > 9) && hours <= 5) { + // basetime = "0200"; + // } + // else if ((hours >= 5 && minutes > 9) && hours < 8) { + // basetime = "0500"; + // } + // else if (hours >= 8 && minutes < 10) { + // basetime = "0500"; + // } + // else if ((hours >= 8 && minutes > 9) && hours < 11) { + // basetime = "0800"; + // } + // else if (hours >= 11 && minutes < 10) { + // basetime = "0800"; + // } + // else if (hours >= 11 && hours < 14) { + // basetime = "1100"; + // } + // else if (hours >= 14 && minutes < 10) { + // basetime = "1100"; + // } + // else if ((hours >= 14 && minutes > 9) && hours < 17) { + // basetime = "1400"; + // } + // else if (hours >= 17 && minutes < 10) { + // basetime = "1400"; + // } + // else if ((hours >= 17 && minutes > 9) && hours < 20) { + // basetime = "1700"; + // } + // else if (hours >= 20 && minutes < 10) { + // basetime = "2000"; + // } + // else if ((hours >= 20 && minutes > 9) && hours < 23) { + // basetime = "2000"; + // } + // else if (hours >= 23 && minutes < 10) { + // basetime = "2300"; + // } + // else if (hours >= 23 && minutes > 9) { + // basetime = "2300"; + // } + // const apidata = { + // serviceKey: "r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4%2F45y0uVNw6BaYbgpKmL%2BLUDFVTfIYUmEe4K%2FaniEjdV9mg5t82Q%3D%3D", + // numOfRows: 14, + // pageNo: 1, + // dataType: "JSON", + // base_date: today, + // base_time: basetime, + // nx: rs.x, + // ny: rs.y, + // } + // dispatch(controlweatherAction.request(apidata)); + // } - }, [controlGpDetail]) + // }, [controlGpDetail]) useEffect(() => { if (historyModal) { @@ -335,11 +352,11 @@ const ControlReportDetail = props => { - 15시 - - 27℃ - - 2m/s + {controlDetail?.items.item[12].fcstTime.substring(0, 2)}시 + {a()} + {controlDetail?.items.item[12].fcstValue}℃ + + {controlDetail?.items.item[4].fcstValue}m/s diff --git a/test/pav-warning.js b/test/pav-warning.js index 98cf829..c3fb80d 100644 --- a/test/pav-warning.js +++ b/test/pav-warning.js @@ -2,82 +2,82 @@ const { getConnection, writeData } = require('./pav-client'); const { getCoordsFormBetweenCoord, dumyData } = require('./pav-utils'); // const host = "192.168.0.24" -// const host = "localhost" -const host = '192.168.0.34'; +const host = "localhost" +// const host = '192.168.0.34'; const port = 8082; // 기본정보 -const prefix = 'PA'; +const prefix = 'PASANGUU'; const pathSampleCoord = [ - [37.5215, 126.605], - [37.5215, 126.61], - // [37.5215, 126.6082], - [37.521, 126.6082], - [37.521, 126.6057], - [37.5205, 126.6057], - [37.5205, 126.6082], - [37.52, 126.6082], - [37.52, 126.6057], - [37.5195, 126.6057], - [37.5195, 126.6082], - [37.519, 126.6082], - [37.519, 126.605] + [37.5215, 126.605], + [37.5215, 126.61], + // [37.5215, 126.6082], + [37.521, 126.6082], + [37.521, 126.6057], + [37.5205, 126.6057], + [37.5205, 126.6082], + [37.52, 126.6082], + [37.52, 126.6057], + [37.5195, 126.6057], + [37.5195, 126.6082], + [37.519, 126.6082], + [37.519, 126.605] ]; const divDist = 10; // [m] // 특정거리에 따른 좌표 추출 const getCoords = coords => { - if (!coords || coords.length < 1) return; - const totalCoords = []; - for (let i = 1; i < coords.length; i++) { - const divCoords = getCoordsFormBetweenCoord( - coords[i - 1], - coords[i], - divDist - ); - totalCoords.push(...divCoords); - } - return totalCoords; + if (!coords || coords.length < 1) return; + const totalCoords = []; + for (let i = 1; i < coords.length; i++) { + const divCoords = getCoordsFormBetweenCoord( + coords[i - 1], + coords[i], + divDist + ); + totalCoords.push(...divCoords); + } + return totalCoords; }; const getClient = () => { - const dronName = prefix + '003'; - // const dronName = prefix + '0000001A'; + const dronName = prefix; + // const dronName = prefix + '0000001A'; - const client = {}; - client.dronName = dronName; - client.socket = getConnection(dronName, host, port); - client.data = getCoords(pathSampleCoord); - return client; + const client = {}; + client.dronName = dronName; + client.socket = getConnection(dronName, host, port); + client.data = getCoords(pathSampleCoord); + return client; }; const sendData = (client, cnt) => { - const data = { - ...dumyData, - terminalId: client.dronName, - body: [ - { - ...dumyData.body[0], - objectId: client.dronName, - lat: client.data[cnt][0], - lon: client.data[cnt][1] - } - ] - }; - writeData(client.socket, JSON.stringify(data)); - iteratorSendData(++cnt); + const data = { + ...dumyData, + terminalId: client.dronName, + body: [ + { + ...dumyData.body[0], + objectId: client.dronName, + lat: client.data[cnt][0], + lon: client.data[cnt][1] + } + ] + }; + writeData(client.socket, JSON.stringify(data)); + iteratorSendData(++cnt); }; const client = getClient(); const iteratorSendData = (cnt = 0) => { - if (cnt >= client.data.length) { - client.socket.destroy(); - return; - } - setTimeout(() => sendData(client, cnt), 1000); + if (cnt >= client.data.length) { + client.socket.destroy(); + return; + } + setTimeout(() => sendData(client, cnt), 1000); }; iteratorSendData();