Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/lib/sentiment_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class SentimentAnalyzer
# Returns {symbol_rating: number, num_tweets: number, results: [json objs]}
# Looks up symbol in cache. If in cache, return value if not expired.
# Otherwise, fetch the tweets and process them.
# rubocop:disable MethodLength
def self.get_results(symbol)
symbol.upcase!
if Company.find_by(symbol: symbol).nil?
Expand All @@ -20,7 +19,6 @@ def self.get_results(symbol)
author: cached_result.tweet_author,
text: cached_result.tweet_text }] }
end
# rubocop:enable MethodLength

class << self
private
Expand Down Expand Up @@ -71,10 +69,14 @@ def analyze_tweets(tweets)
tweet_map = {}
tweets.each do |tweet|
res = analyzer.process(tweet.text)
# Skip adding neutral
next unless res
factor = res.sentiment == ':)' ? 1 : -1
score = factor * res.overall_probability
score = 0
case res.sentiment
when ':)'
score = res.overall_probability
when ':('
score = res.overall_probability - 1
end
total_points += score
results << res
tweet_map[tweet] = score
Expand All @@ -89,7 +91,6 @@ def analyze_tweets(tweets)
end
# rubocop:enable MethodLength, AbcSize

# rubocop:disable MethodLength
def get_closest(tweets, tweet_map, rating)
# set smallest_diff to 10 to promise we'll get a tweet
smallest_diff = 10 # on a scale of -1 to 1
Expand All @@ -104,7 +105,6 @@ def get_closest(tweets, tweet_map, rating)
end
closest
end
# rubocop:enable MethodLength

# Check cache for stored sentiment values
def get_cached_sentiment(symbol)
Expand Down