This repository has been archived by the owner on Mar 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
91 lines (75 loc) · 2.4 KB
/
server.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var http = require('http');
var express = require('express');
var app = express();
var morgan = require('morgan');
var api = require('./routes/api');
var riot = require('./riot_module/riot.js');
var mongoose = require('mongoose');
var staticData = require('./modules/static-data.js');
var generator = require('./modules/generator.js');
var Match = require('./models/match.js');
var ItemSet = require('./models/set.js');
app.use(express.static(__dirname + '/public'));
app.use(morgan('dev'));
app.use('/api', api);
mongoose.connect('mongodb://localhost/mongo', function(err) {
if(err) {
console.log('DB Connection Error.', err);
} else {
console.log('DB Connection Successful.');
}
});
//ItemSet.remove({}, function(){});
// application ----------------------------------------------
app.get('/', function(req, res) {
res.sendFile('public/index.html', {'root' : __dirname});
});
app.get('/set', function(req, res) {
res.sendFile('public/set.html', {'root' : __dirname});
});
app.listen(3000, function() {
console.log('Server running at http://127.0.0.1:3000/');
});
// Update static data on server start, update daily afterwards.
staticData.updateChampionData();
staticData.updateItemData();
staticData.updateSpellData();
setInterval(function() {
staticData.updateChampionData();
staticData.updateItemData();
staticData.updateSpellData();
}, 86400 * 1000);
// Get featured game data
setInterval(function() {
generator.getFeaturedGames("na");
}, 60000);
// Generate sets from featured game data (when they end)
setInterval(function() {
generator.generateSets();
}, 30000);
// Print match count to console every 30 seconds
setInterval(function() {
Match.count({}, function(err, count) {
if(err) console.log(err);
console.log("Match Count: " + count);
});
}, 30000);
// Print item set count to console every 30 seconds
setInterval(function() {
ItemSet.count({}, function(err, count) {
if(err) console.log(err);
console.log("Analyzed Matches: " + count / 10);
console.log("Item Set Count: " + count);
console.log("--------------------");
});
}, 30000);
var clearOldSets = function() {
var d = new Date;
d.setHours(d.getHours() - 3);
ItemSet.find({
date : { $lte : d } }).remove({}).exec();
Match.find({}).remove({}).exec();
}
clearOldSets();
// Clear-out old featured item sets every 12 hours (keeps item sets created within last 3 hours)
setInterval(clearOldSets, 12 * 60 * 60000);