public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); try { //Read in request body string requestBody = new StreamReader(req.Body).ReadToEnd(); FacebookDataRequest data = JsonConvert.DeserializeObject <FacebookDataRequest>(requestBody); SentimentService sentimentService = new SentimentService(); List <AnalyseTextRequest> requests = new List <AnalyseTextRequest>(); foreach (var item in data.Posts.Where(x => x?.Data?.FirstOrDefault() != null)) { var sentimentEntity = await sentimentService.GetSentiment(new AnalyseTextRequest { ContentCreatedOn = UnixTimeStampToDateTime(double.Parse(item.Timestamp)), Medium = "Facebook", Text = item.Data.First().Post }); var result = await sentimentService.SaveSentimentResult(sentimentEntity); log.Info($"Sentiment Detected: {sentimentEntity.SentimentRating}"); } return(new OkObjectResult("Posts saved successfully")); } catch (Exception e) { log.Error("Uncaught exception occurred", e); return(new BadRequestObjectResult("An unexpected error occurred processing your request")); } }
public async Task <SentimentResponse> Handle(SentimentRequest request, CancellationToken cancellationToken) { return(await Task.Run(() => new SentimentResponse { Message = request.Message, Score = SentimentService.Predict(request.Message).Percentage } )); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); try { //TODO - Get real redirect URL: BotWebAgent webAgent = new BotWebAgent(SettingsManager.RedditUsername(), SettingsManager.RedditPassword(), SettingsManager.RedditAppid(), SettingsManager.RedditAppSecret(), "http://www.example.com/unused/redirect/uri"); var reddit = new Reddit(webAgent); var user = await reddit.GetUserAsync(SettingsManager.RedditUsername()); var comments = user.GetComments(-1); IList <AnalyseTextRequest> analyseRequests = new List <AnalyseTextRequest>(); await comments.ForEachAsync(c => { analyseRequests.Add(new AnalyseTextRequest { ContentCreatedOn = c.Created, Medium = "Reddit", Text = c.Body }); }); SentimentService sentimentService = new SentimentService(); foreach (var comment in analyseRequests) { try { log.Info($"Getting sentiment and saving comment: {comment.Text}"); var result = await sentimentService.GetSentiment(comment); await sentimentService.SaveSentimentResult(result); } catch (Exception e) { log.Error($"{e.Message}"); log.Error($"Error saving comment {comment.Text}"); } } return(new OkObjectResult("Posts saved successfully")); } catch (Exception e) { log.Error("Uncaught exception occurred", e); return(new BadRequestObjectResult("An unexpected error occurred processing your request")); } }
public DiscordListeners(Config config, DiscordSocketClient discordClient, SentimentService sentimentService, SentimentHistoryService sentimentHistoryService, SentimentSummaryService sentimentSummaryService, VoiceToTextService voiceToTextService, ChartService chartService) { this.config = config; this.discordClient = discordClient; this.sentimentService = sentimentService; this.sentimentHistoryService = sentimentHistoryService; this.sentimentSummaryService = sentimentSummaryService; this.chartService = chartService; this.semaphore = new SemaphoreSlim(1); this.voiceToTextService = voiceToTextService; this.audioChannels = new Dictionary <ulong, SocketVoiceChannel>(); this.semaphores = new Dictionary <ulong, SemaphoreSlim>(); this.streams = new Dictionary <ulong, Stream>(); this.initializedSemaphore = new SemaphoreSlim(1); }
public ActionResult Index() { GetCache(); // get tweets from twitter using hashtag. var tweets = new TweetProvider().Search("%23recognitionhack OR %23RecognitionHack -filter:retweets", _lastStatus); if (tweets.Count > 0) { // get sentiment scores for the tweets. var sentiments = new SentimentService().Get(SentimentRequestDto.CreateFromTweets(tweets)); // get the average of all the scores _sentimentScore = (_sentimentScore == 0) ? sentiments.Select(x => x.Score).ToList().Average() : ((_sentimentScore * _tweetCount) + sentiments.Select(x => x.Score).ToList().Average()) / (tweets.Count + _tweetCount); _tweetCount = _tweetCount == 0 ? tweets.Count : tweets.Count + _tweetCount; SetCache(_sentimentScore, _tweetCount, tweets.First().StatusId); } return(View(_sentimentScore)); }
public SentimentController(SentimentService sentimentService, ILineWriter lineWriter) { _sentimentService = sentimentService; _lineWriter = lineWriter; }
public AssetAddedIntegrationEventHandler(SentimentService sentimentService) { _sentimentService = sentimentService; }
public SentimentController(SentimentService sentimentService) { _sentimentService = sentimentService; }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); try { Auth.SetUserCredentials(SettingsManager.TwitterConsumerKey(), SettingsManager.TwitterConsumerSecret(), SettingsManager.TwitterUserAccessToken(), SettingsManager.TwitterUserAccessSecret()); var user = User.GetAuthenticatedUser(); var tweets = Timeline.GetUserTimeline(user, 200); var nonRetweetedTweets = tweets.Where(x => x.RetweetedTweet == null).ToList(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:7071/api/"); foreach (var tweet in nonRetweetedTweets) { var queueResult = await client.PostAsJsonAsync("AnalyseTextandPersistFunction", new AnalyseTextRequest { Text = tweet.Text, ContentCreatedOn = tweet.CreatedAt, Medium = "Twitter" } ); } //Read in request body string requestBody = new StreamReader(req.Body).ReadToEnd(); AnalyseTextRequest data = JsonConvert.DeserializeObject <AnalyseTextRequest>(requestBody); //Validate request was passed if (data == null) { return(new BadRequestObjectResult("Please pass a valid request body")); } //Log the data that was posted to us out log.Info($"Data - Medium: {data.Medium}{Environment.NewLine} Data - Posted On {data.ContentCreatedOn}{Environment.NewLine} Data - Text {data.Text}"); //Add basic validation - we can't process anything without all of the fields if (string.IsNullOrEmpty(data.Medium)) { return(new BadRequestObjectResult("Please include a medium in the request body")); } if (string.IsNullOrEmpty(data.Text) || data.Text.Length > 5000) { return(new BadRequestObjectResult("Please include text that is less than 5000 characters")); } if (data.ContentCreatedOn == default(DateTime)) { return(new BadRequestObjectResult("Please include a valid date for the content created on time and date")); } SentimentService sentimentService = new SentimentService(); //Get Sentiment and save to table var entity = await sentimentService.GetSentiment(data); var result = await sentimentService.SaveSentimentResult(entity); return(new OkObjectResult($"Sentiment Detected: {entity?.SentimentRating} - Saved to table status code: {result.HttpStatusCode}")); } catch (Exception e) { log.Error("Uncaught exception occurred", e); return(new BadRequestObjectResult("An unexpected error occurred processing your request")); } }