<commit_before># Description:
#   Display rain
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Command: [not included in help script]
#   rain - is it going to rain in the next hour?
#
# Author:
#   robertocarroll

moment = require 'moment'

# default greeting
greeting = 'Hello'
 # Time
currentHour = moment().hour()
if currentHour < 12
  greeting = 'Good morning'
if currentHour >= 12 && currentHour <= 17
  greeting = 'Good afternoon'
if currentHour > 17 && currentHour <= 24
  greeting = 'Good evening'

# get the weather
currentWeather = ' '
exclude = 'hourly,daily,flags'
getWeather = (msg, cb) ->
	msg.http("https://api.forecast.io/forecast/#{process.env.HUBOT_DARK_SKY_API_KEY}/53.480759,-2.242631?exclude=#{exclude}") 
    	.get() (err, res, body) ->
    		try
    			result = JSON.parse(body)
    			if result['minutely']
    				dataPoints = result['minutely']['data'] || []
    				dataPointsWithPrecipitation = []
    				mostIntenseDataPoint = {}
    				mostProbableDataPoint = {}
    				now = new Date()

    				if dataPoints.length > 0
    					totalIntensity = 0
    					for dataPoint in dataPoints
    						intensity = dataPoint['precipIntensity'] || 0
    						probability = dataPoint['precipProbability'] || 0
    						totalIntensity += (dataPoint['precipIntensity'] || 0)

    						if totalIntensity == 0
				    			currentWeather = "Excellent! Looks like a clear, dry hour."
				    		else 
				    			dataPointsWithPrecipitation.push(dataPoint)
				    			hightIntensity = mostIntenseDataPoint['precipIntensity'] || 0
				    			mostIntenseDataPoint = dataPoint if intensity > hightIntensity

				    			hightProbability = mostProbableDataPoint['precipProbability'] || 0
				    			mostProbableDataPoint = dataPoint if probability > hightProbability

				    			isAnomaly = true if dataPointsWithPrecipitation.length < 5
				    			isAnomaly = true if mostIntenseDataPoint['precipProbability'] < 0.20
				    			isAnomaly = true if totalIntensity < (3 * mostIntenseDataPoint['precipIntensity'])

				    			if !isAnomaly
				    				intensity = mostIntenseDataPoint['precipIntensity']
				    				if intensity >= 0.4
				    					_intensity = 'heavy'
				    				else if intensity >= 0.1
				    					_intensity = 'moderate'
				    				else if intensity >= 0.02
				    					_intensity = 'light'
				    				else
				    					_intensity = 'very light'


				    				probability = mostProbableDataPoint['precipProbability']
				    				if probability >= 0.99
				    					_probability = 'definitely going'
				    				else if probability >= 0.90
				    					_probability = 'very likely'
				    				else if probability >= 0.66
				    					_probability = 'likely'
				    				else if probability >= 0.33
				    					_probability = 'likely as not'	
				    				else if probability >= 0.10
				    					_probability = 'unlikely'	
				    				else
				    					_probability = 'probably not going'				

				    				timestamp = mostIntenseDataPoint['time']
				    				date = new Date(timestamp * 1000)
				    				delta = (date - now)
				    				mostIntenseFromNow = "#{Math.round(delta / 60 / 1000)}"

				    				currentWeather = "It's #{_probability} to rain in the next hour. It will probably be #{_intensity} rain in about #{mostIntenseFromNow} minutes."
				    			else 
				    				currentWeather = "Don't worry. It's probably not going to rain in the next hour."
				    				

    		catch e
    			currentWeather = "Sorry, I can't get a forecast at the moment."
    		cb currentWeather


module.exports = (robot) ->
  robot.hear /rain/i, (msg) ->
    # Weather  
    getWeather msg, (currentWeather) ->  
    	msg.send greeting + '. ' + currentWeather
    

<commit_msg>Fixed up the greeting in rain.<commit_after># Description:
#   Display rain
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Command: [not included in help script]
#   rain - is it going to rain in the next hour?
#
# Author:
#   robertocarroll

moment = require 'moment'

# default greeting


