Skip to content

Commit

Permalink
Initial Release | 2016-08-25
Browse files Browse the repository at this point in the history
  • Loading branch information
yo-less committed Aug 25, 2016
0 parents commit 9a2c215
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 yo-less / Jens

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions MMM-KVV.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.MMM-KVV .table {
border-spacing: 0px 0px;
border-collapse: separate;
text-align: left;
}

.MMM-KVV .spacerRow {
padding-bottom: 5px;
}

.MMM-KVV .destination {
font-weight: normal;
color: white;
}

.MMM-KVV .line {
border-spacing: 10px 0px;
border-collapse: separate;
text-align: left;
color:white;
font-weight: normal;
}

.MMM-KVV .departure {
padding-left: 10px;
text-align: right;
font-weight: normal;
color: white;
}

220 changes: 220 additions & 0 deletions MMM-KVV.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/* Magic Mirror
* Module: MMM-KVV
*
* By yo-less
* MIT Licensed.
*/

Module.register("MMM-KVV", {

defaults: {
apiBase: 'http://live.kvv.de/webapp/departures/bystop/',
apiKey: '377d840e54b59adbe53608ba1aad70e8',
stopID: 'de:8212:89',
maxConn: '8',
lines: '',
direction: '',
labelRow: true,
stopName: 'KVV',
reload: 1 * 60 * 1000 // every minute
},

getTranslations: function () {
return {
en: "translations/en.json",
de: "translations/de.json"
};
},

getStyles: function () {
return ["MMM-KVV.css"];
},

start: function () {
var self = this;
Log.info("Starting module: " + this.name);
this.sendSocketNotification("CONFIG", this.config);
setInterval(
function()
{self.sendSocketNotification("CONFIG", self.config);}
,this.config.reload);
},


socketNotificationReceived: function (notification, payload) {
if (notification === "TRAMS" + this.config.stopID) {
this.kvv_data = payload;
this.config.stopName = payload.stopName;
this.updateDom();
}
},

getDom: function () {

// Auto-create MagicMirror header

var wrapper = document.createElement("div");
var header = document.createElement("header");
header.innerHTML = this.config.stopName;
wrapper.appendChild(header);

// Loading data notification

if (!this.kvv_data) {
var text = document.createElement("div");
text.innerHTML = this.translate("LOADING");
text.className = "small dimmed";
wrapper.appendChild(text);

} else {

// Create connection table once data is received

var table = document.createElement("table");
table.classList.add("small", "table");
table.border='0';

if (this.config.labelRow) {
table.appendChild(this.createLabelRow());
}

table.appendChild(this.createSpacerRow());

// Listing selected connections
var counter = 0;

for (var f in this.kvv_data.departures){

var tram = this.kvv_data.departures[f];

if(this.config.lines !== '' ) {

if(this.kvv_lines(tram.route, this.config.lines)) {

if (this.config.direction === '1') {
if (tram.direction === '1') {
table.appendChild(this.createDataRow(tram));
counter = counter + 1;
}
} else if (this.config.direction === '2') {
if (tram.direction === '2') {
table.appendChild(this.createDataRow(tram));
counter = counter + 1;
}
} else {
table.appendChild(this.createDataRow(tram));
counter = counter + 1;
}
}

} else {

if (this.config.direction === '1') {
if (tram.direction === '1') {
table.appendChild(this.createDataRow(tram));
counter = counter + 1;
}
} else if (this.config.direction === '2') {
if (tram.direction === '2') {
table.appendChild(this.createDataRow(tram));
counter = counter + 1;
}
} else {
table.appendChild(this.createDataRow(tram));
counter = counter + 1;
}
}

}

if (counter == 0) {
this.hide();
} else {
wrapper.appendChild(table);
}

}

return wrapper;

},

// Function checking whether a line is wanted by the user

kvv_lines: function(queried_line, lines_config) {

//Remove spaces in the config parameter (if any)
var lines_clean = lines_config.replace(/\s+/g,'');

//Create a line array from the config parameter
var lines_array = lines_clean.split(",");

//Check if the line in question is in the config

for (var i=0;i<lines_array.length;i++) {
if(lines_array[i] == queried_line)
{return true;}
}
return false;
},

createLabelRow: function () {
var labelRow = document.createElement("tr");

var lineLabel = document.createElement("th");
lineLabel.className = "line";
lineLabel.innerHTML = this.translate("LINE");
labelRow.appendChild(lineLabel);

var destinationLabel = document.createElement("th");
destinationLabel.className = "destination";
destinationLabel.innerHTML = this.translate("DESTINATION");
labelRow.appendChild(destinationLabel);

var departureLabel = document.createElement("th");
departureLabel.className = "departure";
departureLabel.innerHTML = this.translate("DEPARTURE");
labelRow.appendChild(departureLabel);

return labelRow;
},

createSpacerRow: function () {
var spacerRow = document.createElement("tr");

var spacerHeader = document.createElement("th");
spacerHeader.className = "spacerRow";
spacerHeader.setAttribute("colSpan", "3");
spacerHeader.innerHTML = "";
spacerRow.appendChild(spacerHeader);

return spacerRow;
},

createDataRow: function (data) {
var row = document.createElement("tr");

var line = document.createElement("td");
line.className = "line";
line.innerHTML = data.route;
row.appendChild(line);

var destination = document.createElement("td");
destination.innerHTML = data.destination;
row.appendChild(destination);

var departure = document.createElement("td");
departure.className = "departure";
if (data.time == "0"){
departure.innerHTML = this.translate("NOW");
} else if (data.time.charAt(2)==":"){
departure.innerHTML = data.time + this.translate("TIME");
} else {
departure.innerHTML = data.time;
}
row.appendChild(departure);

return row;
}

});
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# MMM-KVV
<B>Station monitor</B> for the <B>Karlsruhe local transport (KVV)</B> bus, tram and train system.<P>

