Beispiel #1
0
        public async Task WeeklyReview(DateTime now)
        {
            FeedManager    feedManager = new FeedManager();
            List <Subject> subjects    = await repo.ReadSubjectsAsync();

            foreach (Subject subject in subjects)
            {
                int    days      = 6;
                int    fcToday   = 0;
                int    fcHistory = 0;
                float  avarage   = 0;
                double std       = 0;
                double zScore    = 0;

                List <Feed> feeds;

                DateTime      end    = now;
                DateTime      start  = end.AddDays(-7);
                List <double> values = new List <double>();

                if (subject.GetType().Equals(typeof(Person)))
                {
                    feeds = await feedManager.GetPersonFeedsSinceAsync(subject.Name, now.AddDays(-7));

                    subject.FeedCount = feeds.Count();
                }
                else if (subject.GetType().Equals(typeof(Organisation)))
                {
                    feeds = await feedManager.GetOrganisationFeedsSinceAsync(subject.Name, now.AddDays(-7));

                    subject.FeedCount = feeds.Count();
                }
                else
                {
                    feeds = await feedManager.GetWordFeedsSinceAsync(subject.Name, now.AddDays(-7));

                    subject.FeedCount = feeds.Count();
                }

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

                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;

                if (zScore > 2)
                {
                    subject.Trending = true;
                }
                else
                {
                    subject.Trending = false;
                }
            }

            await repo.UpdateSubjects(subjects);
        }