# Time
currentHour = null
greeting = null
getGreeting = (greeting) ->
	currentHour = moment().hour()
	if currentHour < 12
		greeting = 'Good morning'
	else if currentHour >= 12 && currentHour <= 17
		greeting = 'Good afternoon'
	else if currentHour > 17 && currentHour <= 24
		greeting = 'Good evening'
	else
		greeting = 'Hello'

# Weather  


# get the weather
currentWeather = ' '
exclude = 'hourly,daily,flags'
getWeather = (msg, cb) ->
	msg.http("https://api.forecast.io/forecast/#{process.env.HUBOT_DARK_SKY_API_KEY}/53.480759,-2.242631?exclude=#{exclude}") 
    	.get() (err, res, body) ->
    		try
    			result = JSON.parse(body)
    			if result['minutely']
    				dataPoints = result['minutely']['data'] || []
    				dataPointsWithPrecipitation = []
    				mostIntenseDataPoint = {}
    				mostProbableDataPoint = {}
    				now = new Date()

    				if dataPoints.length > 0
    					totalIntensity = 0
    					for dataPoint in dataPoints
    						intensity = dataPoint['precipIntensity'] || 0
    						probability = dataPoint['precipProbability'] || 0
    						totalIntensity += (dataPoint['precipIntensity'] || 0)

    						if totalIntensity == 0
				    			currentWeather = "Excellent! Looks like a clear, dry hour."
				    		else 
				    			dataPointsWithPrecipitation.push(dataPoint)
				    			hightIntensity = mostIntenseDataPoint['precipIntensity'] || 0
				    			mostIntenseDataPoint = dataPoint if intensity > hightIntensity

				    			hightProbability = mostProbableDataPoint['precipProbability'] || 0
				    			mostProbableDataPoint = dataPoint if probability > hightProbability

				    			isAnomaly = true if dataPointsWithPrecipitation.length < 5
				    			isAnomaly = true if mostIntenseDataPoint['precipProbability'] < 0.20
				    			isAnomaly = true if totalIntensity < (3 * mostIntenseDataPoint['precipIntensity'])

				    			if !isAnomaly
				    				intensity = mostIntenseDataPoint['precipIntensity']
				    				if intensity >= 0.4
				    					_intensity = 'heavy'
				    				else if intensity >= 0.1
				    					_intensity = 'moderate'
				    				else if intensity >= 0.02
				    					_intensity = 'light'
				    				else
				    					_intensity = 'very light'


				    				probability = mostProbableDataPoint['precipProbability']
				    				if probability >= 0.99
				    					_probability = 'definitely going'
				    				else if probability >= 0.90
				    					_probability = 'very likely'
				    				else if probability >= 0.66
				    					_probability = 'likely'
				    				else if probability >= 0.33
				    					_probability = 'likely as not'	
				    				else if probability >= 0.10
				    					_probability = 'unlikely'	
				    				else
				    					_probability = 'probably not going'				

				    				timestamp = mostIntenseDataPoint['time']
				    				date = new Date(timestamp * 1000)
				    				delta = (date - now)
				    				mostIntenseFromNow = "#{Math.round(delta / 60 / 1000)}"

				    				currentWeather = "It's #{_probability} to rain in the next hour. It will probably be #{_intensity} rain in about #{mostIntenseFromNow} minutes."
				    			else 
				    				currentWeather = "Don't worry. It's probably not going to rain in the next hour."
				    				

    		catch e
    			currentWeather = "Sorry, I can't get a forecast at the moment."
    		cb currentWeather


module.exports = (robot) ->
  robot.hear /rain/i, (msg) ->
  	getWeather msg, (currentWeather) ->
  		theGreeting = getGreeting(greeting)
  		msg.send theGreeting + '. ' + currentWeather
    


{'fraction_non_alphanumeric': 0.09725521245711269, 'fraction_numerical': 0.018474531538664556, 'mean_word_length': 2.238888888888889, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 40, 'https://': 2, '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': '3581997', 'n_tokens_mistral': 3130, 'n_tokens_neox': 2357, 'n_words': 586}