From bcab544f86aee1753ff7f661b101b474212348e0 Mon Sep 17 00:00:00 2001 From: Kangmin An Date: Fri, 20 Aug 2021 12:54:54 +0900 Subject: [PATCH] =?UTF-8?q?Update=20:=20Chart=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C=20=EC=88=98=EC=A0=95.=20=EC=98=88=EC=B8=A1?= =?UTF-8?q?=20=EC=98=A8=EB=8F=84=20=EC=A0=84=EB=8B=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/ChartTabs.js | 55 ++-- client/src/components/LocCodeChange.js | 392 ++++++++++++----------- server/src/controllers/dataController.js | 6 +- 3 files changed, 234 insertions(+), 219 deletions(-) diff --git a/client/src/components/ChartTabs.js b/client/src/components/ChartTabs.js index 514458b..21ca526 100644 --- a/client/src/components/ChartTabs.js +++ b/client/src/components/ChartTabs.js @@ -56,14 +56,13 @@ function ChartTabs() { let date = new Date( new Date(userWeather[i].collected_at).getTime() ); + let hour = date.getHours(); + let minute = date.getMinutes(); + let f_date = `${hour < 10 ? `0${hour}` : hour}:${ + minute < 10 ? `0${minute}` : minute + }`; - tempLabelArray.push( - `${date.getHours()}:${ - date.getMinutes() < 10 - ? `0${date.getMinutes()}` - : date.getMinutes() - }` - ); + tempLabelArray.push(f_date); labelArray.push(`${date.getHours()}:${date.getMinutes()}`); } for (let j = 0; j < userWeatherPredict.length; j++) { @@ -71,15 +70,18 @@ function ChartTabs() { let date = new Date( new Date(userWeatherPredict[j].collected_at).getTime() ); - tempLabelArray.push( - `${date.getHours()}:${ - date.getMinutes() < 10 - ? `0${date.getMinutes()}` - : date.getMinutes() - }` - ); + let hour = date.getHours(); + let minute = date.getMinutes(); + let f_date = `${hour < 10 ? `0${hour}` : hour}:${ + minute < 10 ? `0${minute}` : minute + }`; + tempLabelArray.push(f_date); } + console.log(tempLabelArray); + console.log(userWeather); + console.log(userWeatherPredict); + setTemp(tempArray); setHumi(humiArray); setPress(pressArray); @@ -107,23 +109,18 @@ function ChartTabs() { windspeedArray.push(outWeather[i].wind_speed); let date = new Date(new Date(outWeather[i].collected_at).getTime()); - - tempLabelArray.push( - `${date.getHours()}:${ - date.getMinutes() < 10 - ? `0${date.getMinutes()}` - : date.getMinutes() - }` - ); - labelArray.push( - `${date.getHours()}:${ - date.getMinutes() < 10 - ? `0${date.getMinutes()}` - : date.getMinutes() - }` - ); + let hour = date.getHours(); + let minute = date.getMinutes(); + let f_date = `${hour < 10 ? `0${hour}` : hour}:${ + minute < 10 ? `0${minute}` : minute + }`; + + tempLabelArray.push(f_date); + labelArray.push(f_date); } + console.log(tempLabelArray); + setTemp(tempArray); setHumi(humiArray); setPress(pressArray); diff --git a/client/src/components/LocCodeChange.js b/client/src/components/LocCodeChange.js index 71943f4..dc3934d 100644 --- a/client/src/components/LocCodeChange.js +++ b/client/src/components/LocCodeChange.js @@ -1,197 +1,213 @@ -import React, { useEffect, useState } from 'react' -import '../App.css' -import { Form, Button, Row, Col, Card } from 'react-bootstrap'; -import axios from 'axios'; -import Swal from 'sweetalert2' -import { callUserInfo } from '../utils/CheckDB'; -import { routesClient } from '../routesClient'; - +import React, { useEffect, useState } from "react"; +import "../App.css"; +import { Form, Button, Row, Col, Card } from "react-bootstrap"; +import axios from "axios"; +import Swal from "sweetalert2"; +import { callUserInfo } from "../utils/CheckDB"; +import { routesClient } from "../routesClient"; function LocCodeChange() { - - const cardstyled = { - margin: 'auto', - padding: '1em', - display: 'flex', - justifyContent: 'center', - width: '100%', - borderWidth: '3px', - borderRadius: '20px', - borderColor: 'rgb(110, 189, 142)', - color: '#04AB70' - } - - const inboxstyled = { - display: 'flex', - flexDirection: 'column', - maxWidth: '90%', - justifyContent: 'center', - margin: 'auto', - padding: '0.5em', - color: 'black' - } - - const btnstyled2 = { - background: 'white', - width: '50%', - borderWidth: '2px', - color: 'rgb(110, 189, 142)', - borderColor: 'rgba(195, 195, 195, 0.753)', + const cardstyled = { + margin: "auto", + padding: "1em", + display: "flex", + justifyContent: "center", + width: "100%", + borderWidth: "3px", + borderRadius: "20px", + borderColor: "rgb(110, 189, 142)", + color: "#04AB70", + }; + + const inboxstyled = { + display: "flex", + flexDirection: "column", + maxWidth: "90%", + justifyContent: "center", + margin: "auto", + padding: "0.5em", + color: "black", + }; + + const btnstyled2 = { + background: "white", + width: "50%", + borderWidth: "2px", + color: "rgb(110, 189, 142)", + borderColor: "rgba(195, 195, 195, 0.753)", + }; + + const [does, setDoes] = useState([]); // DOE + const [sggs, setSggs] = useState([]); // SGG + const [emds, setEmds] = useState([]); // EMD + const [sggsArray, setSggsArray] = useState([]); // DOE 와 SGG 내의 code_doe 같을 때 => sgg 값 + const [emdsArray, setEmdsArray] = useState([]); // SGG 과 EMD 내의 code_sgg && DOE 와 EMD 내의 code_doe => emd 값 + + const doeSelect = document.getElementById("select-doe"); + const sggSelect = document.getElementById("select-sgg"); + const emdSelect = document.getElementById("select-emd"); + + // Local code 받아오기 + useEffect(() => { + async function getLocCode() { + const res = await axios.get(routesClient.localdata); + const local_codes = res.data.contents.loc_code; + + setDoes(local_codes.DOE); + setSggs(local_codes.SGG); + setEmds(local_codes.EMD); } - const [does, setDoes] = useState([]) // DOE - const [sggs, setSggs] = useState([]) // SGG - const [emds, setEmds] = useState([]) // EMD - const [sggsArray, setSggsArray] = useState([]) // DOE 와 SGG 내의 code_doe 같을 때 => sgg 값 - const [emdsArray, setEmdsArray] = useState([]) // SGG 과 EMD 내의 code_sgg && DOE 와 EMD 내의 code_doe => emd 값 - - const doeSelect = document.getElementById('select-doe') - const sggSelect = document.getElementById('select-sgg') - const emdSelect = document.getElementById('select-emd') - - // Local code 받아오기 - useEffect(() => { - async function getLocCode() { - const res = await axios.get(routesClient.localdata) - const local_codes = res.data.contents.loc_code - - setDoes(local_codes.DOE) - setSggs(local_codes.SGG) - setEmds(local_codes.EMD) - } - - getLocCode() - }, []) - - function selectLocal() { - sggs.map(function (sggvalue) { - if (Number(doeSelect.value) === sggvalue['code_doe']) { - setSggsArray(sggvalue['sgg']) + getLocCode(); + }, []); + + function selectLocal() { + sggs.map(function (sggvalue) { + if (Number(doeSelect.value) === sggvalue["code_doe"]) { + setSggsArray(sggvalue["sgg"]); + } + }); + emds.map(function (emdvalue) { + if ( + Number(sggSelect.value) === emdvalue["code_sgg"] && + Number(doeSelect.value) === emdvalue["code_doe"] + ) { + setEmdsArray(emdvalue["emd"]); + } + }); + } + + async function handleSubmit(event) { + event.preventDefault(); + if ( + doeSelect.options[doeSelect.selectedIndex].text !== "도" && + sggSelect.options[sggSelect.selectedIndex].text !== "시군구" && + emdSelect.options[emdSelect.selectedIndex].text !== "읍면동" + ) { + const saveCodeEmd = emdSelect.value; + + await axios.post(routesClient.edit, { loc_code: saveCodeEmd }); // loccal code 수정 + + callUserInfo().then((res) => { + console.log("loc_code", res[0].loc_code); + if (res[0].loc_code) { + Swal.fire({ + title: "변경되었습니다.", + text: "축하드립니다!👏", + icon: "success", + customClass: "swal-wide", + confirmButtonText: "확인", + }).then((res) => { + if (res.isConfirmed) { + window.location.reload(); + } else { + window.location.reload(); } - }) - emds.map(function (emdvalue) { - if ((Number(sggSelect.value) === emdvalue['code_sgg']) - && (Number(doeSelect.value) === emdvalue['code_doe'])) { - setEmdsArray(emdvalue['emd']) - } - }) - } - - - async function handleSubmit(event) { - event.preventDefault() - if (doeSelect.options[doeSelect.selectedIndex].text !== '도' - && sggSelect.options[sggSelect.selectedIndex].text !== '시군구' - && emdSelect.options[emdSelect.selectedIndex].text !== '읍면동') { - - const saveCodeEmd = emdSelect.value - - await axios.post(routesClient.edit, { loc_code: saveCodeEmd }) // loccal code 수정 - - callUserInfo().then((res) => { - console.log('loc_code', res[0].loc_code) - if (res[0].loc_code) { - Swal.fire({ - title: '변경되었습니다.', - text: '축하드립니다!👏', - icon: 'success', - customClass: 'swal-wide', - confirmButtonText: '확인', - }).then((res) => { - if (res.isConfirmed) { - window.location.replace('/') - } - else { - window.location.replace('/') - } - }) - } - }) - - - } - else { - Swal.fire({ - title: '실패', - text: '전부 선택해주세요', - icon: 'error', - customClass: 'swal-wide', - confirmButtonText: '확인' - }) + }); } - + }); + } else { + Swal.fire({ + title: "실패", + text: "전부 선택해주세요", + icon: "error", + customClass: "swal-wide", + confirmButtonText: "확인", + }); } - - - - - - return ( - - - - 지역 코드 - - - 본인의 지역을 선택해주세요 - -
- -
- - - - - - - - { - does.map((doevalue) => ( - - )) - } - - - - - - - { - sggsArray.map((sggvalue) => ( - - )) - } - - - - - - - { - emdsArray.map((emdvalue) => ( - - )) - } - - - - - - -
-
-
-
- ) + } + + return ( + + + 지역 코드 + + 본인의 지역을 선택해주세요 + +
+ +
+ + + + + + + {does.map((doevalue) => ( + + ))} + + + + + + + {sggsArray.map((sggvalue) => ( + + ))} + + + + + + + {emdsArray.map((emdvalue) => ( + + ))} + + + + + + +
+
+
+
+ ); } -export default LocCodeChange; \ No newline at end of file +export default LocCodeChange; diff --git a/server/src/controllers/dataController.js b/server/src/controllers/dataController.js index 5231a45..53d9921 100644 --- a/server/src/controllers/dataController.js +++ b/server/src/controllers/dataController.js @@ -156,13 +156,15 @@ export const getUserWeatherData = async (req, res) => { pyprocess.stdout.on("data", (data) => { let weather_predict = []; - const str_result = data.toString(); - let temp_predict = str_result.trim(); + let temp_predict = data.toString(); temp_predict = temp_predict.replace("]]", ""); temp_predict = temp_predict.replace("[[", ""); + temp_predict = temp_predict.trim(); temp_predict = temp_predict.split(" "); + temp_predict = temp_predict.filter((val) => val.length > 0); + let date_10m = new Date(weather[weather.length - 1]["collected_at"]); date_10m.setMinutes(date_10m.getMinutes() + 10); -- GitLab