곽태식

예보 api 추가및 merge오류 삭제

......@@ -25,7 +25,7 @@ app.use('/',express.static(path.join(__dirname, 'code')));
app.use('/Cname/:Cname/Cbirth',express.static(path.join(__dirname, 'public')));
app.use('/Cname/:Cname/Cbirth',express.static(path.join(__dirname, 'code')));
app.use('/Fname/:Fname/Fbirth',express.static(path.join(__dirname, 'newpublic')));
app.use('/Cname/:Cname/Cbirth',express.static(path.join(__dirname, 'newcode')));
app.use('/Fname/:Fname/Fbirth',express.static(path.join(__dirname, 'newcode')));
app.use('/', indexRouter);
......
const db = require('./db.js');
const secret_key = require('../keys/api_option').weather_key;
const traffic_key = require('../keys/api_option').traffic_key;
//const traffic_key = require('../keys/api_option').traffic_key;
const requesting = require('request');
const lat = "37.239795";
const lon = "127.083240";
......@@ -56,27 +56,27 @@ module.exports = (server, app) => {
}
// 교통사고정보를 받아오는 함수
const req_traffic_API = (year) => {
// const req_traffic_API = (year) => {
//async await 사용하기 위하여 promise 사용
return new Promise((resolve, reject) => {
requesting.get({
// api를 요청할 주소 -- 시크릿키,위도,경도 입력
url: `http://taas.koroad.or.kr/data/rest/accident/death?authKey=${traffic_key}&searchYear=${year}&siDo=${city}&guGun=${town}&type=json`,
json: true
},
//api에게 응답 받았을때 실행되는 callback function
function (err, api_res, api_body) {
//err 존재시 promise reject 호출
if (err) reject(err);
// api의 response이 있을경우 promise resolve 호출
if (api_res) {
console.log("calling traffic api");
resolve(api_body);
}
});
})
}
// return new Promise((resolve, reject) => {
// requesting.get({
// // api를 요청할 주소 -- 시크릿키,위도,경도 입력
// url: `http://taas.koroad.or.kr/data/rest/accident/death?authKey=${traffic_key}&searchYear=${year}&siDo=${city}&guGun=${town}&type=json`,
// json: true
// },
// //api에게 응답 받았을때 실행되는 callback function
// function (err, api_res, api_body) {
// //err 존재시 promise reject 호출
// if (err) reject(err);
//
// // api의 response이 있을경우 promise resolve 호출
// if (api_res) {
// console.log("calling traffic api");
// resolve(api_body);
// }
// });
// })
// }
const API_bundle = async () => {
try {
......@@ -89,8 +89,8 @@ module.exports = (server, app) => {
Day3_Weather = await req_API("forecast","3days"); //3일예보(단기예보)
// 사용자의 생일에 따라서 다른 년도의 교통사고정보를 가져옴.
const year = year_start + (client_birth % (year_range+1));
Traffic_Accident = await req_traffic_API(year); //교통사고정보
// const year = year_start + (client_birth % (year_range+1));
// Traffic_Accident = await req_traffic_API(year); //교통사고정보
info = {
......@@ -107,12 +107,22 @@ module.exports = (server, app) => {
typhoon: Current_Weather.common.stormYn, //현재 태풍
time: Current_Weather.weather.minutely[0].timeObservation, // 불러온 시각
Forecast_3D: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd64hour,
traffic: Traffic_Accident.totalCount, // 교통사고 발생횟수
Forecast_64W: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd61hour,
Forecast_25W: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd25hour,
Forecast_46W: Day3_Weather.weather.forecast3days[0].fcst3hour.wind.wspd46hour,
Forecast_25R: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob25hour,
Forecast_46R: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob46hour,
Forecast_64R: Day3_Weather.weather.forecast3days[0].fcst3hour.precipitation.prob64hour,
Forecast_25S: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code25hour,
Forecast_46S: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code46hour,
Forecast_64S: Day3_Weather.weather.forecast3days[0].fcst3hour.sky.code64hour,
// traffic: Traffic_Accident.totalCount, // 교통사고 발생횟수
death_prob: 0 //확률
}
console.log("API INFO \n", info);
console.log("Traffic count:", info.traffic);
// console.log("Traffic count:", info.traffic);
......@@ -130,7 +140,7 @@ module.exports = (server, app) => {
//죽을 확률 계산(내맘대로 커스텀)
info.death_prob = (
(info.heat / 50) + (Math.abs(info.sensible_temperature - 15) / 10) + (info.discomport / 10) + (info.UV / 10)
+ info.windspd*1 + (info.rain / 10) + (Math.abs(info.current_temperature - 15) / 10) + (info.traffic / 5)
+ info.windspd*1 + (info.rain / 10) + (Math.abs(info.current_temperature - 15) / 10) //+ (info.traffic / 5)
);
//이벤트 기반으로 일정 시간 간격으로 클라이언트에게 보낼 정보
......
......@@ -38,7 +38,7 @@
<script src="highcharts.js"></script>
<script src="modules/exporting.js"></script>
<script src="modules/export-data.js"></script>
<script src="kts.js"></script>
<img src="images/indexWallpaper.jpg" alt="" style="z-index:-1; min-width: 100%; min-height: 100%"width="50%" height="100%">
<div id="banner" >
......