This module is an extension of the amazing [MagicMirror<sup>2</sup>](https://github.com/MichMich/MagicMirror) project by [MichMich](https://github.com/MichMich/) which has inspired me to share my coding skills with others as well. Check it out, you know you want to :). <P>

It's always nice to see mirrors using my work, so feel free to send me some screenshots of your implementations.<P>

Lastly, why not join in on our discussions at the official [MagicMirror<sup>2</sup> Forum](http://forum.magicmirror.builders/)?

## Screenshots

![German version](screenshots/screenshot_de.png)
![English version](screenshots/screenshot_en.png)

## Languages
As of version 1.0.0, MMM-KVV features language support for `German (de)` and `English (en)` mirrors.

## Prerequisite
A working installation of [MagicMirror<sup>2</sup>](https://github.com/MichMich/MagicMirror)

## Dependencies
* npm
* [request](https://www.npmjs.com/package/request)

## Installation
1. Navigate into your MagicMirror's `modules` folder.
2. Execute `git clone https://github.com/yo-less/MMM-KVV.git`.
3. Execute `cd MMM-KVV`.
3. Execute `npm install`.

## Module behavior
Please note that this module auto-creates a module header which displays the name of the chosen Karlsruhe local transport stop. It is therefore recommended not to add a 'header' entry to your config.js for this module.<P>
This module automatically disappears from your mirror as soon as a station has stopped offering connections at night. It reappears as soon as your chosen station is scheduled to be served again.<P>
This module has been programmed to allow for multiple instances. Simply add more MMM-KVV config entries to your config.js file to display multiple stations and configure them according to your needs.

## Configuration
Sample minimum configuration entry for your `~/MagicMirror/config/config.js`:

...

{
module: 'MMM-KVV',
position: 'top_left',
config: {
stopID: '', // Which stop would you like to have displayed?
}
} // If this isn't your last module, add a comma after the bracket

...

Sample configuration entry for your `~/MagicMirror/config/config.js` with optional parameters:

...

{
module: 'MMM-KVV',
position: 'top_left',
config: {
stopID: '', // Which stop would you like to have displayed?
maxConn: 6, // How manny connections would you like to see?
lines: '', // What lines are you interested in?
direction: '', // If you want to, you can limit the information to one of two directions
labelRow: true, // Show or hide column headers
reload: 60000 // How often should the information be updated? (In milliseconds)
}
} // If this isn't your last module, add a comma after the bracket

...

## Figuring out the correct stopID
1. Open your web browser and navigate to the [KVV Live Web Page](http://live.kvv.de).
2. Use the search field to find the stop you are interested in.
3. Once you can see the list of connections for your stop in your browser, note the information after "stopId=",<BR> this is the `StopID` you are looking for.

## Config Options
| **Option** | **Default** | **Description** |
| :---: | :---: | --- |
| stopID | de:8212:89 | <BR>Which stop would you like to have displayed? <BR><EM> Default: Karlsruhe central station (tram stop)</EM><P> |
| maxConn<BR>`optional` | 8 | <BR> How manny connections would you like to see? <P> |
| lines<BR>`optional` | | <BR> Only show connections for specific lines - use commas to choose multiple lines.<BR><EM> Example values: 'S1, 3'<BR><B>Note</B>: You <B>can</B> use spaces when setting this parameter in order to enhance legibility.</EM><P> |
| direction<BR>`optional` | | <BR> There are really "two" stops to every stop, depending on what side of the street you're standing on. You can limit the presented information to one of those "two" stops.<BR> <EM>Possible values: 1, 2</EM><P> |
| labelRow<BR>`optional` | true | <BR> Show or hide column headers<BR> <EM>Possible values: true, false</EM><P> |
| reload<BR>`optional` | 60000 | <BR> How often should the information be updated? (In milliseconds) <BR><EM> Default: Every minute </EM><P> |

## Licence
MIT License

Copyright (c) 2016 yo-less / Jens

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 9a2c215

Please sign in to comment.