Skip to content

Commit

Permalink
Fixed linting errors, removed useless code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dleclercpro committed Oct 5, 2023
1 parent b6a3429 commit 553dfc9
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 44 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.1",
"version": "1.11.2",
"author": "David Leclerc",
"main": "./src/index.ts",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/models/pages/HomePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { By } from 'selenium-webdriver';
import Page from './Page';
import logger from '../../logger';
import { ConstructionWorkError } from '../errors';
import { MEDIUM_TIME, VERY_VERY_LONG_TIME } from '../../constants/times';
import { VERY_VERY_LONG_TIME } from '../../constants/times';
import { HOMEPAGE_URL } from '../../config';

const TEXTS = {
Expand Down
2 changes: 1 addition & 1 deletion src/models/pages/ResultsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { formatDateForFilename } from '../../utils/locale';
import { NoResultsError, FoundNoAppointmentError, NoAppointmentInformationError, GhostUIElementError } from '../errors';
import { LogMessage } from '../../constants';
import Page from './Page';
import { MEDIUM_TIME, VERY_VERY_LONG_TIME } from '../../constants/times';
import { VERY_VERY_LONG_TIME } from '../../constants/times';

const TEXTS = {
NoAppointment: 'keine Termine frei',
Expand Down
2 changes: 1 addition & 1 deletion src/models/scenarios/Scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class Scenario {
await this.doExecute(bot);

} catch (err: unknown) {
let error = err;
const error = err;

if (err instanceof Error) {
if (isKnownEvent(err.name)) {
Expand Down
7 changes: 3 additions & 4 deletions src/models/sessions/SessionHistoryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class SessionHistoryBuilder {
const history = new SessionHistory(this.buildBuckets(bucketSize), bucketSize);

let session: IncompleteSession = IncompleteSession.create();
let release: Release = RELEASE_ZERO;

// Read logs in chronological order
logs.forEach(log => {
Expand All @@ -45,7 +44,7 @@ class SessionHistoryBuilder {
if (log.msg.includes(TEXTS.SessionStart)) {
session = IncompleteSession.create();

logger.trace(`Starting session: ${session.getId()} [${release.toString()}]`);
logger.trace(`Starting session: ${session.getId()} [${log.version.toJSON()}]`);
session.start(new Date(log.time));
}

Expand All @@ -56,7 +55,7 @@ class SessionHistoryBuilder {

// Session ended
if (log.msg.includes(TEXTS.SessionEnd)) {
logger.trace(`Finishing session: ${session.getId()}`);
logger.trace(`Finishing session: ${session.getId()} [${log.version.toJSON()}]`);
session.end(new Date(log.time));

// Sessions should have a start and an end
Expand All @@ -75,7 +74,7 @@ class SessionHistoryBuilder {
// Store complete session in history
history.addSession(new CompleteSession({
id: session.getId(),
release,
release: log.version,
startTime: session.getStartTime()!,
endTime: session.getEndTime()!,
logs: session.getLogs(),
Expand Down
13 changes: 1 addition & 12 deletions src/models/sessions/SessionHistoryExporter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logger from '../../logger';
import { getLastValue } from '../../utils/array';
import { writeFile, writeJSON } from '../../utils/file';
import { writeFile } from '../../utils/file';
import { sum } from '../../utils/math';
import { logToText } from '../../utils/parsing';
import CompleteSession from './CompleteSession';
Expand Down Expand Up @@ -44,17 +44,6 @@ class SessionHistoryExporter {

await writeFile(filepath, lines.join('\n') + '\n');
}

public async exportToJSONFile(filepath: string, history: SessionHistory) {
if (!filepath.endsWith('.json')) {
const ext = getLastValue(filepath.split('.'));
throw new Error(`Invalid file extension for export: ${ext}`);
}

const data: any = [];

await writeJSON(filepath, data);
}
}

export default SessionHistoryExporter.getInstance();
27 changes: 5 additions & 22 deletions src/utils/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import logger from '../logger';
import Release from '../models/Release';
import { Log } from '../types';
import { listFiles, readFile } from './file';
import fs from 'fs';



Expand Down Expand Up @@ -44,9 +43,9 @@ export const parseLogs = async (filepath: string, since?: Date | Release) => {

if (since) {
if (since instanceof Date) {
logger.info(`Keeping logs newer than: ${since}`);
logger.debug(`Keeping logs newer than: ${since}`);
} else {
logger.info(`Keeping logs with release version higher or equal to: ${since.toString()}`);
logger.debug(`Keeping logs with release version higher or equal to: ${since.toString()}`);
}
}

Expand All @@ -67,25 +66,9 @@ export const parseLogs = async (filepath: string, since?: Date | Release) => {
})
.filter(hasLogMessage); // Every log should have a message

logger.debug(`Parsed ${logs.length} valid log entries.`);

return logs;
}



export const findAndParseLogs = async (dir: string, since?: Date | Release) => {
logger.info(`Finding and reading logs...`);

if (since) {
if (since instanceof Date) {
logger.info(`Keeping logs newer than: ${since}`);
} else {
logger.info(`Keeping logs with release version higher or equal to: ${since.toString()}`);
}
if (logs.length > 0) {
logger.debug(`Parsed ${logs.length} valid log entries.`);
}

const files = await listFiles(dir);

console.log(files);
return logs;
}

0 comments on commit 553dfc9

Please sign in to comment.