Browse Source

deps & data folder (#1)

pull/1/head
Alexey Velikiy 6 years ago committed by GitHub
parent
commit
c25a9a3dc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .gitignore
  2. 9
      server/build/webpack.base.conf.js
  3. 10
      server/build/webpack.dev.conf.js
  4. 27506
      server/dist/server.js
  5. 12
      server/package.json
  6. 11
      server/src/config.ts
  7. 4
      server/src/index.ts
  8. 7
      server/src/services/analytics.ts
  9. 14
      server/src/services/data.ts

2
.gitignore vendored

@ -2,3 +2,5 @@ node_modules/
dist/
.vscode/
package-lock.json
server/dist
data

9
server/build/webpack.base.conf.js

@ -21,15 +21,6 @@ module.exports = {
filename: "server.js",
path: resolve('dist')
},
// externals: [
// function(context, request, callback) {
// if(request[0] == '.') {
// callback();
// } else {
// callback(null, "require('" + request + "')");
// }
// }
// ],
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),

10
server/build/webpack.dev.conf.js

@ -1,4 +1,14 @@
var base = require('./webpack.base.conf');
base.watch = true;
base.externals = [
function(context, request, callback) {
if(request[0] == '.') {
callback();
} else {
callback(null, "require('" + request + "')");
}
}
]
module.exports = base;

27506
server/dist/server.js vendored

File diff suppressed because one or more lines are too long

12
server/package.json

@ -18,11 +18,6 @@
},
"homepage": "https://github.com/hastic/hastic-server#readme",
"dependencies": {
"encoding": "^0.1.12",
"event-stream": "^3.3.4",
"express": "^4.16.3",
"fast-csv": "^2.4.1",
"node-fetch": "^2.1.2"
},
"devDependencies": {
"@types/express": "^4.11.1",
@ -37,6 +32,11 @@
"nodemon": "^1.17.3",
"ts-loader": "^3.5.0",
"typescript": "^2.8.3",
"webpack": "^3.5.6"
"webpack": "^3.5.6",
"encoding": "^0.1.12",
"event-stream": "^3.3.4",
"express": "^4.16.3",
"fast-csv": "^2.4.1",
"node-fetch": "^2.1.2"
}
}

11
server/src/config.ts

@ -1,9 +1,8 @@
import * as path from 'path';
const DATA_PATH = path.join(__dirname, '../data');
const ANALYTICS_PATH = path.join(__dirname, '../../src');
const ANOMALIES_PATH = path.join(ANALYTICS_PATH, 'anomalies');
const SEGMENTS_PATH = path.join(ANALYTICS_PATH, 'segments');
const METRICS_PATH = path.join(ANALYTICS_PATH, 'metrics');
export const ANALYTICS_PATH = path.join(__dirname, '../../src');
export { DATA_PATH, ANALYTICS_PATH, ANOMALIES_PATH, SEGMENTS_PATH, METRICS_PATH }
export const DATA_PATH = path.join(__dirname, '../../data');
export const ANOMALIES_PATH = path.join(DATA_PATH, 'anomalies');
export const SEGMENTS_PATH = path.join(DATA_PATH, 'segments');
export const METRICS_PATH = path.join(DATA_PATH, 'metrics');

4
server/src/index.ts

@ -5,6 +5,10 @@ import { router as anomaliesRouter } from './routes/anomalies';
import { router as segmentsRouter } from './routes/segments';
import { router as alertsRouter } from './routes/alerts';
import { checkDataFolders } from './services/data';
checkDataFolders();
const app = express();
const PORT = process.env.HASTIC_PORT || 8000;

7
server/src/services/analytics.ts

@ -12,12 +12,7 @@ import { getLabeledSegments, insertSegments, removeSegments } from './segments';
import { split, map, mapSync } from 'event-stream';
const learnWorker = spawn('python3', ['worker.py'], { cwd: ANALYTICS_PATH })
learnWorker.stdout.pipe(split())
.pipe(
mapSync(function(line){
onMessage(line)
})
);
learnWorker.stdout.pipe(split()).pipe(mapSync(onMessage));
learnWorker.stderr.on('data', data => console.error(`worker stderr: ${data}`));

14
server/src/services/data.ts

@ -0,0 +1,14 @@
import * as config from '../config'
import * as fs from 'fs';
export function checkDataFolders() {
if(fs.existsSync(config.DATA_PATH)) {
return;
}
fs.mkdirSync(config.DATA_PATH);
fs.mkdirSync(config.ANOMALIES_PATH);
fs.mkdirSync(config.SEGMENTS_PATH);
fs.mkdirSync(config.METRICS_PATH);
}
Loading…
Cancel
Save