Skip to content

Commit

Permalink
Differentiate between known/unknown errors in history summary.
Browse files Browse the repository at this point in the history
  • Loading branch information
dleclercpro committed Oct 5, 2023
1 parent e7e558f commit d3875f0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "berlin-lea-performance-monitor",
"version": "1.11.3",
"version": "1.12.0",
"author": "David Leclerc",
"main": "./src/index.ts",
"scripts": {
Expand Down
21 changes: 12 additions & 9 deletions src/models/sessions/SessionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { WEEKDAYS, WORKDAYS } from '../../constants/times';
import logger from '../../logger';
import { VersionedData, Weekday } from '../../types';
import { toCountsFromArray, unique } from '../../utils/array';
import { isKnownEvent } from '../../utils/event';
import { formatDateForFilename, getWeekday } from '../../utils/locale';
import { sum } from '../../utils/math';
import TimeDuration from '../TimeDuration';
Expand Down Expand Up @@ -38,9 +39,10 @@ class SessionHistory {
}

public summarize() {
const errorCounts = this.getErrorCounts();
const successTimes = this
.getSuccesses()
const knownErrorCounts = this.getErrorCounts(isKnownEvent);
const unknownErrorCounts = this.getErrorCounts(err => !isKnownEvent(err));

const successTimes = this.getSuccesses()
.map(session => formatDateForFilename(session.getEndTime()));

if (successTimes.length > 0) {
Expand All @@ -49,10 +51,11 @@ class SessionHistory {
logger.info(`There was never an appointment available.`);
}

if (sum(Object.values(errorCounts)) > 0) {
logger.info(errorCounts, `Errors encountered:`);
} else {
logger.info(`There was no error encountered.`);
if (sum(Object.values(knownErrorCounts)) > 0) {
logger.info(knownErrorCounts, `Known errors encountered:`);
}
if (sum(Object.values(unknownErrorCounts)) > 0) {
logger.info(unknownErrorCounts, `Unknown errors encountered:`);
}
}

Expand Down Expand Up @@ -182,8 +185,8 @@ class SessionHistory {
return unique(this.getErrors(errorFilter));
}

public getErrorCounts() {
return toCountsFromArray(this.getErrors());
public getErrorCounts(errorFilter: EventFilter = () => true) {
return toCountsFromArray(this.getErrors(errorFilter));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/sessions/SessionHistoryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SessionHistoryBuilder {
const errorCount = session.getErrors().length;
if (errorCount > 1) {
const sessionStartLine = session.getLogs()[0].line;
logger.warn(`Invalid session [@${sessionStartLine}] with ${errorCount} errors found (there should only be one)`);
logger.warn(`Invalid session [${session.getStartTime()} @${sessionStartLine}] with ${errorCount} > 1 errors found`);
return;
}

Expand Down

0 comments on commit d3875f0

Please sign in to comment.