Skip to content

Commit

Permalink
Merge pull request #20 from da4throux/history
Browse files Browse the repository at this point in the history
update doc & clean velibHistory
  • Loading branch information
da4throux authored Aug 15, 2017
2 parents f8a29b4 + 628c3d5 commit 029751f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Binary file added MMM-Paris-RATP-PG 1.6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 19 additions & 2 deletions MMM-Paris-RATP-PG.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ Module.register("MMM-Paris-RATP-PG",{
},

socketNotificationReceived: function(notification, payload) {
var maxVelibArchiveAge = this.config.velibTrendDay ? 24 * 60 * 60 : this.config.velibTrendTimeScale || 60 * 60;
var velibArchiveCleaned = 0;
var now = new Date();
this.caller = notification;
switch (notification) {
case "BUS":
Expand All @@ -290,18 +293,32 @@ Module.register("MMM-Paris-RATP-PG",{
this.updateDom();
break;
case "VELIB":
if (!this.velibHistory[payload.id]) {
if (!this.velibHistory[payload.id]) { // loading of data
this.velibHistory[payload.id] = localStorage[payload.id] ? JSON.parse(localStorage[payload.id]) : [];
while ((this.velibHistory[payload.id].length > 0) && (((now - new Date(this.velibHistory[payload.id][0].lastUpdate)) / 1000) > maxVelibArchiveAge) ) {
this.velibHistory[payload.id].shift();
velibArchiveCleaned++;
}
if (this.config.debug) {
console.log (' *** First load size of velib History for ' + payload.id + ' is: ' + this.velibHistory[payload.id].length);
console.log (velibArchiveCleaned + ' elements removed');
console.log (this.velibHistory[payload.id]);
}
this.velibHistory[payload.id].push(payload);
localStorage[payload.id] = JSON.stringify(this.velibHistory[payload.id]);
if (this.config.debug) {console.log (' *** size of velib History for ' + payload.id + ' is: ' + this.velibHistory[payload.id].length);}
this.updateDom();
} else if (this.velibHistory[payload.id][this.velibHistory[payload.id].length - 1].lastUpdate != payload.lastUpdate) {
while ((this.velibHistory[payload.id].length > 0) && (((now - new Date(this.velibHistory[payload.id][0].lastUpdate)) / 1000) > maxVelibArchiveAge) ) {
this.velibHistory[payload.id].shift();
velibArchiveCleaned++;
}
this.velibHistory[payload.id].push(payload);
localStorage[payload.id] = JSON.stringify(this.velibHistory[payload.id]);
this.updateDom();
if (this.config.debug) {
console.log (' *** size of velib History for ' + payload.id + ' is: ' + this.velibHistory[payload.id].length);
console.log (' *** Update - size of velib History for ' + payload.id + ' is: ' + this.velibHistory[payload.id].length);
console.log (velibArchiveCleaned + ' elements removed');
console.log (this.velibHistory[payload.id]);
}
} else {
Expand Down
Binary file removed MMM-Paris-RATP-PG.png
Binary file not shown.
Binary file removed MMM-Paris-RATP-PG2.png
Binary file not shown.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ A module to display:
* available docks & bikes in selected Velib stations, along with the trend over the last day (configurable).

# Screenshot
![screenshot](https://github.com/da4throux/MMM-Paris-RATP-PG/blob/master/MMM-Paris-RATP-PG2.png)
![screenshot](https://github.com/da4throux/MMM-Paris-RATP-PG/blob/history/MMM-Paris-RATP-PG%201.6.png)

# API

It is based on the open REST API from Pierre Grimaud https://github.com/pgrimaud/horaires-ratp-api, which does not require any configuration / registration. Immediate use. Support v2 & v3.
It is based on the open REST API from Pierre Grimaud https://github.com/pgrimaud/horaires-ratp-api, which does not require any configuration / registration. Immediate use. Support v2 & v3 (however the v2 seems to be deprecated, so you should rely on v3).
It also use the Paris Open Data for the velib: https://opendata.paris.fr/explore/dataset/stations-velib-disponibilites-en-temps-reel/ (use it to get the 5 digits stations you will need for the configuration).

# Install
Expand Down Expand Up @@ -83,4 +83,4 @@ busStations: [
{api: 'v3', type: 'metros', line: '6', stations: 'raspail', destination: 'A'},
{type: 'velib', stations: 05029, destination: 'leaving', label 'RER'}]
```
# v1.5
# v1.6

0 comments on commit 029751f

Please sign in to comment.