<commit_before>'use strict';

/* Timetable for local transport Module */

/* Magic Mirror
 * Module: MVG-LocalTransport
 *
 * By <NAME>
 * MIT Licensed.
 */

Module.register('MMM-MVG-LocalTransport', {
    defaults: {
        retryDelay: 1000,
        updateInterval: 30 * 1000, // Update every minute.
        animationSpeed: 2000,
        fade: true,
        fadePoint: 0.25, // Start on 1/4th of the list.
        initialLoadDelay: 0, // start delay seconds.
        apiBase: 'http://anthonygraglia.com/cgi-bin/mvg.py',
        id: ''
    },
    start: function () {
        var self = this;
        Log.info('--- ' + this.name + ': Starting module');
        this.updateTimer = null;
        this.scheduleUpdate();

        setInterval(function () {
            self.updateDom();
        }, 30000);
    },
    scheduleUpdate: function (delay) {
        var self = this;

        clearTimeout(this.updateTimer);
        this.updateTimer = setTimeout(function () {
            self.sendSocketNotification('MMM-MVG-GETDATA', self.config);
        }, !!delay ? delay : this.config.updateInterval);
    },
    socketNotificationReceived: function (notification, payload) {
        if (notification === 'MMM-MVG-DATARECEIVED') {
            if (payload.id === this.config.id) {
                this.items = payload.data;
                this.loaded = true;
            }
            this.updateDom();
            this.scheduleUpdate();
        }
    },
    getStyles: function () {
        return ['MMM-MVG-LocalTransport.css', 'font-awesome.css'];
    },
    getDom: function () {
        var wrapper = document.createElement('div');

        if (this.config.id === '') {
            wrapper.innerHTML = 'Please set the correct Station ID: ' + this.name + '.';
            wrapper.className = 'dimmed light small';
            return wrapper;
        }

        if (!this.loaded) {
            wrapper.innerHTML = 'Loading connections ...';
            wrapper.className = 'dimmed light small';
            return wrapper;
        }

        Log.info(this.name + ' : Creating departures table');

        var table = document.createElement('table');
        table.className = 'small mmm-mvg-table';

        var items = this.items;

        for (var key in items) {
            if (items.hasOwnProperty(key)) {
                var item = items[key];

                var row = document.createElement('tr');
                row.className = 'mmm-mvg-row normal';
                table.appendChild(row);

                var lineCell = document.createElement('td');
                lineCell.className = item['product'] + ' mmm-mvg-row-line';
                lineCell.innerHTML = item['label'];
                row.appendChild(lineCell);

                var destCell = document.createElement('td');
                destCell.className = 'mmm-mvg-row-destination bright';
                destCell.innerHTML = key;
                row.appendChild(destCell);

                var minutesCell = document.createElement('td');
                minutesCell.className = 'mmm-mvg-row-minutes';
                minutesCell.innerHTML = item['departureTimes'].join(', ');
                row.appendChild(minutesCell);
            }
        }

        return table;
    }
});<commit_msg>Update config options and added the option to limit the number of departures times per row.<commit_after>'use strict';

/* Timetable for local transport Module */

/* Magic Mirror
 * Module: MVG-LocalTransport
 *
 * By <NAME>
 * MIT Licensed.
 */

Module.register('MMM-MVG-LocalTransport', {
    defaults: {
        retryDelay: 10000,
        updateInterval: 30000,
        apiBase: 'http://anthonygraglia.com/cgi-bin/mvg.py',
        id: '',
        debug: false,
        perLineDepartureLimit: 3
    },
    start: function () {
        var self = this;
        Log.info('--- ' + this.name + ': Starting module');
        this.updateTimer = null;
        this.scheduleUpdate();

        setInterval(function () {
            self.updateDom();
        }, 15000);
    },
    scheduleUpdate: function (delay) {
        var self = this;

        clearTimeout(this.updateTimer);
        this.updateTimer = setTimeout(function () {
            self.sendSocketNotification('MMM-MVG-GETDATA', self.config);
        }, !!delay ? delay : this.config.updateInterval);
    },
    socketNotificationReceived: function (notification, payload) {
        if (notification === 'MMM-MVG-DATARECEIVED') {
            if (payload.id === this.config.id) {
                this.items = payload.data;
                this.loaded = true;
            }
            this.updateDom();
            this.scheduleUpdate();
        }
    },
    getStyles: function () {
        return ['MMM-MVG-LocalTransport.css', 'font-awesome.css'];
    },
    getDom: function () {
        var wrapper = document.createElement('div');

        if (this.config.id === '') {
            wrapper.innerHTML = 'Please set the correct Station ID: ' + this.name + '.';
            wrapper.className = 'dimmed light small';
            return wrapper;
        }

        if (!this.loaded) {
            wrapper.innerHTML = 'Loading connections ...';
            wrapper.className = 'dimmed light small';
            return wrapper;
        }

        Log.info(this.name + ' : Creating departures table');

        var table = document.createElement('table');
        table.className = 'small mmm-mvg-table';

        var items = this.items;

        for (var key in items) {
            if (items.hasOwnProperty(key)) {
                var item = items[key];
                var departureTimes = item['departureTimes'];

                if (departureTimes.length > this.config.perLineDepartureLimit) {
                    departureTimes.length = this.config.perLineDepartureLimit;
                }

                var row = document.createElement('tr');
                row.className = 'mmm-mvg-row normal';
                table.appendChild(row);

                var lineCell = document.createElement('td');
                lineCell.className = item['product'] + ' mmm-mvg-row-line';
                lineCell.innerHTML = item['label'];
                row.appendChild(lineCell);

                var destCell = document.createElement('td');
                destCell.className = 'mmm-mvg-row-destination bright';
                destCell.innerHTML = key;
                row.appendChild(destCell);

                var minutesCell = document.createElement('td');
                minutesCell.className = 'mmm-mvg-row-minutes';
                minutesCell.innerHTML = departureTimes.join(', ');
                row.appendChild(minutesCell);
            }
        }

        return table;
    }
});
{'fraction_non_alphanumeric': 0.1265634306134604, 'fraction_numerical': 0.006104824300178678, 'mean_word_length': 1.792931392931393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5867744', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1751, 'n_words': 376}