Browse Source

드론관제 날씨 기능

pull/2/head
sanguu(박상현) 2 years ago
parent
commit
80816006f5
  1. 7
      src/modules/control/gp/models/controlGpModel.ts
  2. 1
      src/modules/control/gp/reducers/controlGpReducer.ts
  3. 19
      src/modules/control/gp/sagas/controlGpSaga.ts
  4. 161
      src/views/control/report/ControlReportDetail.js
  5. 106
      test/pav-warning.js

7
src/modules/control/gp/models/controlGpModel.ts

@ -54,6 +54,7 @@ export interface ControlDetailData {
ownerNm: string; ownerNm: string;
hpno: string; hpno: string;
telno: string; telno: string;
items: [];
} }
export interface ControlGpDtlData { export interface ControlGpDtlData {
@ -100,12 +101,6 @@ export interface ControlGpData {
controlWarnNotyCd: boolean; controlWarnNotyCd: boolean;
} }
export interface ControlweatherData { export interface ControlweatherData {
serviceKey: string;
numOfRows: string;
pageNo: string;
dataType: string;
base_date: string;
base_time: string;
nx: string; nx: string;
ny: string; ny: string;
} }

1
src/modules/control/gp/reducers/controlGpReducer.ts

@ -113,7 +113,6 @@ export const controlGpDtlReducer = createReducer<
.handleAction(controlGpDtlAction.success, (state, action) => .handleAction(controlGpDtlAction.success, (state, action) =>
produce(state, draft => { produce(state, draft => {
const data: ControlDetailData = action.payload; const data: ControlDetailData = action.payload;
draft.controlDetail = data; draft.controlDetail = data;
}) })
); );

19
src/modules/control/gp/sagas/controlGpSaga.ts

@ -119,9 +119,26 @@ function* controlDtlSaga(
) { ) {
try { try {
const controlId = action.payload; 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); 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) { } catch (error) {
yield put(Actions.controlGpDtlAction.failure(error)); yield put(Actions.controlGpDtlAction.failure(error));
} }

161
src/views/control/report/ControlReportDetail.js

@ -1,5 +1,5 @@
import moment from 'moment'; import moment from 'moment';
import React from 'react'; import React, { useMemo } from 'react';
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { X } from 'react-feather'; import { X } from 'react-feather';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
@ -33,77 +33,94 @@ const ControlReportDetail = props => {
const { controlGpDetail, controlDetail } = useSelector( const { controlGpDetail, controlDetail } = useSelector(
state => state.controlGpDtlState state => state.controlGpDtlState
); );
const { controlWheather } = useSelector(state => state.ControlGpWeatherState); //const { controlWheather } = useSelector(state => state.ControlGpWeatherState);
const { controlGpWarnLog } = useSelector(state => state.controlGpLogState); 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) { function a() {
basetime = "0200"; if (controlDetail) {
} let wheatherDetail = controlDetail.items.item;
else if ((hours >= 5 && minutes > 9) && hours < 8) { let skyDetail = wheatherDetail[6].fcstValue;
basetime = "0500"; if (skyDetail == 1 || skyDetail == 2 || skyDetail == 4) {
} return <CloudRain />;
else if (hours >= 8 && minutes < 10) { } else if (skyDetail == 4) {
basetime = "0500"; return <CloudSnow />;
} } else if (skyDetail == 0 || wheatherDetail[5].fcstValue == 1) {
else if ((hours >= 8 && minutes > 9) && hours < 11) { return <Sun />;
basetime = "0800"; } else
} return <Cloud />;
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));
} }
}
// 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(() => { useEffect(() => {
if (historyModal) { if (historyModal) {
@ -335,11 +352,11 @@ const ControlReportDetail = props => {
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>15</td> <td>{controlDetail?.items.item[12].fcstTime.substring(0, 2)}</td>
<td><Sun /></td> <td>{a()}</td>
<td>27</td> <td>{controlDetail?.items.item[12].fcstValue}</td>
<td><Navigation2 className="rotate-45" /></td> <td><Navigation2 style={{ transform: `rotate(${controlDetail?.items.item[3].fcstValue}deg)` }} /></td>
<td>2m/s</td> <td>{controlDetail?.items.item[4].fcstValue}m/s</td>
</tr> </tr>
</tbody> </tbody>
</Table> </Table>

106
test/pav-warning.js

@ -2,82 +2,82 @@ const { getConnection, writeData } = require('./pav-client');
const { getCoordsFormBetweenCoord, dumyData } = require('./pav-utils'); const { getCoordsFormBetweenCoord, dumyData } = require('./pav-utils');
// const host = "192.168.0.24" // const host = "192.168.0.24"
// const host = "localhost" const host = "localhost"
const host = '192.168.0.34'; // const host = '192.168.0.34';
const port = 8082; const port = 8082;
// 기본정보 // 기본정보
const prefix = 'PA'; const prefix = 'PASANGUU';
const pathSampleCoord = [ const pathSampleCoord = [
[37.5215, 126.605], [37.5215, 126.605],
[37.5215, 126.61], [37.5215, 126.61],
// [37.5215, 126.6082], // [37.5215, 126.6082],
[37.521, 126.6082], [37.521, 126.6082],
[37.521, 126.6057], [37.521, 126.6057],
[37.5205, 126.6057], [37.5205, 126.6057],
[37.5205, 126.6082], [37.5205, 126.6082],
[37.52, 126.6082], [37.52, 126.6082],
[37.52, 126.6057], [37.52, 126.6057],
[37.5195, 126.6057], [37.5195, 126.6057],
[37.5195, 126.6082], [37.5195, 126.6082],
[37.519, 126.6082], [37.519, 126.6082],
[37.519, 126.605] [37.519, 126.605]
]; ];
const divDist = 10; // [m] const divDist = 10; // [m]
// 특정거리에 따른 좌표 추출 // 특정거리에 따른 좌표 추출
const getCoords = coords => { const getCoords = coords => {
if (!coords || coords.length < 1) return; if (!coords || coords.length < 1) return;
const totalCoords = []; const totalCoords = [];
for (let i = 1; i < coords.length; i++) { for (let i = 1; i < coords.length; i++) {
const divCoords = getCoordsFormBetweenCoord( const divCoords = getCoordsFormBetweenCoord(
coords[i - 1], coords[i - 1],
coords[i], coords[i],
divDist divDist
); );
totalCoords.push(...divCoords); totalCoords.push(...divCoords);
} }
return totalCoords; return totalCoords;
}; };
const getClient = () => { const getClient = () => {
const dronName = prefix + '003'; const dronName = prefix;
// const dronName = prefix + '0000001A'; // const dronName = prefix + '0000001A';
const client = {}; const client = {};
client.dronName = dronName; client.dronName = dronName;
client.socket = getConnection(dronName, host, port); client.socket = getConnection(dronName, host, port);
client.data = getCoords(pathSampleCoord); client.data = getCoords(pathSampleCoord);
return client; return client;
}; };
const sendData = (client, cnt) => { const sendData = (client, cnt) => {
const data = { const data = {
...dumyData, ...dumyData,
terminalId: client.dronName, terminalId: client.dronName,
body: [ body: [
{ {
...dumyData.body[0], ...dumyData.body[0],
objectId: client.dronName, objectId: client.dronName,
lat: client.data[cnt][0], lat: client.data[cnt][0],
lon: client.data[cnt][1] lon: client.data[cnt][1]
} }
] ]
}; };
writeData(client.socket, JSON.stringify(data)); writeData(client.socket, JSON.stringify(data));
iteratorSendData(++cnt); iteratorSendData(++cnt);
}; };
const client = getClient(); const client = getClient();
const iteratorSendData = (cnt = 0) => { const iteratorSendData = (cnt = 0) => {
if (cnt >= client.data.length) { if (cnt >= client.data.length) {
client.socket.destroy(); client.socket.destroy();
return; return;
} }
setTimeout(() => sendData(client, cnt), 1000); setTimeout(() => sendData(client, cnt), 1000);
}; };
iteratorSendData(); iteratorSendData();

Loading…
Cancel
Save