<commit_before>'use strict';

import moment from 'moment';
import weather from 'weather-js';
import constants from '../constants'
import { relation, request } from '../helpers'
// -- Internal
const RELATIONS = ['when', 'location'];

export default (state) => {

  return new Promise((resolve, reject) => {
    const { location, when } = relation(RELATIONS, state.nlp.relations);
    const ms = new Date()
    console.log('ActionForecastMSN'.bold.yellow, `location: ${location}, when: ${when}`);

    if (!location) return resolve( request(state, {relation: ['location']}) );

    weather.find({search: location, degreeType: 'C'}, (error, response) => {
      if (error) return reject(error);

      const item = response[0];
      const condition = _determineCondition(item.current, item.forecast, when);
      state.action = {
        ms: (new Date() - ms),
        engine: 'msn',

        type: constants.action.type.rich,
        title: `Conditions for ${item.location.name} at ${item.current.observationtime}`,
        value: condition
      }
      if (!when) state.action.related = item.forecast;

      resolve(state);
    });
  });
};

const _determineCondition = (condition = {}, forecast = [], when) => {
  let value = {
    code: condition.skycode,
    condition: condition.skytext,
    temperature: condition.temperature,
    humidity: condition.humidity,
    wind: condition.windspeed,
    date: moment(condition.date, 'YYYY-MM-DD').format(),
  };

  forecast.map( (condition) => {
    const date = moment(condition.date, 'YYYY-MM-DD');
    if (date.isSame(when, 'day')) {
      return value = {
        code: condition.skycodeday,
        condition: condition.skytextday,
        temperature: [condition.low, condition.high],<commit_msg>Action interns errors is not necessary dispatch a reject() promise<commit_after>'use strict';

import moment from 'moment';
import weather from 'weather-js';
import constants from '../constants'
import { relation, request } from '../helpers'
// -- Internal
const RELATIONS = ['when', 'location'];

export default (state) => {

  return new Promise((resolve, reject) => {
    const { location, when } = relation(RELATIONS, state.nlp.relations);
    const ms = new Date()
    console.log('ActionForecastMSN'.bold.yellow, `location: ${location}, when: ${when}`);

    if (!location) return resolve( request(state, {relation: ['location']}) );

    weather.find({search: location, degreeType: 'C'}, (error, response) => {
      if (!error) {
        const item = response[0];
        const condition = _determineCondition(item.current, item.forecast, when);
        state.action = {
          ms: (new Date() - ms),
          engine: 'msn',

          type: constants.action.type.rich,
          title: `Conditions for ${item.location.name} at ${item.current.observationtime}`,
          value: condition
        }
        if (!when) state.action.related = item.forecast;

        resolve(state);
      }
    });
  });
};

const _determineCondition = (condition = {}, forecast = [], when) => {
  let value = {
    code: condition.skycode,
    condition: condition.skytext,
    temperature: condition.temperature,
    humidity: condition.humidity,
    wind: condition.windspeed,
    date: moment(condition.date, 'YYYY-MM-DD').format(),
  };

  forecast.map( (condition) => {
    const date = moment(condition.date, 'YYYY-MM-DD');
    if (date.isSame(when, 'day')) {
      return value = {
        code: condition.skycodeday,
        condition: condition.skytextday,
        temperature: [condition.low, condition.high],
{'fraction_non_alphanumeric': 0.15427769985974754, 'fraction_numerical': 0.0005610098176718093, 'mean_word_length': 3.1805392731535758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '7229748', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1026, 'n_words': 266}