Commit 29e50d28c6f4464dba34fec4e9c3d53460a5183c

Authored by lsagona
1 parent 783fd26bfe
Exists in master

put date of first appearance in the right class

Showing 2 changed files with 12 additions and 9 deletions Inline Diff

src/app/model/vessel.ts View file @ 29e50d2
import {Message} from './message'; 1 1 import {Message} from './message';
2 2
export class Vessel { 3 3 export class Vessel {
messages: Array<Message>; 4 4 messages: Array<Message>;
5 firstAppearance: number;
5 6
constructor(messages: Array<Message>) { 6 7 constructor(messages: Array<Message>) {
this.messages = messages; 7 8 this.messages = messages;
} 8 9 }
9 10
addMessage(message: Message): void { 10 11 addMessage(message: Message): void {
this.messages.push(message); 11 12 this.messages.push(message);
13 this.determineFirstAppearance(message);
14
} 12 15 }
13 16
getMMSI(): string { 14 17 getMMSI(): string {
if (this.messages.length === 0) { 15 18 if (this.messages.length === 0) {
return ''; 16 19 return '';
} 17 20 }
return this.messages[0].mmsi; 18 21 return this.messages[0].mmsi;
} 19 22 }
20 23
getName(): string { 21 24 getName(): string {
return this.messages[0].vesselName; 22 25 return this.messages[0].vesselName;
} 23 26 }
24 27
public getColor(): string { 25 28 public getColor(): string {
return '#' + (+this.getMMSI()).toString(16).substr(0, 6); 26 29 return '#' + (+this.getMMSI()).toString(16).substr(0, 6);
30 }
31
32 determineFirstAppearance(message: Message): void {
33 const timeInS = Date.parse(message.time) / 1000;
src/app/model/vessels.ts View file @ 29e50d2
import {Vessel} from './vessel'; 1 1 import {Vessel} from './vessel';
import {Message} from './message'; 2 2 import {Message} from './message';
3 3
export class Vessels { 4 4 export class Vessels {
vessels: Map<number, Vessel>; 5 5 vessels: Map<number, Vessel>;
firstAppearance: number; 6
7 6
constructor() { 8 7 constructor() {
this.vessels = new Map<number, Vessel>(); 9 8 this.vessels = new Map<number, Vessel>();
} 10 9 }
11 10
addMessage(message: Message): void { 12 11 addMessage(message: Message): void {
if (!this.vessels.get(Number(message.mmsi))) { 13 12 if (!this.vessels.get(Number(message.mmsi))) {
this.vessels.set(Number(message.mmsi), new Vessel(new Array<Message>())); 14 13 this.vessels.set(Number(message.mmsi), new Vessel(new Array<Message>()));
} 15 14 }
this.determineFirstAppearance(message); 16
this.vessels.get(Number(message.mmsi)).addMessage(message); 17 15 this.vessels.get(Number(message.mmsi)).addMessage(message);
} 18 16 }
19 17
determineFirstAppearance(message: Message): void { 20 18
const timeInS = Date.parse(message.time) / 1000; 21
if (this.firstAppearance > timeInS) { 22
this.firstAppearance = timeInS; 23