Exemplo n.º 1
0
        public void VerifyAlarms2()
        {
            management.AuthorManagement.AddAuthor(author);

            Entity entity = new Entity()
            {
                EntityName = "Coca Cola"
            };
            Entity entity2 = new Entity()
            {
                EntityName = "Pepsi"
            };

            management.EntityManagement.AddEntity(entity);
            management.EntityManagement.AddEntity(entity2);
            Sentiment sentiment = new Sentiment()
            {
                SentimientText = "Me gusta",
                SentimentType  = Sentiment.TypeSentiment.Positive
            };

            management.SentimentManagement.AddSentiment(sentiment);
            EntityAlarm aAlarm = new EntityAlarm()
            {
                Entity       = entity,
                TypeOfAlarm  = EntityAlarm.Type.Positive,
                QuantityPost = 1,
                QuantityTime = 1,
                IsInHours    = false
            };

            management.AlarmManagement.AddAlarm(aAlarm);
            Phrase phrase = new Phrase()
            {
                TextPhrase   = "Me gusta Coca Cola",
                PhraseDate   = new DateTime(2020, 04, 28),
                Entity       = entity,
                PhraseType   = Phrase.TypePhrase.Positive,
                PhraseAuthor = author
            };
            Phrase phrase2 = new Phrase()
            {
                TextPhrase   = "Me gusta Pepsi",
                PhraseDate   = DateTime.Now,
                Entity       = entity2,
                PhraseType   = Phrase.TypePhrase.Positive,
                PhraseAuthor = author
            };

            management.PhraseManagement.AddPhrase(phrase);
            management.PhraseManagement.AddPhrase(phrase2);
            MockedTimeProvider provider = new MockedTimeProvider()
            {
                MockedDateTime = new DateTime(2020, 04, 30, 19, 10, 30)
            };

            management.UpdateAlarms(provider);
            Assert.IsFalse(aAlarm.IsActive);
        }
Exemplo n.º 2
0
        public void GetToString()
        {
            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.POSITIVE, ENTITY);

            string str = "Alarm POSITIVE, for Entity: Google, with PostQuantity: 1";

            Assert.AreEqual(alarm.ToString(), str);
        }
Exemplo n.º 3
0
        public void UpdateValidNumberDays()
        {
            EntityAlarm alarm = new EntityAlarm("2", "1", SentimentType.NEGATIVE, ENTITY);

            alarm.Time = "5";

            Assert.AreEqual(alarm.Time, "5");
        }
Exemplo n.º 4
0
        public void UpdateValidSentimentType()
        {
            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.NEGATIVE, ENTITY);

            alarm.Type = SentimentType.POSITIVE;

            Assert.AreEqual(alarm.Type, SentimentType.POSITIVE);
        }
Exemplo n.º 5
0
        public void UpdateValidPostQuantity()
        {
            EntityAlarm alarm = new EntityAlarm("2", "1", SentimentType.NEGATIVE, ENTITY);

            alarm.PostQuantity = "61";

            Assert.AreEqual(alarm.PostQuantity, "61");
        }
Exemplo n.º 6
0
        public void GetAlarmStatus()
        {
            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.POSITIVE, ENTITY);

            string str = $"In 1 Days/Hours there where 0 {SentimentType.POSITIVE} posts";

            Assert.AreEqual(alarm.GetStatus(), str);
        }
        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);
        }
Exemplo n.º 8
0
        public void UpdateValidEntity()
        {
            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.NEGATIVE, ENTITY);

            Entity uber = new Entity("Uber");

            alarm.Entity = uber;

            Assert.AreEqual(alarm.Entity, uber);
        }
        private void AddAlarmUI()
        {
            EntityAlarm alarmToAdd = new EntityAlarm()
            {
                Entity       = (Entity)cmbEntities.SelectedItem,
                QuantityPost = int.Parse(textBoxQuantityPost.Text),
                QuantityTime = int.Parse(textBoxQuantityTime.Text),
                TypeOfAlarm  = TypeOfAlarmChecked(),
                IsInHours    = IsInHoursTimeFrame()
            };

            generalManagement.AlarmManagement.AddAlarm(alarmToAdd);
            InitializeAlarms();
        }
        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);
        }
Exemplo n.º 11
0
        public void AnalyzeNoUpdatePostCount()
        {
            EntityAlarm alarm = new EntityAlarm("2", "1", SentimentType.NEGATIVE, ENTITY);

            Phrase phrase = new Phrase("I like google", YESTERDAY.AddDays(-25), AUTHOR);

            phrase.AnalyzePhrase(new List <Entity> {
                ENTITY
            }, new List <Sentiment> {
                new Sentiment(SentimentType.POSITIVE, "I like")
            });

            alarm.AnalyzePhrases(new List <Phrase> {
                phrase
            });

            Assert.AreEqual(alarm.PostCount, 0);
        }
Exemplo n.º 12
0
        public void IsNotEnabled()
        {
            EntityAlarm alarm = new EntityAlarm("2", "1", SentimentType.POSITIVE, ENTITY);

            Phrase phrase = new Phrase("I like google", YESTERDAY, AUTHOR);

            phrase.AnalyzePhrase(new List <Entity> {
                ENTITY
            }, new List <Sentiment> {
                new Sentiment(SentimentType.POSITIVE, "I like")
            });

            alarm.AnalyzePhrases(new List <Phrase> {
                phrase
            });

            Assert.IsFalse(alarm.IsEnabled());
        }
