public ActionResult _SentimentAlert(int id) { SentimentAlert alert = (SentimentAlert)alertManager.GetAlertById(id); ViewBag.Operator = alert.Operator.GetOperator(); ViewBag.Property = alert.SubjectProperty.GetSubject(); return(PartialView(alert)); }
public SentimentAlert FindSentimentAlert(SentimentAlert alert) { SentimentAlert sentimentAlert = null; try { sentimentAlert = context.Alerts.OfType <SentimentAlert>().Where(a => a.Subject.ID.Equals(alert.Subject.ID) && a.Operator.Equals(alert.Operator) && a.SubjectProperty.Equals(alert.SubjectProperty) && a.Value.Equals(alert.Value)).First(); } catch (Exception) { return(sentimentAlert); } return(sentimentAlert); }
public ActionResult _SentimentAlertDropDown(SentimentAlert alert) { ViewBag.Operator = alert.Operator.GetOperator(); ViewBag.Property = alert.SubjectProperty.GetSubject(); return(PartialView(alert)); }
private async Task <bool> CheckSentimentAlert(SentimentAlert alert, DateTime now) { Subject subject = alert.Subject; FeedManager feedManager = new FeedManager(); List <Feed> feeds; DateTime end = now; DateTime start = end.AddDays(-7); Dictionary <string, double> valuePairs = new Dictionary <string, double>(); if (subject.GetType() == typeof(Person)) { feeds = await feedManager.GetPersonFeedsSinceAsync(subject.Name, start); } else if (subject.GetType() == typeof(Organisation)) { feeds = await feedManager.GetOrganisationFeedsSinceAsync(subject.Name, start); } else { feeds = await feedManager.GetWordFeedsSinceAsync(subject.Name, start); } int feedCount = feeds.Count(); int posNegFeeds = 0; int result; if (alert.SubjectProperty.Equals(SubjectProperty.pos)) { foreach (Feed f in feeds) { string[] sentiment = f.Sentiment.Split(','); float posneg = float.Parse(sentiment[0], System.Globalization.CultureInfo.InvariantCulture); if (posneg > 0) { posNegFeeds++; } } valuePairs.Add("Positive", posNegFeeds); valuePairs.Add("Negative", feedCount - posNegFeeds); result = posNegFeeds / feedCount; } else { foreach (Feed f in feeds) { string[] sentiment = f.Sentiment.Split(','); float posneg = float.Parse(sentiment[0], System.Globalization.CultureInfo.InvariantCulture); if (posneg < 0) { posNegFeeds++; } valuePairs.Add("Positive", feedCount - posNegFeeds); valuePairs.Add("Negative", posNegFeeds); } result = (posNegFeeds / feedCount) * 100; } alert.Graph.EndDate = end; alert.Graph.StartDate = start; alert.JsonValues = JsonConvert.SerializeObject(valuePairs); switch (alert.Operator) { case Operator.GT: if (result >= alert.Value) { return(true); } break; case Operator.LT: if (result <= alert.Value) { return(true); } break; } return(false); }
public Alert AddAlert(string subjectName, string alertType, string subjectBName, string compare, string subjectProperty, int value) { Alert alert; SubjectManager subjectManager = new SubjectManager(unitOfWorkManager); GraphManager graphManager = new GraphManager(unitOfWorkManager); Subject subject = subjectManager.GetSubjectByName(subjectName); Alert existingAlert; if (alertType.Equals("Trend")) { alert = new TrendAlert(subject); alert.Graph = graphManager.AddAlertLineGraph(); existingAlert = repo.FindTrendAlert((TrendAlert)alert); } else if (alertType.Equals("Compare")) { Subject subjectB = subjectManager.GetSubjectByName(subjectBName); Operator @operator; if (compare.Equals("GT")) { @operator = Operator.GT; } else { @operator = Operator.LT; } alert = new CompareAlert(subject, subjectB, @operator); alert.Graph = graphManager.AddAlertBarGraph(); existingAlert = repo.FindCompareAlert((CompareAlert)alert); } else if (alertType.Equals("Check")) { SubjectProperty property; if (subjectProperty.Equals("count")) { property = SubjectProperty.count; } else { property = SubjectProperty.relativeCount; } Operator @operator; if (compare.Equals("GT")) { @operator = Operator.GT; } else { @operator = Operator.LT; } alert = new CheckAlert(property, @operator, value, subject); alert.Graph = graphManager.AddAlertLineGraph(); existingAlert = repo.FindCheckAlert((CheckAlert)alert); } else { SubjectProperty property; if (subjectProperty.Equals("pos")) { property = SubjectProperty.pos; } else { property = SubjectProperty.neg; } Operator @operator; if (compare.Equals("GT")) { @operator = Operator.GT; } else { @operator = Operator.LT; } alert = new SentimentAlert(property, @operator, value, subject); alert.Graph = graphManager.AddAlertBarGraph(); existingAlert = repo.FindSentimentAlert((SentimentAlert)alert); } if (existingAlert != null) { alert = existingAlert; } else { this.Validate(alert); repo.AddAlert(alert); } return(alert); }