Skip to content

Commit

Permalink
Add implementation for timeFormat and re-enable walking time.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrVragec committed Jan 15, 2019
1 parent 437288f commit 075739e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 19 deletions.
Binary file added .github/Example_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MagicMirror² Module to monitor public transport (U-bahn, tram, bus, S-Bahn) in Munich - Germany.

## Example
![](.github/Example_3.png)
![](.github/Example_4.png)

## Dependencies
* instance of [MagicMirror²](https://github.com/MichMich/MagicMirror)
Expand Down Expand Up @@ -32,7 +32,10 @@ MagicMirror² Module to monitor public transport (U-bahn, tram, bus, S-Bahn) in
},
ignoreStations: [], // destination not to be shown
timeToWalk: 10, // 10 min walking time to station. Default is 0
includeWalkingTime: false // if the walking time should be included and the starting time is displayed
showWalkingTime: false, // if the walking time should be included and the starting time is displayed
showTrainDepartureTime: true, // show tran departure time
trainDepartureTimeFormat: "relative", // format of the train departure time
walkingTimeFormat: "relative", // format of the walking time
}
},
```
Expand All @@ -49,4 +52,7 @@ MagicMirror² Module to monitor public transport (U-bahn, tram, bus, S-Bahn) in
| `sbahn` | Show data for S-Bahn. <br> **Possible values:** `true` or `false` <br> **Default:** `true` |
| `ignoreStations` | Ignore destinations based on a array list. <br> **Possible values e.g.:** `["Feldmoching", "Hauptbahnhof"]` <br> **Default** `[]` |
| `timeToWalk` | Time to walk to the station from your current location <br> **Default:** `0` minutes |
| `includeWalkingTime` | If the time to leave should be displayed which includes the walking time. <br> **Default:** `false` |
| `showWalkingTime` | If the time to leave should be displayed which includes the walking time. <br> **Default:** `false` |
| `showTrainDepartureTime` | If the time of train departure should be displayed. <br> **Default:** `true` |
| `trainDepartureTimeFormat` | Train departure time format. Absolute: 21:10; Relative: in 8 min; <br> **Default** `relative` |
| `walkingTimeFormat` | Walking time format. Absolute: 21:08; Relative in 6 min; <br> **Default** `relative` |
66 changes: 52 additions & 14 deletions mvgmunich.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

const MS_PER_MINUTE = 60000;

Module.register("mvgmunich", {
// Default module configuration
defaults: {
Expand All @@ -23,7 +22,10 @@ Module.register("mvgmunich", {
haltestelleName: "",
ignoreStations: [], // list of destination to be ignored in the list
timeToWalk: 0, // walking time to the station
includeWalkingTime: false, // if the walking time should be included and the starting time is displayed
showWalkingTime: false, // if the walking time should be included and the starting time is displayed
showTrainDepartureTime: true,
trainDepartureTimeFormat: "relative",
walkingTimeFormat: "relative",
showIcons: true,
transportTypesToShow: {
"ubahn": true,
Expand Down Expand Up @@ -99,22 +101,58 @@ Module.register("mvgmunich", {
continue;
}

var timingForCurrentTrain = Math.floor((new Date(apiResultItem.departureTime).getTime() - new Date().getTime()) / 1000 / 60);

this.htmlText += "<tr class='normal'>";
// check if user want's icons or not
// check if user wants icons
if (this.config.showIcons) {
htmlText += "<td class='" + apiResultItem.product.toLocaleLowerCase() + "'>" + apiResultItem.label + "</td>";
} else {
htmlText += "<td>" + apiResultItem.label + "</td>";
}
htmlText += "<td class='" + apiResultItem.product.toLocaleLowerCase() + "'></td>";
}
// add transport number
htmlText += "<td>" + apiResultItem.label + "</td>";

// add last station aka direction
htmlText += "<td class='stationColumn'>" + apiResultItem.destination + "</td>";
htmlText += "<td class='timing'>" +
(timingForCurrentTrain <= 0 ? this.translate("JETZT") : this.translate("IN") +
" " + timingForCurrentTrain + " " + this.translate("MIN")
) + "</td>";

if(this.config.showTrainDepartureTime) {
// add departure time
htmlText += "<td class='timing'>";
var departureTime = new Date(apiResultItem.departureTime)

// check what kind of time user wants (absolute / relative)
if(this.config.trainDepartureTimeFormat == "absolute") {
htmlText += (departureTime.getHours() < 10 ? '0' : '') + departureTime.getHours()
+ ":" + (departureTime.getMinutes() < 10 ? '0' : '') + departureTime.getMinutes();
} else if (this.config.trainDepartureTimeFormat == "relative") {
var timingForCurrentTrain = Math.floor((departureTime.getTime() - new Date().getTime()) / 1000 / 60);
htmlText += (timingForCurrentTrain <= 0
? this.translate("JETZT")
: this.translate("IN") + " " + timingForCurrentTrain + " " + this.translate("MIN"));
} else {
htmlText += "trainDepartureTimeFormat config is wrong"
}
htmlText += "</td>";
}
// check if user want's to see walking time
if (this.config.showWalkingTime) {
htmlText += "<td> / ";
var startWalkingTime = new Date(apiResultItem.departureTime
- this.config.timeToWalk * MS_PER_MINUTE);
// check what kind of walking time user wants (absolute / relative)
if(this.config.walkingTimeFormat == "absolute") {
var hoursStr = (startWalkingTime.getHours() < 10 ? '0' : '') + startWalkingTime.getHours();
var minutesStr = (startWalkingTime.getMinutes() < 10 ? '0' : '') + startWalkingTime.getMinutes();
// add walking time timing
htmlText += hoursStr + ":" + minutesStr;
} else if (this.config.walkingTimeFormat == "relative") {
var timingForStartWalking = Math.floor((startWalkingTime.getTime() - new Date().getTime()) / 1000 / 60);
htmlText += (timingForStartWalking <=0
? this.translate("JETZT")
: this.translate("IN") + " " + timingForStartWalking + " " + this.translate("MIN"));
} else {
htmlText += "walkingTimeFormat config is wrong"
}
htmlText += "</td>";
}
htmlText += "</tr>";

noOfItems++;
if (noOfItems == this.config.maxEntries) {
break;
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MMM-mvgmunich",
"version": "1.0.4",
"version": "1.0.4",
"description": "",
"main": "mvgmunich.js",
"author": "Simon Crnko",
Expand All @@ -16,5 +16,9 @@
"type": "git",
"url": "https://github.com/mrVragec/MMM-mvgmunich"
},
"contributors": ""
"contributors": "",
"dependencies": {
"cheerio":"~1.0.0-rc.2",
"array-filter":"~1.0.0"
}
}

0 comments on commit 075739e

Please sign in to comment.