Exemplo n.º 13
0
        private void lstAlarms_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstAlarms.SelectedItem is null)
            {
                return;
            }

            if (rbtnEntity.Checked)
            {
                SelectedEntityAlarm = lstAlarms.SelectedItem as EntityAlarm;
                LoadEntityAlarmData(SelectedEntityAlarm);
            }
            else
            {
                SelectedAuthorAlarm = lstAlarms.SelectedItem as AuthorAlarm;
                LoadAuthorAlarmData(SelectedAuthorAlarm);
            }
        }
        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 Modify(int?id, Entity entity)
        {
            if (!id.HasValue)
            {
                throw new EntityException("You must select an Entity to modify.");
            }

            PhraseRepository      phraseRepository = new PhraseRepository();
            EntityAlarmRepository alarmRepository  = new EntityAlarmRepository();

            using (SentimentAnalysisContext context = new SentimentAnalysisContext())
            {
                var entityFound = context.Entities.FirstOrDefault(e => e.Id == id);

                if (id != entity.Id || !entityFound.Name.Equals(entity.Name))
                {
                    Exists(entity);
                }

                entityFound.Name = entity.Name;

                context.SaveChanges();

                foreach (var phrase in context.Phrases.Where(p => p.Entity == null || p.Entity.Id == entityFound.Id))
                {
                    phrase.Entity = null;

                    try
                    {
                        Phrase toModify = Helper.Instance.ToPhraseBL(phrase);
                        toModify.AnalyzePhrase(Helper.Instance.GetEntities(context.Entities), Helper.Instance.GetSentiments(context.Sentiments));
                        phraseRepository.Modify(phrase.Id, toModify);
                    }
                    catch (AnalysisException) { }
                }

                foreach (var alarm in context.EntityAlarms.ToList())
                {
                    EntityAlarm toModify = Helper.Instance.ToEntityAlarmBL(alarm);
                    toModify.ReAnalyePhrases(Helper.Instance.GetPhrases(context.Phrases));
                    alarmRepository.Modify(alarm.Alarm.Id, toModify);
                }
            }
        }
Exemplo n.º 16
0
        public void AnalyzePhraseWithoutEntity()
        {
            EntityAlarm alarm = new EntityAlarm("2", "2", SentimentType.NEGATIVE, ENTITY);

            Phrase phrase = new Phrase("I like UberEats", YESTERDAY.AddDays(-1), AUTHOR);

            try
            {
                phrase.AnalyzePhrase(new List <Entity> {
                    ENTITY
                }, new List <Sentiment> {
                    new Sentiment(SentimentType.POSITIVE, "I like")
                });
            }
            catch (AnalysisException) { }

            alarm.AnalyzePhrases(new List <Phrase> {
                phrase
            });

            Assert.AreEqual(alarm.PostCount, 0);
        }
Exemplo n.º 17
0
        public void Delete(int?id)
        {
            if (!id.HasValue)
            {
                throw new SentimentException("You must select an Sentiment to delete.");
            }

            EntityAlarmRepository alarmRepository = new EntityAlarmRepository();

            using (SentimentAnalysisContext context = new SentimentAnalysisContext())
            {
                Entities.Sentiment toRemove = context.Sentiments.FirstOrDefault(s => s.Id == id);

                if (toRemove == null)
                {
                    throw new SentimentException("Sentiment not found.");
                }

                context.Sentiments.Remove(toRemove);
                context.SaveChanges();

                foreach (var phrase in context.Phrases.Where(p => p.Type != null && p.Type == toRemove.Type))
                {
                    phrase.Type = null;
                }

                foreach (var alarm in context.EntityAlarms.ToList())
                {
                    EntityAlarm toModify = Helper.Instance.ToEntityAlarmBL(alarm);

                    try
                    {
                        alarmRepository.Modify(alarm.Id, toModify);
                    }
                    catch { }
                }
            }
        }
        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();
        }
        public void GetAllAlarms()
        {
            List <EntityAlarm> alarms = new List <EntityAlarm>();

            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);

            EntityAlarm newAlarm = new EntityAlarm("3", "1", SentimentType.NEGATIVE, ENTITY);

            alarms.Add(ALARM);
            alarms.Add(newAlarm);

            REPOSITORY.Add(ALARM);
            REPOSITORY.Add(newAlarm);

            using (SentimentAnalysisContext context = new SentimentAnalysisContext())
            {
                var repositoryAlarms = Helper.Instance.GetEntityAlarms(context.EntityAlarms);

                Assert.IsTrue(repositoryAlarms.SequenceEqual(alarms));
            }
        }
        public void AddSentimentNoUpdateDifferentSentimentTypeAlarm()
        {
            Phrase phrase = new Phrase("i like google", DateTime.Now, AUTHOR);
            Entity google = new Entity("google");

            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like");

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

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

            REPOSITORY.Add(sentiment);

            Assert.AreEqual(alarm.PostCount, 0);
        }