Skip to content
This repository was archived by the owner on Mar 14, 2019. It is now read-only.

Commit bdde787

Browse files
committed
Initial commit
0 parents  commit bdde787

File tree

1,173 files changed

+56846
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,173 files changed

+56846
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#MMM-Ruter Change Log
2+
3+
## [1.0.0] - 2016-10-23
4+
5+
- Initial version

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Cato Antonsen
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MMM-Ruter.js

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/* Magic Mirror
2+
* Module: Ruter
3+
*
4+
* By Cato Antonsen (https://github.com/CatoAntonsen)
5+
* MIT Licensed.
6+
*/
7+
8+
Module.register("MMM-Ruter",{
9+
10+
// Default module config.
11+
defaults: {
12+
showHeader: false, // Set this to true to show header above the journeys (default is false)
13+
showPlatform: false, // Set this to true to get the names of the platforms (default is false)
14+
maxItems: 5, // Number of journeys to display (default is 5)
15+
humanizeTimeTreshold: 15, // If time to next journey is below this value, it will be displayed as "x minutes" instead of time (default is 15 minutes)
16+
serviceReloadInterval: 30000, // Refresh rate in MS for how often we call Ruter's web service. NB! Don't set it too low! (default is 30 seconds)
17+
timeReloadInterval: 1000, // Refresh rate how often we check if we need to update the time shown on the mirror (default is every second)
18+
animationSpeed: 1000, // How fast the animation changes when updating mirror (default is 1 second)
19+
fade: true, // Set this to true to fade list from light to dark. (default is true)
20+
fadePoint: 0.25 // Start on 1/4th of the list.
21+
},
22+
23+
getStyles: function () {
24+
return ["ruter.css"];
25+
},
26+
27+
getScripts: function() {
28+
return ["moment.js"];
29+
},
30+
31+
getTranslations: function() {
32+
return {
33+
en: "translations/en.json",
34+
nb: "translations/nb.json"
35+
}
36+
},
37+
38+
start: function() {
39+
console.log(this.translate("STARINGMODULE") + ": " + this.name);
40+
41+
this.journeys = [];
42+
this.previousTime = [];
43+
44+
this.sendSocketNotification("CONFIG", this.config);
45+
46+
var self = this;
47+
48+
setInterval(function() {
49+
self.updateDomIfNeeded();
50+
}, this.config.timeReloadInterval);
51+
52+
},
53+
54+
socketNotificationReceived: function(notification, payload) {
55+
if (notification === "RUTER_UPDATE") {
56+
this.journeys = payload;
57+
}
58+
},
59+
60+
getDom: function() {
61+
if (this.journeys.length > 0) {
62+
63+
var table = document.createElement("table");
64+
table.className = "ruter small";
65+
66+
if (this.config.showHeader) {
67+
table.appendChild(this.getTableHeaderRow());
68+
}
69+
70+
for(var i = 0; i < this.journeys.length; i++) {
71+
72+
var tr = this.getTableRow(this.journeys[i]);
73+
74+
// Create fade effect. <-- stolen from default "calendar" module
75+
if (this.config.fade && this.config.fadePoint < 1) {
76+
if (this.config.fadePoint < 0) {
77+
this.config.fadePoint = 0;
78+
}
79+
var startingPoint = this.journeys.length * this.config.fadePoint;
80+
var steps = this.journeys.length - startingPoint;
81+
if (i >= startingPoint) {
82+
var currentStep = i - startingPoint;
83+
tr.style.opacity = 1 - (1 / steps * currentStep);
84+
}
85+
}
86+
87+
table.appendChild(tr);
88+
}
89+
90+
return table;
91+
} else {
92+
var wrapper = document.createElement("div");
93+
wrapper.innerHTML = this.translate("LOADING");
94+
wrapper.className = "small dimmed";
95+
}
96+
97+
return wrapper;
98+
},
99+
100+
getTableHeaderRow: function() {
101+
var thLine = document.createElement("th");
102+
thLine.className = "light";
103+
thLine.appendChild(document.createTextNode(this.translate("LINEHEADER")));
104+
105+
var thDestination = document.createElement("th");
106+
thDestination.className = "light";
107+
thDestination.appendChild(document.createTextNode(this.translate("DESTINATIONHEADER")));
108+
109+
var thPlatform = document.createElement("th");
110+
thPlatform.className = "light";
111+
thPlatform.appendChild(document.createTextNode(this.translate("PLATFORMHEADER")));
112+
113+
var thTime = document.createElement("th");
114+
thTime.className = "light time"
115+
thTime.appendChild(document.createTextNode(this.translate("TIMEHEADER")));
116+
117+
var thead = document.createElement("thead");
118+
thead.addClass = "xsmall dimmed";
119+
thead.appendChild(thLine);
120+
thead.appendChild(thDestination);
121+
if (this.config.showPlatform) { thead.appendChild(thPlatform); }
122+
thead.appendChild(thTime);
123+
124+
return thead;
125+
},
126+
127+
getTableRow: function(journey) {
128+
var tdLine = document.createElement("td");
129+
var txtLine = document.createTextNode(journey.lineName);
130+
tdLine.appendChild(txtLine);
131+
132+
var tdDestination = document.createElement("td");
133+
tdDestination.className = "destination bright";
134+
tdDestination.appendChild(document.createTextNode(journey.destinationName));
135+
136+
if (this.config.showPlatform) {
137+
var tdPlatform = document.createElement("td");
138+
tdPlatform.className = "platform";
139+
tdPlatform.appendChild(document.createTextNode(journey.platform));
140+
}
141+
142+
var tdTime = document.createElement("td");
143+
tdTime.className = "time light";
144+
tdTime.appendChild(document.createTextNode(this.formatTime(journey.time)));
145+
146+
var tr = document.createElement("tr");
147+
tr.appendChild(tdLine);
148+
tr.appendChild(tdDestination);
149+
if (this.config.showPlatform) { tr.appendChild(tdPlatform); }
150+
tr.appendChild(tdTime);
151+
152+
return tr;
153+
},
154+
155+
updateDomIfNeeded: function() {
156+
var needUpdate = false;
157+
158+
for(var i=0; i < this.journeys.length; i++) {
159+
var time = this.formatTime(this.journeys[i].time);
160+
if (this.previousTime[i] != time) {
161+
needUpdate = true;
162+
this.previousTime[i] = time;
163+
}
164+
}
165+
166+
if (needUpdate) {
167+
this.updateDom(this.config.animationSpeed);
168+
}
169+
},
170+
171+
formatTime: function(t) {
172+
var min = moment.duration(moment(t) - moment.now()).minutes();
173+
if (min == 0) {
174+
return this.translate("NOW")
175+
} else if (min == 1) {
176+
return this.translate("1MIN");
177+
} else if (min < this.config.humanizeTimeTreshold) {
178+
return min + " " + this.translate("MINUTES");
179+
} else {
180+
return moment(t).format("LT");
181+
}
182+
}
183+
});

