From 553dfc9bd78209b2cb91e70815be5c8ec883b38c Mon Sep 17 00:00:00 2001 From: David Leclerc Date: Thu, 5 Oct 2023 20:10:38 +0200 Subject: [PATCH] Fixed linting errors, removed useless code. --- package-lock.json | 4 +-- package.json | 2 +- src/models/pages/HomePage.ts | 2 +- src/models/pages/ResultsPage.ts | 2 +- src/models/scenarios/Scenario.ts | 2 +- src/models/sessions/SessionHistoryBuilder.ts | 7 +++-- src/models/sessions/SessionHistoryExporter.ts | 13 +-------- src/utils/parsing.ts | 27 ++++--------------- 8 files changed, 15 insertions(+), 44 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0e41811c..a26cfb3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "berlin-lea-performance-monitor", - "version": "1.11.1", + "version": "1.11.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "berlin-lea-performance-monitor", - "version": "1.11.1", + "version": "1.11.2", "dependencies": { "chart.js": "^3.9.1", "chartjs-adapter-moment": "^1.0.1", diff --git a/package.json b/package.json index 1200e63e..6af6a618 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/models/pages/HomePage.ts b/src/models/pages/HomePage.ts index 5a99245d..de9fd989 100644 --- a/src/models/pages/HomePage.ts +++ b/src/models/pages/HomePage.ts @@ -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 = { diff --git a/src/models/pages/ResultsPage.ts b/src/models/pages/ResultsPage.ts index 1e5649d3..50ba6cc4 100644 --- a/src/models/pages/ResultsPage.ts +++ b/src/models/pages/ResultsPage.ts @@ -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', diff --git a/src/models/scenarios/Scenario.ts b/src/models/scenarios/Scenario.ts index 17371b29..4ffd4023 100644 --- a/src/models/scenarios/Scenario.ts +++ b/src/models/scenarios/Scenario.ts @@ -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)) { diff --git a/src/models/sessions/SessionHistoryBuilder.ts b/src/models/sessions/SessionHistoryBuilder.ts index 004cf59c..ffb047e5 100644 --- a/src/models/sessions/SessionHistoryBuilder.ts +++ b/src/models/sessions/SessionHistoryBuilder.ts @@ -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 => { @@ -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)); } @@ -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 @@ -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(), diff --git a/src/models/sessions/SessionHistoryExporter.ts b/src/models/sessions/SessionHistoryExporter.ts index aa14f845..db09ca42 100644 --- a/src/models/sessions/SessionHistoryExporter.ts +++ b/src/models/sessions/SessionHistoryExporter.ts @@ -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'; @@ -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(); \ No newline at end of file diff --git a/src/utils/parsing.ts b/src/utils/parsing.ts index 876b78fe..6bdeb094 100644 --- a/src/utils/parsing.ts +++ b/src/utils/parsing.ts @@ -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'; @@ -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()}`); } } @@ -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; } \ No newline at end of file