示例#1
0
        public ActionResult _CheckAlert(int id)
        {
            CheckAlert alert = (CheckAlert)alertManager.GetAlertById(id);

            ViewBag.Operator = alert.Operator.GetOperator();
            ViewBag.Property = alert.SubjectProperty.GetSubject();
            return(PartialView(alert));
        }
示例#2
0
        public CheckAlert FindCheckAlert(CheckAlert alert)
        {
            CheckAlert checkAlert = null;

            try
            {
                checkAlert = context.Alerts.OfType <CheckAlert>().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(checkAlert);
            }
            return(checkAlert);
        }
示例#3
0
 public ActionResult _CheckAlertDropDown(CheckAlert alert)
 {
     ViewBag.Operator = alert.Operator.GetOperator();
     ViewBag.Property = alert.SubjectProperty.GetSubject();
     return(PartialView(alert));
 }
示例#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);
        }
示例#5
0
        private async Task <bool> CheckCheckAlert(CheckAlert alert, DateTime now)
        {
            Subject     subject     = alert.Subject;
            FeedManager feedManager = new FeedManager();
            List <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);
            }

            int fCPast = 0;

            int fc = 0;

            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)
                    {
                        fc++;
                    }
                }
                fCPast += fc;
                values.Add(fc);
                fc = 0;
            }

            fCPast = fCPast / 6;

            fCPast = (fCPast == 0) ? 1 : fCPast;

            int fCNow = 0;

            foreach (Feed f in feeds)
            {
                if (f.Date.Ticks >= end.AddDays(-1).Ticks)
                {
                    fCNow++;
                }
            }
            values.Add(fCNow);
            valuePairs.Add(subject.Name, values);

            int result;

            if (alert.SubjectProperty.Equals(SubjectProperty.relativeCount))
            {
                result = (fCNow / fCPast - 1) * 100;
            }
            else
            {
                result = fCNow - fCPast;
            }

            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);
        }