README.md

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# MagicMirror Module: Ruter
2+
The 'MMM-Ruter' is a module for displaying public transport information for the region Oslo and Akershus in Norway on [Magic Mirror 2](https://magicmirror.builders/). It's using data from [Ruter.no](http://reisapi.ruter.no/help).
3+
4+
![Full](images/MMM-Ruter_Full.png)
5+
![Simple](images/MMM-Ruter_Simple.png)
6+
7+
Current version is 1.0.0. See [changelog](CHANGELOG.md "Version history") for version history.
8+
9+
## Installation
10+
11+
Remote to your MM2-box with your terminal software and go to your MagicMirror's Module folder:
12+
````bash
13+
cd ~/MagicMirror/modules
14+
````
15+
16+
Clone the repository:
17+
````bash
18+
git clone https://github.com/CatoAntonsen/MMM-Ruter.git
19+
````
20+
21+
Go to the modules folder:
22+
````bash
23+
cd MMM-Ruter
24+
````
25+
26+
Install the dependencies:
27+
````bash
28+
npm install
29+
````
30+
31+
Add the module to the modules array in the `config/config.js` file (you can change later when you see this works):
32+
```json
33+
{
34+
module: 'MMM-Ruter',
35+
header: 'Ruter',
36+
position: 'top_left',
37+
config: {
38+
showPlatform: true, // If you want to
39+
maxItems: 10,
40+
stops: [
41+
{
42+
stopId: "3010972",
43+
platforms: [ ]
44+
}
45+
]
46+
}
47+
},
48+
```
49+
50+
# Configuration options
51+
52+
These are the valid configuration options you can put inside the config array above:
53+
54+
Configuration option | Comment | Default
55+
---|---|---
56+
showHeader | Set this to true to show header above the journeys | false
57+
showPlatform | Set this to true to get the names of the platforms. Set this to true to check the name of the platform if you need to filter | false
58+
maxItems | Number of journeys to display | 5
59+
humanizeTimeTreshold | If time to next journey is below this value, it will be displayed as "x minutes" instead of time | 15
60+
serviceReloadInterval | Refresh rate in MS for how often we call Ruter's web service. NB! Don't set it too low! | 30000
61+
timeReloadInterval | Refresh rate how often we check if we need to update the time in the GUI | 1000
62+
animationSpeed | How fast the animation changes when updating mirror | 1000
63+
fade | Set this to true to fade list from light to dark | true
64+
fadePoint | Start fading on 1/4th of the list | 0.25
65+
stops | Array of stops. See below | Empty array
66+
67+
## Translations
68+
69+
This modules is translated to the following languages:
70+
71+
Language | Responsible
72+
---|---
73+
nb (Norwegian) | Me
74+
en (English) | Me
75+
76+
If you add other languages, please make a PR or drop me a line!
77+
78+
## Stops
79+
You have to configure at least one stop. The module is using the same stop ID's as Ruter does in it's API. The simplest way to find those are to go to [https://ruter.no](https://ruter.no) in your browser and do a search _from_ your stop to somewhere/anywhere. Then extract `NNNNNN` from the resulting URL: https://ruter.no/reiseplanlegger/Mellom/Fra/(`NNNNNN`)*.
80+
81+
Notice that you can only use stops, not addresses or areas. You can test if it is a valid stop by enter the following URL in your browser http://reisapi.ruter.no/StopVisit/GetDepartures/`NNNNNN` (replace `NNNNNN` with your id) |
82+
83+
Stop option | Comment
84+
---|---|---
85+
stopId | Id of stop
86+
platformFilter | The names of the platforms you want to see
87+
88+
Example:
89+
```json
90+
{
91+
stopId: "3010972",
92+
platform: [ "1", "3"]
93+
}
94+
95+
```
96+
97+
# Future enhanchements
98+
99+
1. Make it possible to have multiple instances of this module simultaneously
100+
2. Show exceptions
101+
3. Add filter for individual lines on one platform

images/MMM-Ruter_Full.png

79.5 KB
Loading

images/MMM-Ruter_Simple.png

57 KB
Loading

0 commit comments

Comments
 (0)