-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConsumableSchedule.ts
130 lines (105 loc) · 3.06 KB
/
ConsumableSchedule.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
export class NamedStationVisitsStore {
name: string;
emoji: string | null;
private stations: Station[];
constructor(name: string, emoji: string | null, stations: Station[]) {
this.name = name;
this.emoji = emoji;
this.stations = stations;
}
peekStation(): Station | undefined {
return this.stations[0];
}
popStation(): Station | undefined {
return this.stations.shift();
}
get length(): number {
return this.stations.length;
}
}
export class Station {
isMerged: boolean;
busLanes: Lane[];
tramLanes: Lane[];
constructor(isMerged: boolean, busLanes: Lane[], tramLanes: Lane[]) {
this.isMerged = isMerged;
this.busLanes = busLanes;
this.tramLanes = tramLanes;
}
getMergedLanes(): Lane[] {
return this.busLanes.concat(this.tramLanes);
}
get hasBusLanes(): boolean {
return this.busLanes.length > 0;
}
get hasTramLanes(): boolean {
return this.tramLanes.length > 0;
}
get hasLanes(): boolean {
return this.hasBusLanes || this.hasTramLanes;
}
get hasSingleTypeOfLane(): boolean {
return this.hasBusLanes !== this.hasTramLanes;
}
get hasVisits(): boolean {
return this.busLanes.some(lane => lane.directions.some(direction => direction.visits.length > 0))
|| this.tramLanes.some(lane => lane.directions.some(direction => direction.visits.length > 0));
}
}
export class Lane {
name: string;
directions: Direction[];
constructor(name: string, directions: Direction[]) {
this.name = name;
this.directions = directions;
}
peekDirection(): Direction | undefined {
return this.directions[0];
}
popDirection(): Direction | undefined {
return this.directions.shift();
}
}
export class Direction {
visits: Visit[];
name: string;
destination: string;
via: string | null;
directionTag: number;
constructor(times: Visit[], name: string, destination: string, via: string | null, directionTag: number) {
this.visits = times;
this.name = name;
this.destination = destination;
this.via = via;
this.directionTag = directionTag;
}
get fullLaneDescription(): string {
return this.name + ": " + this.destination + (this.via ? " via " + this.via : "");
}
peekVisit(): Visit | undefined {
return this.visits[0];
}
popVisit(): Visit | undefined {
return this.visits.shift();
}
}
export class Visit {
time: Date;
constructor(time: Date) {
this.time = time;
}
get minuteOffset(): number {
// Compute how many minutes in the future this visit is
let now = new Date();
let diff = this.time.getTime() - now.getTime();
return Math.round(diff / 60000);
}
get formattedOffsetFR(): string {
let offset = this.minuteOffset;
if (offset <= 0) {
return "maintenant";
} else {
return offset + " min";
}
}
}