Skip to content

Commit 6e6a211

Browse files
committed
Added new function to show crowd level on the bus
Added in a new icon representing crowd levels on the bus. This is denoted with a stickman icon. 1 stickman - Seating available 2 stickman - Standing available 3 stickman - Limited standing
1 parent 72ef8d9 commit 6e6a211

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

MMM-SG-Transport-V2.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,35 @@ Module.register("MMM-SG-Transport-V2", {
7373

7474
createBusRow: function(bus) {
7575

76-
// Calculate arrival times
7776
ArrivalTimeArray = [];
77+
CrowdingLevelArray = []
7878
if (bus.NextBus.EstimatedArrival !== "") {
7979
ArrivalTimeArray.push(bus.NextBus.EstimatedArrival);
80+
CrowdingLevelArray.push(bus.NextBus.Load)
8081
}
8182
if (bus.NextBus2.EstimatedArrival !== "") {
8283
ArrivalTimeArray.push(bus.NextBus2.EstimatedArrival);
84+
CrowdingLevelArray.push(bus.NextBus.Load)
8385
}
8486
if (bus.NextBus3.EstimatedArrival !== "") {
8587
ArrivalTimeArray.push(bus.NextBus3.EstimatedArrival);
88+
CrowdingLevelArray.push(bus.NextBus.Load)
8689
}
8790

8891
// Don't display if no data
8992
if (ArrivalTimeArray.length == 0) {
90-
return document.createElement("div");
93+
return document.createElement("div");
9194
}
9295

9396
var row = document.createElement("tr");
9497
var element = document.createElement("td");
9598
element.innerHTML = bus.ServiceNo + ": "
9699
row.appendChild(element);
97100

98-
ArrivalTimeArray.forEach(function(ArrivalTime) {
101+
for (var i = 0; i < ArrivalTimeArray.length; i++) {
102+
var ArrivalTime = ArrivalTimeArray[i];
103+
var CrowdingLevel = CrowdingLevelArray[i];
104+
99105
var time = new Date(ArrivalTime);
100106
var now = new Date();
101107
var arrivalTimeInMinutes = Math.floor((time - now) / (60 * 1000));
@@ -106,9 +112,34 @@ Module.register("MMM-SG-Transport-V2", {
106112
}
107113

108114
var element = document.createElement("td");
109-
element.innerHTML = arrivalTimeInMinutes;
115+
element.innerHTML = arrivalTimeInMinutes + ":&nbsp;";
116+
117+
// Location of stickman image
118+
var pathToImage = "modules/MMM-SG-Transport-V2/images/stickman.png";
119+
// Height of image
120+
var height = 17;
121+
122+
var image = "<img src='" + pathToImage + "' height='" + height + "'>"
123+
124+
// Seating available
125+
if (CrowdingLevel == "SEA") {
126+
// print once
127+
element.innerHTML += image;
128+
129+
// Standing available
130+
} else if (CrowdingLevel == "SDA") {
131+
element.innerHTML += image;
132+
element.innerHTML += image;
133+
134+
// Limited standing
135+
} else if (CrowdingLevel == "LSD") {
136+
element.innerHTML += image;
137+
element.innerHTML += image;
138+
element.innerHTML += image;
139+
}
140+
110141
row.appendChild(element);
111-
});
142+
};
112143

113144
return row;
114145
},

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ This module works with [MagicMirror<sup>2</sup>](https://github.com/MichMich/Mag
1616

1717
![Screenshot](screenshots/screenshot.png)
1818

19+
## Legend
20+
21+
The number of stickman refers to the crowd level on the bus.
22+
23+
1 stickman - Seating available
24+
2 stickman - Standing available
25+
3 stickman - Limited standing
26+
27+
1928
## Prerequisite
2029
A working installation of [MagicMirror<sup>2</sup>](https://github.com/MichMich/MagicMirror)
2130

images/stickman.png

11.8 KB
Loading

screenshots/screenshot.png

235 Bytes
Loading

0 commit comments

Comments
 (0)