Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
eue
Commits
2cc99e71
Commit
2cc99e71
authored
Aug 04, 2021
by
KangMin An
Browse files
Update: 외부 날씨 저장 스케줄 생성. 외부 날씨 확인 경로 작성.
parent
dbb80397
Changes
3
Hide whitespace changes
Inline
Side-by-side
server/API명세서.md
View file @
2cc99e71
...
...
@@ -7,7 +7,7 @@
| Root | ﹒ | /api | 서버의 기본 경로 |
| Data Collector | GET | /data/input?... | 아두이노를 통해 수집한 자료 등록 (내부, 외부는 쿼리로 구분) |
| Data | GET | /data/user | 사용자 지정 장소의 날씨 데이터 요청 |
| Data | GET | /data/outside?loc
C
ode | 해당 지역구의 날씨 데이터 요청 |
| Data | GET | /data/outside?loc
c
ode | 해당 지역구의 날씨 데이터 요청 |
| Data | GET | /data/loccode | 행정 구역 코드 요청 |
| Auth | POST | /signup | 회원가입 요청 |
| Auth | POST | /login | 로그인 요청 |
...
...
server/src/controllers/dataController.js
View file @
2cc99e71
...
...
@@ -5,7 +5,7 @@ import jwt from "jsonwebtoken";
import
resForm
from
"
../resForm
"
;
// 외부 수집기로 부터 들어온 정보 처리
const
handleOutData
=
async
(
locCode
,
date
,
lat
,
lng
)
=>
{
export
const
handleOutData
=
async
(
locCode
,
date
,
lat
,
lng
)
=>
{
try
{
// OpenWeatherAPI로 부터 지역의 날씨 정보획득을 위해 지역의 경도와 위도, API Key, 단위 기준 metric 전달
const
response
=
await
fetch
(
...
...
@@ -31,6 +31,8 @@ const handleOutData = async (locCode, date, lat, lng) => {
logging
:
false
,
}
);
console
.
log
(
"
Outside data successfully stored.
"
);
}
catch
(
err
)
{
console
.
log
(
"
Input Weather_Out Data Error.
"
);
console
.
log
(
err
);
...
...
@@ -52,6 +54,8 @@ const handleInData = async (email, date, temp, humi, lights) => {
logging
:
false
,
}
);
console
.
log
(
"
Inside data successfully stored.
"
);
}
catch
(
err
)
{
console
.
log
(
"
Input Weather_In Data Error.
"
);
console
.
log
(
err
);
...
...
@@ -73,7 +77,6 @@ export const getDataInput = (req, res) => {
`Outside[
${
locCode
}
] Data(date:
${
trans_date
}
/ lat:
${
lat
}
/ lng:
${
lng
}
) Input.`
);
handleOutData
(
locCode
,
trans_date
,
lat
,
lng
);
console
.
log
(
"
Outside data successfully stored.
"
);
}
else
{
// 내부 데이터 수집기 동작
const
{
...
...
@@ -86,12 +89,11 @@ export const getDataInput = (req, res) => {
`User[
${
email
}
] Data(date:
${
trans_date
}
/ temp:
${
temp
}
/ humi:
${
humi
}
/ lights:
${
lights
}
) Input.`
);
handleInData
(
email
,
trans_date
,
temp
,
humi
,
lights
);
console
.
log
(
"
Inside data successfully stored.
"
);
}
res
.
status
(
resForm
.
code
.
ok
);
res
.
status
(
resForm
.
code
.
ok
)
.
json
({
msg
:
resForm
.
msg
.
ok
})
;
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
status
(
resForm
.
code
.
err
);
res
.
status
(
resForm
.
code
.
err
)
.
json
({
msg
:
resForm
.
msg
.
err
})
;
}
};
...
...
@@ -119,12 +121,12 @@ export const getUserWeatherData = (req, res) => {
// 실외 날씨 데이터 요청 처리
export
const
getOutWeatherData
=
async
(
req
,
res
)
=>
{
const
{
query
:
{
loc
C
ode
},
query
:
{
loc
c
ode
},
}
=
req
;
try
{
// 실외 지역 번호를 통해 날씨 데이터 전송.
const
result
=
await
db
.
Weather_Out
.
findAll
({
where
:
{
loc_code
:
loc
C
ode
},
where
:
{
loc_code
:
loc
c
ode
},
order
:
[[
"
collected_at
"
,
"
DESC
"
]],
logging
:
false
,
});
...
...
server/src/schedules.js
View file @
2cc99e71
import
db
from
"
./db/index
"
;
import
envs
from
"
../config/config
"
;
import
schedule
from
"
node-schedule
"
;
import
{
spawn
}
from
"
child_process
"
;
import
dotenv
from
"
dotenv
"
;
dotenv
.
config
();
import
{
handleOutData
}
from
"
./controllers/dataController
"
;
// Data Processing Python Codes Directory - server directory에서 실행
const
DATA_PROCESSING_DIR
=
"
./src/data_processing/main.py
"
;
// 매일 자정에 실행할 스케줄의 규칙
const
rule
=
new
schedule
.
RecurrenceRule
();
rule
.
hour
=
0
;
rule
.
minute
=
0
;
rule
.
second
=
0
;
const
rule
_dataProcessing
=
new
schedule
.
RecurrenceRule
();
rule
_dataProcessing
.
hour
=
0
;
rule
_dataProcessing
.
minute
=
0
;
rule
_dataProcessing
.
second
=
0
;
// 매일 자정에 실행되는 데이터 처리 스케줄
const
dataProcessingJob
=
schedule
.
scheduleJob
(
rule
,
()
=>
{
const
dataProcessingJob
=
schedule
.
scheduleJob
(
rule
_dataProcessing
,
()
=>
{
const
today
=
new
Date
();
console
.
log
(
...
...
@@ -25,10 +25,10 @@ const dataProcessingJob = schedule.scheduleJob(rule, () => {
const
pyprocess
=
spawn
(
"
python
"
,
[
DATA_PROCESSING_DIR
,
process
.
env
.
MYSQL_HOST
,
process
.
env
.
MYSQL_USER
,
process
.
env
.
MYSQL_PASSWORD
,
process
.
env
.
MYSQL_DATABASE
,
envs
.
db
.
host
,
envs
.
db
.
user
,
envs
.
db
.
password
,
envs
.
db
.
database
,
]);
pyprocess
.
stdout
.
on
(
"
data
"
,
(
data
)
=>
{
...
...
@@ -45,3 +45,106 @@ const dataProcessingJob = schedule.scheduleJob(rule, () => {
console
.
log
(
"
The data processing done.
"
);
});
});
// 10분 마다 지역 외부 날씨 저장 스케쥴
const
rules_weather_out_store
=
{
"
00m
"
:
new
schedule
.
RecurrenceRule
(),
"
10m
"
:
new
schedule
.
RecurrenceRule
(),
"
20m
"
:
new
schedule
.
RecurrenceRule
(),
"
30m
"
:
new
schedule
.
RecurrenceRule
(),
"
40m
"
:
new
schedule
.
RecurrenceRule
(),
"
50m
"
:
new
schedule
.
RecurrenceRule
(),
};
rules_weather_out_store
[
"
00m
"
].
minute
=
0
;
rules_weather_out_store
[
"
10m
"
].
minute
=
10
;
rules_weather_out_store
[
"
20m
"
].
minute
=
20
;
rules_weather_out_store
[
"
30m
"
].
minute
=
30
;
rules_weather_out_store
[
"
40m
"
].
minute
=
40
;
rules_weather_out_store
[
"
50m
"
].
minute
=
50
;
// 임의의 사용자 데이터 등록
const
coordinates
=
[
{
lat
:
37.240049
,
lng
:
131.86931
,
locCode
:
3743011
},
{
lat
:
37.206616
,
lng
:
127.037113
,
locCode
:
3124053
},
{
lat
:
37.666729
,
lng
:
127.051501
,
locCode
:
1111072
},
{
lat
:
35.177681
,
lng
:
128.805934
,
locCode
:
3807063
},
];
// 데이터 저장 용 날짜 생성
const
make_date
=
()
=>
{
const
now
=
new
Date
();
const
year
=
now
.
getFullYear
();
const
month
=
now
.
getMonth
()
+
1
<
10
?
`0
${
now
.
getMonth
()
+
1
}
`
:
now
.
getMonth
()
+
1
;
const
date
=
now
.
getDate
()
<
10
?
`0
${
now
.
getDate
()}
`
:
now
.
getDate
();
const
hour
=
now
.
getHours
()
<
10
?
`0
${
now
.
getHours
()}
`
:
now
.
getHours
();
const
minute
=
now
.
getMinutes
()
<
10
?
`0
${
now
.
getMinutes
()}
`
:
now
.
getMinutes
();
const
str_date
=
`
${
year
}
-
${
month
}
-
${
date
}
T
${
hour
}
:
${
minute
}
:00+09:00`
;
const
collected_at
=
new
Date
(
str_date
);
return
collected_at
;
};
// 날씨 저장 스케줄 등록
const
weatherOutStoringJob_00m
=
schedule
.
scheduleJob
(
rules_weather_out_store
[
"
00m
"
],
()
=>
{
const
date
=
make_date
();
coordinates
.
map
(({
lat
,
lng
,
locCode
})
=>
handleOutData
(
locCode
,
date
,
lat
,
lng
)
);
}
);
const
weatherOutStoringJob_10m
=
schedule
.
scheduleJob
(
rules_weather_out_store
[
"
10m
"
],
()
=>
{
const
date
=
make_date
();
coordinates
.
map
(({
lat
,
lng
,
locCode
})
=>
handleOutData
(
locCode
,
date
,
lat
,
lng
)
);
}
);
const
weatherOutStoringJob_20m
=
schedule
.
scheduleJob
(
rules_weather_out_store
[
"
20m
"
],
()
=>
{
const
date
=
make_date
();
coordinates
.
map
(({
lat
,
lng
,
locCode
})
=>
handleOutData
(
locCode
,
date
,
lat
,
lng
)
);
}
);
const
weatherOutStoringJob_30m
=
schedule
.
scheduleJob
(
rules_weather_out_store
[
"
30m
"
],
()
=>
{
const
date
=
make_date
();
coordinates
.
map
(({
lat
,
lng
,
locCode
})
=>
handleOutData
(
locCode
,
date
,
lat
,
lng
)
);
}
);
const
weatherOutStoringJob_40m
=
schedule
.
scheduleJob
(
rules_weather_out_store
[
"
40m
"
],
()
=>
{
const
date
=
make_date
();
coordinates
.
map
(({
lat
,
lng
,
locCode
})
=>
handleOutData
(
locCode
,
date
,
lat
,
lng
)
);
}
);
const
weatherOutStoringJob_50m
=
schedule
.
scheduleJob
(
rules_weather_out_store
[
"
50m
"
],
()
=>
{
const
date
=
make_date
();
coordinates
.
map
(({
lat
,
lng
,
locCode
})
=>
handleOutData
(
locCode
,
date
,
lat
,
lng
)
);
}
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment