<commit_before>const ForecastIo = require('forecastio');
const Router = require('express').Router;
const Trail = require(__dirname + '/../models/trail');
const hikeMatchRouter = module.exports = new Router();
const errorHandler = require(__dirname + '/../lib/db_error_handler');
const jwtAuth = require(__dirname + '/../lib/jwt_auth');

hikeMatchRouter.get('/hikematch', jwtAuth, (req, res) => {
  Trail.find({ userId: req.user._id }, (err, data) => {
    if (err) return errorHandler(err, res);

    var trailArray = data;
    var goodWeatherTrailArray = [];

    if (!trailArray.length) {
      return res.status(200).json({ msg: 'No trails in the database, please enter some trails' });
    }

    trailArray.forEach((trail) => {
      var trailLoc = trail.loc;
      var trailLon = trail.lon;
      var trailLat = trail.lat;
      var trailGoodWeather = true;

      var forecastIo = new ForecastIo('ce1e9e7c47068378251586a90ecb14cd');
      forecastIo.forecast(trailLat, '-' + trailLon).then(function(data) {
        var jsonString = JSON.stringify((data) , null, 2);
        var parsed = JSON.parse(jsonString);

        for (var i = 0; i < 3; i++) {
          var dateString = new Date(parsed['daily']['data'][i]['time']*1000); // eslint-disable-line
          dateString = new Date(dateString).toUTCString();
          date = dateString.split(' ').slice(0, 4).join(' ');

          var rainChanceString = parsed['daily']['data'][i]['precipProbability'] * 100  // eslint-disable-line

          if (rainChanceString >= 30) return trailGoodWeather = false;

          console.log(trailLoc + ' rain chance for ' + date + ' = ' +
           rainChanceString + ' %');
        }
      });
      if (trailGoodWeather) goodWeatherTrailArray.push(trail.loc);
    });

    res.status(200).json({ msg: 'You found some hikes with nice weather',
                           fairWeatherHikes: goodWeatherTrailArray
                         });
  });
});<commit_msg>refactor to output an object<commit_after>const ForecastIo = require('forecastio');
const Router = require('express').Router;
const Trail = require(__dirname + '/../models/trail');
const hikeMatchRouter = module.exports = new Router();
const errorHandler = require(__dirname + '/../lib/db_error_handler');
const jwtAuth = require(__dirname + '/../lib/jwt_auth');

hikeMatchRouter.get('/hikematch', jwtAuth, (req, res) => {
  Trail.find({
    userId: req.user._id
  }, (err, data) => {
    if (err) return errorHandler(err, res);

    var trailArray = data;
    var goodWeatherTrailArray = [];

    if (!trailArray.length) {
      return res.status(200).json({
        msg: 'No trails in the database, please enter some trails'
      });
    }

    trailArray.forEach((trail) => {
      var goodHike = {};
      var trailLoc = trail.loc;
      var trailLon = trail.lon;
      var trailLat = trail.lat;
      var trailGoodWeather = true;

      goodHike.trailName = trailLoc;
      goodHike.weatherForecast = [];

      var forecastIo = new ForecastIo('ce1e9e7c47068378251586a90ecb14cd');
      forecastIo.forecast(trailLat, '-' + trailLon).then(function (data) {
        var jsonString = JSON.stringify((data), null, 2);
        var parsed = JSON.parse(jsonString);

        for (var i = 0; i < 3; i++) {
          var dateString = new Date(parsed['daily']['data'][i]['time'] * 1000); // eslint-disable-line
          dateString = new Date(dateString).toUTCString();
          date = dateString.split(' ').slice(0, 4).join(' ');

          var rainChanceString = parsed['daily']['data'][i]['precipProbability'] * 100 // eslint-disable-line
          goodHike.weatherForecast[i] = rainChanceString;
          // if (rainChanceString >= 30) return trailGoodWeather = false;

          console.log(trailLoc + ' rain chance for ' + date + ' = ' +
            rainChanceString + ' %');
          if (i === 2) {
            console.log(goodHike);
            return goodHike
          }
        }
      });
      return goodWeatherTrailArray.push(goodHike);
      // if (trailGoodWeather) goodWeatherTrailArray.push(trail.loc);
    });

    res.status(200).json({
      msg: 'You found some hikes with nice weather',
      fairWeatherHikes: goodWeatherTrailArray
    });
  });
});
{'fraction_non_alphanumeric': 0.14984637201607184, 'fraction_numerical': 0.019617111793902152, 'mean_word_length': 2.805755395683453, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3190118', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1314, 'n_words': 287}