diff --git a/src/app/model/vessel.ts b/src/app/model/vessel.ts index 070f33e..5d56693 100644 --- a/src/app/model/vessel.ts +++ b/src/app/model/vessel.ts @@ -2,13 +2,16 @@ import {Message} from './message'; export class Vessel { messages: Array; + firstAppearance: number; constructor(messages: Array) { this.messages = messages; } addMessage(message: Message): void { - this.messages.push(message); + this.messages.push(message); + this.determineFirstAppearance(message); + } getMMSI(): string { @@ -26,4 +29,11 @@ export class Vessel { return '#' + (+this.getMMSI()).toString(16).substr(0, 6); } + determineFirstAppearance(message: Message): void { + const timeInS = Date.parse(message.time) / 1000; + if (this.firstAppearance > timeInS) { + this.firstAppearance = timeInS; + } + } + } diff --git a/src/app/model/vessels.ts b/src/app/model/vessels.ts index fea6cef..3a6572a 100644 --- a/src/app/model/vessels.ts +++ b/src/app/model/vessels.ts @@ -3,7 +3,6 @@ import {Message} from './message'; export class Vessels { vessels: Map; - firstAppearance: number; constructor() { this.vessels = new Map(); @@ -13,14 +12,8 @@ export class Vessels { if (!this.vessels.get(Number(message.mmsi))) { this.vessels.set(Number(message.mmsi), new Vessel(new Array())); } - this.determineFirstAppearance(message); this.vessels.get(Number(message.mmsi)).addMessage(message); } - determineFirstAppearance(message: Message): void { - const timeInS = Date.parse(message.time) / 1000; - if (this.firstAppearance > timeInS) { - this.firstAppearance = timeInS; - } - } + }