Example #1
0
        public ActionResult _CompareAlert(int id)
        {
            CompareAlert alert = (CompareAlert)alertManager.GetAlertById(id);

            ViewBag.Operator = alert.Operator.GetOperator();
            return(PartialView(alert));
        }
Example #2
0
        public CompareAlert FindCompareAlert(CompareAlert alert)
        {
            CompareAlert compareAlert = null;

            try
            {
                compareAlert = context.Alerts.OfType <CompareAlert>().Where(a => a.SubjectA.ID.Equals(alert.SubjectA.ID) && a.SubjectB.ID.Equals(alert.SubjectB.ID) && a.Operator.Equals(alert.Operator)).First();
            }
            catch (Exception)
            {
                return(compareAlert);
            }
            return(compareAlert);
        }
Example #3
0
 public ActionResult _CompareAlertDropDown(CompareAlert alert)
 {
     ViewBag.Operator = alert.Operator.GetOperator();
     return(PartialView(alert));
 }
Example #4
0
        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);
        }
Example #5
0
        private async Task <bool> CheckCompareAlert(CompareAlert alert, DateTime now)
        {
            Subject subjectA = alert.SubjectA;
            Subject subjectB = alert.SubjectB;

            int fcA = 0;
            int fcB = 0;

            FeedManager feedManager = new FeedManager();
            List <Feed> feedsA;
            List <Feed> feedsB;

            DateTime end   = now;
            DateTime start = end.AddDays(-7);
            Dictionary <string, double> valuePairs = new Dictionary <string, double>();

            if (subjectA.GetType() == typeof(Person))
            {
                feedsA = await feedManager.GetPersonFeedsSinceAsync(subjectA.Name, start);

                feedsB = await feedManager.GetPersonFeedsSinceAsync(subjectB.Name, start);
            }
            else if (subjectA.GetType() == typeof(Organisation))
            {
                feedsA = await feedManager.GetOrganisationFeedsSinceAsync(subjectA.Name, start);

                feedsB = await feedManager.GetOrganisationFeedsSinceAsync(subjectB.Name, start);
            }
            else
            {
                feedsA = await feedManager.GetWordFeedsSinceAsync(subjectA.Name, start);

                feedsB = await feedManager.GetWordFeedsSinceAsync(subjectB.Name, start);
            }

            fcA = feedsA.Count();
            valuePairs.Add(subjectA.Name, fcA);
            fcB = feedsB.Count();
            valuePairs.Add(subjectB.Name, fcB);

            alert.Graph.EndDate   = end;
            alert.Graph.StartDate = start;
            alert.JsonValues      = JsonConvert.SerializeObject(valuePairs);

            switch (alert.Operator)
            {
            case Operator.GT:
                if (fcA > fcB)
                {
                    return(true);
                }
                break;

            case Operator.LT:
                if (fcA < fcB)
                {
                    return(true);
                }
                break;
            }
            return(false);
        }