Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parametrize gamma #82

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion graph-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"start:prod": "node ./build/app.js",
"test:local": "NEO4J_HOST=neo4j://neo4j:7687 npm run test",
"test": "npm run build-helpers && npm run build && npm run test:unit",
"test:unit": "jest --forceExit --detectOpenHandles --coverage --verbose"
"test:unit": "jest --forceExit --detectOpenHandles --coverage --verbose",
"test:watch": "jest --watch"
},
"author": "",
"license": "BSD-3-Clause",
Expand Down
4 changes: 2 additions & 2 deletions graph-service/src/ewma-utilities/ewma.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe("EWMA helpers", () => {

// tslint:disable-next-line:prefer-for-of
for (let index = 0; index < values.length; index++) {
lastEWMA = EWMA(values[index], lastEWMA);
lastEWMASquare = EWMA(Math.pow(values[index], 2), lastEWMASquare);
lastEWMA = EWMA(values[index], lastEWMA, 0.1);
lastEWMASquare = EWMA(Math.pow(values[index], 2), lastEWMASquare, 0.1);
}

result = EWMAStdDeviation(lastEWMASquare, lastEWMA);
Expand Down
6 changes: 3 additions & 3 deletions graph-service/src/ewma-utilities/ewma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const GAMMA = 0.1;
export const GAMMA = 0.0003;

/**
* Calculates the EWMA at a time T, given the EWMA value at time T - 1 and the measure at time T
Expand All @@ -7,8 +7,8 @@ export const GAMMA = 0.1;
* @param Yt - Measure at time T
* @param previousEWMA - EWMA at time T - 1
*/
export function EWMA(Yt: number, previousEWMA: number): number {
return GAMMA * Yt + previousEWMA * (1 - GAMMA);
export function EWMA(Yt: number, previousEWMA: number, gamma: number = GAMMA): number {
return gamma * Yt + previousEWMA * (1 - gamma);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions graph-service/src/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { logger } from "helpers";

// tslint:disable-next-line: typedef
export function logging(req, res, next) {
logger.debug(`${coerceReqTrace(req)} => ${coerceReqDetails(req)}`);
// logger.debug(`${coerceReqTrace(req)} => ${coerceReqDetails(req)}`);
req._startTime = Date.now();

const originalSend = res.send;
res.send = (body: any): express.Response => {
if (res.statusCode < 400) {
const duration = Date.now() - res.req._startTime;
logger.debug(`${coerceReqTrace(res.req)} <= ${res.statusCode} after ${duration}ms with ${toJSON(body)}`);
// logger.debug(`${coerceReqTrace(res.req)} <= ${res.statusCode} after ${duration}ms with ${toJSON(body)}`);
}
return originalSend.call(res, body);
};
Expand All @@ -22,7 +22,7 @@ export function logging(req, res, next) {
export function globalErrorHandling(err, req, res, _) {
const status = err.status || 500;

logger.error(`${coerceReqTrace(req)} ${err.stack}`);
// logger.error(`${coerceReqTrace(req)} ${err.stack}`);

res.status(status).json({
status,
Expand Down
2 changes: 1 addition & 1 deletion graph-service/src/testing_tools/process_topologies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck
import graphService = require("./service");
import graphService = require("../service");
import fs = require("fs");
import { util } from "prettier";
import { inspect } from "util";
Expand Down
4 changes: 2 additions & 2 deletions graph-service/src/testing_tools/requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ PATCH {{base}}/graph/components/status
Content-Type: application/json

{
"component": "J",
"status": "CONFIRMED"
"component": "B",
"status": "NORMAL"
}

###
Expand Down
2 changes: 1 addition & 1 deletion metrics-processor/src/ewma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const GAMMA = 0.3;
export const GAMMA = 0.0003;

/**
* Calculates the EWMA at a time T, given the EWMA value at time T - 1 and the measure at time T
Expand Down