<commit_before>'use strict';

const FfsApi = require('../ffs/api.js').FfsApi;
const HipchatApi = require('../hipchat/api.js').HipchatApi;
const stationboardOptionsFactory = require('../ffs/api.js').stationboardOptionsFactory;
const moment = require('moment');
const _ = require('lodash');
const cron = require('cron');
const Q = require('q');
const Journey = require('../ffs/models/journey.js');

const delayChecker = new(require('../ffs/delay-checker.js'))();
const config = require('./config.js');

function getTrainsWithDestinations(trains, destinations) {
  var destinations = destinations.map((d) => d.toLowerCase());
  return trains.filter(function (train) {
    var currentDestination = train.to.toLowerCase();
    return destinations.reduce((found, dest) => found || currentDestination.includes(dest), false);
  });
}

function checkDelay(ffsOptions) {
  var optionsFactory = new stationboardOptionsFactory({
      station: config.stationName,
      limit: config.limitTrains,
      transportations: config.transportationFilter
    })
    .withDatetime(moment())
    .withOptions(ffsOptions);

  return new FfsApi().getStationboard(optionsFactory.getOptions())
    .then((data) => {
      let journeys = data.stationboard.map((j) => Journey.fromFfsModel(j));
      return getTrainsWithDestinations(journeys, config.trainDestinations)
    })
    .then((trains) => Q.all(trains
      .filter((t) => !!t.stop.delay && delayChecker.hasChange(t))
      .map((t) => {
        var hipchatApi = new HipchatApi(config.hipchatToken);
        var message = `Ritardo di ${t.stop.delay} minuti. ${config.stationName} (${moment(t.stop.departure).format('HH:mm')}) -> ${t.to}`;
        return hipchatApi.sendNotification(config.hipchatRoomId, {
          from: 'FfsDelay',
          notify: true,
          message: message
        });
      })))
    .catch((err) => console.log(err));
}

function start() {
  config.cronTimes.forEach((cronTime) => {
    new cron.CronJob({
      cronTime: cronTime,
      onTick: checkDelay,
      start: true,
      timeZone: config.timeZone
    });
  });
<commit_msg>Remove old Q library<commit_after>'use strict';

const FfsApi = require('../ffs/api.js').FfsApi;
const HipchatApi = require('../hipchat/api.js').HipchatApi;
const stationboardOptionsFactory = require('../ffs/api.js').stationboardOptionsFactory;
const moment = require('moment');
const _ = require('lodash');
const cron = require('cron');
const Journey = require('../ffs/models/journey.js');

const delayChecker = new(require('../ffs/delay-checker.js'))();
const config = require('./config.js');

function getTrainsWithDestinations(trains, destinations) {
  var destinations = destinations.map((d) => d.toLowerCase());
  return trains.filter(function (train) {
    var currentDestination = train.to.toLowerCase();
    return destinations.reduce((found, dest) => found || currentDestination.includes(dest), false);
  });
}

function checkDelay(ffsOptions) {
  var optionsFactory = new stationboardOptionsFactory({
      station: config.stationName,
      limit: config.limitTrains,
      transportations: config.transportationFilter
    })
    .withDatetime(moment())
    .withOptions(ffsOptions);

  return new FfsApi().getStationboard(optionsFactory.getOptions())
    .then((data) => {
      let journeys = data.stationboard.map((j) => Journey.fromFfsModel(j));
      return getTrainsWithDestinations(journeys, config.trainDestinations)
    })
    .then((trains) => Promise.all(trains
      .filter((t) => !!t.stop.delay && delayChecker.hasChange(t))
      .map((t) => {
        var hipchatApi = new HipchatApi(config.hipchatToken);
        var message = `Ritardo di ${t.stop.delay} minuti. ${config.stationName} (${moment(t.stop.departure).format('HH:mm')}) -> ${t.to}`;
        return hipchatApi.sendNotification(config.hipchatRoomId, {
          from: 'FfsDelay',
          notify: true,
          message: message
        });
      })))
    .catch((err) => console.log(err));
}

function start() {
  config.cronTimes.forEach((cronTime) => {
    new cron.CronJob({
      cronTime: cronTime,
      onTick: checkDelay,
      start: true,
      timeZone: config.timeZone
    });
  });

{'fraction_non_alphanumeric': 0.16024874431954078, 'fraction_numerical': 0.0, 'mean_word_length': 3.7739726027397262, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5187767', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1287, 'n_words': 234}