public BlogHomeResponse() { FeaturedPost = new BlogPost(); RecentPosts = new List <BlogPost>(); LatestTweets = new List <string>(); TrendAlert = new TrendAlert(); }
private TrendAlert GetTrendAlert(XDocument xDoc) { var result = new TrendAlert(); var trends = xDoc.FirstDivByClass("bh-trends"); var link = trends.FirstDescendant("a"); result.Href = link.AttributeValue("href"); result.Image.Src = link.FirstDescendant("img").AttributeValue("src"); result.Image.Src = GetAbsoluteImagePath(result.Image.Src); return(result); }
public TrendAlert FindTrendAlert(TrendAlert alert) { TrendAlert trendAlert = null; try { trendAlert = context.Alerts.OfType <TrendAlert>().Where(a => a.Subject.ID.Equals(alert.Subject.ID)).First(); } catch (Exception) { return(trendAlert); } return(trendAlert); }
public ActionResult _TrendAlertDropDown(TrendAlert alert) { return(PartialView(alert)); }
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); }
private async Task <bool> CheckTrendAlert(TrendAlert alert, DateTime now) { Subject subject = alert.Subject; int days = 6; int fcToday = 0; int fcHistory = 0; float avarage = 0; double std = 0; double zScore = 0; FeedManager feedManager = new FeedManager(); IEnumerable <Feed> feeds; DateTime end = now; DateTime start = end.AddDays(-7); Dictionary <string, List <double> > valuePairs = new Dictionary <string, List <double> >(); List <double> values = new List <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); } foreach (Feed f in feeds) { if (f.Date.Ticks >= end.AddDays(-1).Ticks) { fcToday++; } } for (int i = 6; i > 0; i--) { foreach (Feed f in feeds) { if (start.AddDays(6 - i).Ticks <= f.Date.Ticks && f.Date.Ticks < end.AddDays(-i).Ticks) { fcHistory++; } } avarage += fcHistory; values.Add(fcHistory); fcHistory = 0; } valuePairs.Add(subject.Name, values); avarage = (float)avarage / days; foreach (float item in values) { std += Math.Pow(item - avarage, 2); } std = Math.Sqrt(std / days); zScore = ((float)fcToday - avarage) / std; alert.Graph.EndDate = end; alert.Graph.StartDate = start; alert.JsonValues = JsonConvert.SerializeObject(valuePairs); if (zScore > 2) { return(true); } else { return(false); } }