예제 #1
0
        public void AddUpdateAlarm()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ENTITITES.First(e => e.Name.Equals("Starbucks")));

            EntityAlarmRepository alarmRepository = new EntityAlarmRepository();
            EntityAlarm           alarm           = new EntityAlarm("1", "1", SentimentType.NEGATIVE, ENTITITES.First(e => e.Name.Equals("Starbucks")));

            alarmRepository.Add(alarm);

            SentimentRepository sentimentRepository = new SentimentRepository();

            sentimentRepository.Add(new Sentiment(SentimentType.NEGATIVE, "i dont like"));

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Add(AUTHOR);

            Phrase phrase = new Phrase("I dont like Starbucks", DateTime.Now, AUTHOR);

            REPOSITORY.Add(phrase);

            Assert.AreEqual(alarmRepository.Get(alarm.Id).PostCount, 1);
        }
예제 #2
0
        private void LoadGrid()
        {
            IRepository <EntityAlarm> entityAlarmRepository = new EntityAlarmRepository();
            IRepository <AuthorAlarm> authorAlarmRepository = new AuthorAlarmRepository();
            IRepository <Phrase>      phrasesRepository     = new PhraseRepository();

            List <Alert> alerts = new List <Alert>();

            #region Entity Alarms

            var activeEntityAlarms = entityAlarmRepository.GetAll().Where(a => a.IsEnabled()).ToList();

            activeEntityAlarms.ForEach(a =>
                                       alerts.Add(new Alert()
            {
                NumberDays    = a.Time.ToString(),
                CantPost      = a.PostQuantity.ToString(),
                Entity        = a.Entity.Name.ToString(),
                InitDate      = a.CreationDate.ToString("dd/MM/yyyy HH:mm"),
                SentimentType = a.Type.ToString(),
                Authors       = string.Empty
            })
                                       );

            #endregion

            #region Author Alarms

            var activeAuthorAlarms = authorAlarmRepository.GetAll().Where(a => a.IsEnabled()).ToList();

            var phrases = phrasesRepository.GetAll().ToList();


            foreach (AuthorAlarm alarm in activeAuthorAlarms)
            {
                var phrasesInRange = phrases
                                     .Where(p => p.Type == alarm.Type && alarm.InRangeOfTime(p.PostedDate))
                                     .GroupBy(p => p.Author.Username);

                string authorsName = "";

                phrasesInRange.Select(p => p.Key).ToList().ForEach(a => authorsName += a + ",");

                alerts.Add(new Alert()
                {
                    NumberDays    = alarm.Time.ToString(),
                    CantPost      = alarm.PostQuantity.ToString(),
                    Entity        = string.Empty,
                    InitDate      = alarm.CreationDate.ToString("dd/MM/yyyy HH:mm"),
                    SentimentType = alarm.Type.ToString(),
                    Authors       = authorsName.Substring(0, authorsName.Length - 1)
                });
            }
            #endregion

            dgvAlerts.DataSource = alerts.ToList();
        }
        public void ModifySentimentNoUpdateDifferentSentimentTypeAlarm()
        {
            PhraseRepository      phraseRepository = new PhraseRepository();
            EntityRepository      entityRepository = new EntityRepository();
            AuthorRepository      authorRepository = new AuthorRepository();
            EntityAlarmRepository alarmRepository  = new EntityAlarmRepository();

            Phrase    phrase    = new Phrase("i like google", DateTime.Now, AUTHOR);
            Entity    google    = new Entity("google");
            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like");

            authorRepository.Add(AUTHOR);

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            try
            {
                entityRepository.Add(google);
            }
            catch (AnalysisException) { }

            try
            {
                phrase.AnalyzePhrase(new List <Entity> {
                    google
                }, new List <Sentiment> {
                    sentiment
                });
            }
            catch (AnalysisException) { }

            try
            {
                REPOSITORY.Add(sentiment);
            }
            catch (AnalysisException) { }

            SENTIMENT.Word = "i dont like";
            SENTIMENT.Type = SentimentType.NEGATIVE;

            REPOSITORY.Modify(sentiment.Id, SENTIMENT);

            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.NEGATIVE, google);

            alarmRepository.Add(alarm);

            SENTIMENT.Word = "i really like";

            REPOSITORY.Modify(sentiment.Id, SENTIMENT);

            Assert.AreEqual(alarmRepository.Get(alarm.Id).PostCount, 0);
        }
        public void DeleteEntityDeletesAssosiatedAlarm()
        {
            EntityAlarmRepository alarmRepository = new EntityAlarmRepository();

            Entity entity = new Entity("Uber");

            REPOSITORY.Add(entity);

            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.POSITIVE, entity);

            alarmRepository.Add(alarm);

            REPOSITORY.Delete(entity.Id);

            alarmRepository.Get(alarm.Id);
        }
        public void AddSentimentUpdateAlarm()
        {
            EntityAlarmRepository alarmRepository = new EntityAlarmRepository();

            alarmRepository.Clear();

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Clear();

            PhraseRepository phraseRepository = new PhraseRepository();

            phraseRepository.Clear();

            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Clear();

            authorRepository.Add(AUTHOR);

            Phrase    phrase    = new Phrase("i like google", DateTime.Now, AUTHOR);
            Entity    google    = new Entity("google");
            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like");

            try
            {
                entityRepository.Add(google);
            }
            catch (AnalysisException) { }

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.POSITIVE, google);

            alarmRepository.Add(alarm);

            REPOSITORY.Add(sentiment);

            Assert.AreEqual(alarmRepository.Get(alarm.Id).PostCount, 1);
        }
        public void SetUp()
        {
            AUTHOR = new Author("sada", "sadasd", "sdaasd", new DateTime(1995, 2, 3));

            ENTITY     = new Entity("Google");
            ALARM      = new EntityAlarm("1", "1", SentimentType.POSITIVE, ENTITY);
            REPOSITORY = new EntityAlarmRepository();

            ENTITIES = new List <Entity> {
                ENTITY
            };
            SENTIMENTS = new List <Sentiment> {
                new Sentiment(SentimentType.POSITIVE, "I like")
            };
            PHRASES = new List <Phrase>();

            Phrase phrase = new Phrase("I like Google", DateTime.Now, AUTHOR);

            phrase.AnalyzePhrase(ENTITIES, SENTIMENTS);
            PHRASES.Add(phrase);

            CleanRepositories();
        }