This repository was archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.js
220 lines (187 loc) · 7.26 KB
/
config.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*jshint node: true */
/*globals log, QM_MODULE_PATH */
var fs = require('fs');
var bunyan = require('bunyan');
var logformat = require('bunyan-format');
var utils = require('./src/utils.js');
// read the configuration file
var confFile = process.argv[2];
console.log('Reading configuration file: ' + confFile);
var configStr = fs.readFileSync(confFile);
var config = JSON.parse(configStr); // use eval to allow comments inside the file
//================================================================
// LOG
//================================================================
var loggerConfig = config.log.logger;
var stream;
if (loggerConfig.stream.type == 'stdout') {
console.log('Using stdout as log stream ...');
stream = process.stdout;
} else { // TODO file stream doesn't work
console.log('Using file \'' + loggerConfig.stream.file + '\' as log stream ...');
stream = fs.createWriteStream(loggerConfig.stream.file);
}
var logStream = {
outputMode: loggerConfig.outputMode,
out: stream
};
global.log = bunyan.createLogger({
name: 'StreamStory',
stream: logformat(logStream),
level: config.log.logger.level
});
//================================================================
// USE-CASE CONFIGURATION
//================================================================
exports.USE_CASE_HELLA = 0;
exports.USE_CASE_MHWIRTH = 1;
exports.USE_CASE_NRG = 2;
exports.USE_CASE_SIMULATION = 3;
exports.USE_CASE_TRAFFIC = 4;
exports.USE_CASE_NAME = config.useCase;
if (config.useCase == 'hella') {
exports.USE_CASE = exports.USE_CASE_HELLA;
}
else if (config.useCase == 'mhwirth') {
exports.USE_CASE = exports.USE_CASE_MHWIRTH;
}
else if (config.useCase == 'nrg4cast') {
// NRG4Cast
exports.USE_CASE = exports.USE_CASE_NRG;
}
else if (config.useCase == 'simulation') {
exports.USE_CASE = exports.USE_CASE_SIMULATION;
}
else if (config.useCase == 'traffic') {
exports.USE_CASE = exports.USE_CASE_TRAFFIC;
}
else {
log.error('Unknown use case: %s', config.USE_CASE);
process.exit(1);
}
// resampling interval
if (config.resampleInterval == null) {
log.warn('Resampling interval is not defined in the configuration! Using default ...');
if (exports.USE_CASE == exports.USE_CASE_MHWIRTH) {
exports.STREAM_STORY_RESAMPLING_INTERVAL = 1000*10; // 10s
}
else if (exports.USE_CASE == exports.USE_CASE_TRAFFIC) {
exports.STREAM_STORY_RESAMPLING_INTERVAL = 1000*60*60; // 15min
}
else { // hella
exports.STREAM_STORY_RESAMPLING_INTERVAL = 1000*10; // 10s
}
} else {
exports.STREAM_STORY_RESAMPLING_INTERVAL = config.resampleInterval;
}
//================================================================
// INITIALIZATION
//================================================================
exports.INITIALIZE_ZERO = config.qminer.initializeZeros;
exports.INTERPOLATION = config.interpolation;
//================================================================
// SAVE OUTPUTS
//================================================================
exports.SAVE_STATES = false;
exports.SAVE_ACTIVITIES = false;
exports.SAVE_FRICTION = false;
exports.OUTPUT_DIR = 'output/';
if (config.saveStates == true) {
log.info('Saving states ...');
exports.SAVE_STATES = true;
}
if (config.saveActivities == true) {
log.info('Saving activities ...');
exports.SAVE_ACTIVITIES = true;
}
if (config.saveFriction == true) {
log.info('Saving friction coefficients ...');
exports.SAVE_FRICTION = true;
}
//================================================================
// SERVER
//================================================================
exports.SERVER_PORT = config.server.port;
exports.PING_INTERVAL = config.server.pingInterval;
//================================================================
// QMINER
//================================================================
global.QM_MODULE_PATH = config.qminer.path;
exports.QM_CREATE_PIPELINE = config.qminer.createPipeline;
exports.QM_DATABASE_MODE = config.qminer.mode;
//================================================================
// STORAGE STRUCTURE
//================================================================
var dataPath = config.dataPath + (config.dataPath[config.dataPath.length - 1] == '/' ? '' : '/');
exports.REAL_TIME_BASE_PATH = dataPath + 'online-db/';
exports.REAL_TIME_MODELS_PATH = dataPath + 'models/';
exports.USER_BASES_PATH = dataPath + 'offline-db/';
//================================================================
// QMINER - multiple users
//================================================================
exports.QM_USER_DEFAULT_STORE_NAME = 'default';
//================================================================
// MYSQL
//================================================================
exports.database = config.database;
//================================================================
// STREAM STORY
//================================================================
var seed = config.seed != null ? config.seed : 0;
exports.STREAM_STORY_PARAMS = {
transitions: {
type: 'continuous'
},
rndseed: seed,
pastStates: 2,
verbose: true
}
exports.MEAN_STATE_LABEL = config.meanStateLabel != null ?
config.meanStateLabel : '';
//================================================================
// PIPELINE
//================================================================
exports.GC_INTERVAL = 10000000
//================================================================
// MULTITHREADING
//================================================================
exports.MULTI_THREAD = true;
//================================================================
// PRINT
//================================================================
exports.RAW_PRINT_INTERVAL = config.log.print.rawData;
exports.STREAM_STORY_PRINT_INTERVAL = config.log.print.streamStory;
exports.STORE_PRINT_INTERVAL = config.log.print.stores;
exports.BROKER_PRINT_INTERVAL = config.log.print.broker;
exports.COEFF_PRINT_INTERVAL = config.log.print.coeff;
//================================================================
// INTEGRATION
//================================================================
exports.integration = config.integration;
exports.RESTART_ON_REPLAY = config.restartOnReplay;
// set the global qm object
global.qm = require(QM_MODULE_PATH);
// configure qminer log level
var verbosity = 0;
if (config.log.logger.level == 'debug') verbosity = 1;
else if (config.log.logger.level == 'trace') verbosity = 2;
global.qm.verbosity(verbosity);
//create the directories if they don't exist
try {
utils.createDirSync(exports.REAL_TIME_BASE_PATH);
utils.createDirSync(exports.REAL_TIME_MODELS_PATH);
utils.createDirSync(exports.USER_BASES_PATH);
} catch (e) {
log.error(e, 'Failed to create directories!');
process.exit(3);
}
log.info('Configured!');
log.info('================================================');
log.info('Working directory: %s', process.cwd());
log.info('Module path: %s', QM_MODULE_PATH);
log.info('Mode: ' + config.qminer.mode);
log.info('QMiner verbosity: %d', verbosity);
log.info('StreamStory params: %s', JSON.stringify(exports.STREAM_STORY_PARAMS));
log.info('Data path: %s', dataPath);
log.info('Use-case: %s', config.useCase);
log.info('================================================');