index.js
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var express = require('express');
var router = express.Router();
var db = require('../lib/db')
/* GET home page. */
router.get('/', function(req, res, next) {
// 자외선지수, 불쾌지수, 열지수, 체감 온도, 바람속도, 현재기온, 하늘 상태, 강우량, 태풍, 낙뢰
var uvr, discomfort, heat, sensibleTem, windSpeed, presentTem, skyState, rainfall, typhoon, lightning;
// 사망 확률
var deathProb;
// 쿼리문
var sql = 'SELECT * FROM kkonzi_test.weatherInfo';
db.query(sql, function(err, rows, fields){
if (err) {
console.log(err);
} else {
var tmp = rows.length - 1;
uvr = rows[temp].uvr;
discomfort = rows[temp].discomfort;
heat = rows[temp].heat;
sensibleTem = rows[temp].sensibleTem;
windSpeed = rows[temp].windSpeed;
presentTem = rows[temp].presentTem;
skyState = rows[temp].skyState;
rainfall = rows[temp].rainfall;
typhoon = rows[temp].typhoon;
lightning = rows[temp].lightning;
}
})
deathProb = uvr + discomfort + heat + sensibleTem + windSpeed + presentTem + skyState + rainfall + typhoon + lightning;
sql = 'INSERT INTO kkonzi_test.deathProb (prob) VALUES (?)';
var params = deathProb;
db.query(sql, function(err, rows, fields){
if (err) {
console.log(err);
} else {
console.log('Success!');
}
}
})
res.render('index', {title: 'Express'});
});
module.exports = router;