-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRVVHelper.js
74 lines (65 loc) · 1.93 KB
/
RVVHelper.js
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
/* Magic Mirror
* Node Helper: MMM-RVV
*
* By sebikolon https://github.com/sebikolon
* MIT Licensed.
*/
module.exports = {
// Prints the input text to the browser console, if enabled in the config.
// This might help you to check, if MMM-RVV is fetching the correct data
printToConsole : function(textToLog, config){
if (config.logToConsole === true) {
console.log(textToLog);
}
},
// padWithZeros: function(n) {
// return n < 10 ? "0" + n: n;
// },
getRemainingMinutes: function(sDeparture) {
if (sDeparture.length != 5){
return sDeparture;
}
let dtNow = new Date();
let dtGiven = new Date(
dtNow.getFullYear(),
dtNow.getMonth(),
dtNow.getDate(),
sDeparture.substr(0,2),
sDeparture.substr(3,2),
dtNow.getSeconds());
// If the bus is departing on the next day, increment the day property
if (dtNow.getHours() > sDeparture.substr(0,2)) {
dtGiven.setDate(dtGiven.getDate() + 1);
}
let diff = (dtGiven.getTime() - dtNow.getTime()) / 1000;
diff /= 60;
return Math.round(diff);
},
addTrip: function(tripObj, trips, config){
// Calculate remaining minutes
tripObj.remainingMinutes = this.getRemainingMinutes(tripObj.departure);
// Check special conditions
if (trips.length > 0) {
// Case 1: Remove the first of 2 duplicated trips for route "Graßer Weg" => "Schwabenstraße"
if (tripObj.direction === "Schwabenstraße" && config.stop_from_ID === 4014037){
if ((tripObj.departure).substr(3,2) - (trips[trips.length -1].departure).substr(3,2) === 2)
{
trips.pop();
}
}
// Case 2: tbd.
// Case 3: tbd.
// Case 4: tbd.
// ...
}
// Check, if trip limit is already reached
if (trips.length >= config.maximumTripsToShow) {
this.printToConsole("MMM-RVV could fetch more trips, but they were limited to " + config.maximumTripsToShow + " trips. Aborting the fetch.", config);
limitReached = true;
}
else {
trips.push(tripObj);
}
return trips;
}
};