Blame view

src/app/model/vessel.ts 842 Bytes
de59ffef8   lsagona   add model + search
1
2
3
4
  import {Message} from './message';
  
  export class Vessel {
    messages: Array<Message>;
29e50d28c   lsagona   put date of first...
5
    firstAppearance: number;
de59ffef8   lsagona   add model + search
6
7
8
9
10
11
  
    constructor(messages: Array<Message>) {
      this.messages = messages;
    }
  
    addMessage(message: Message): void {
29e50d28c   lsagona   put date of first...
12
13
      this.messages.push(message);
      this.determineFirstAppearance(message);
de59ffef8   lsagona   add model + search
14
15
16
    }
  
    getMMSI(): string {
9bbae2409   lsagona   highlight selecte...
17
      if (this.messages.length === 0) {
a77940a0e   lsagona   fix a bug when yo...
18
        return undefined;
9bbae2409   lsagona   highlight selecte...
19
      }
de59ffef8   lsagona   add model + search
20
21
22
23
24
25
      return this.messages[0].mmsi;
    }
  
    getName(): string {
      return this.messages[0].vesselName;
    }
287033a62   lsagona   add vessel positi...
26
    public getColor(): string {
72dfa80e2   lsagona   eache vessel have...
27
      return '#' + (+this.getMMSI()).toString(16).substr(0, 6);
287033a62   lsagona   add vessel positi...
28
    }
29e50d28c   lsagona   put date of first...
29
30
    determineFirstAppearance(message: Message): void {
      const timeInS = Date.parse(message.time) / 1000;
1af45d962   lsagona   fix offset
31
      if (this.firstAppearance === undefined || this.firstAppearance > timeInS) {
29e50d28c   lsagona   put date of first...
32
33
34
        this.firstAppearance = timeInS;
      }
    }
de59ffef8   lsagona   add model + search
35
  }