コード例 #1
0
ファイル: Summarizer.cs プロジェクト: izevaka/stacktagz
        public TimeseriesResult Filter(TimeseriesResult timeSeriesResult)
        {
            //remove all tags with one question
            var ret = timeSeriesResult.Timeseries.OrderBy(kv => kv.Value.Count(), new DescendingOrderComparer()).Take(10).ToDictionary(kv=>kv.Key, kv=>kv.Value);

            return new TimeseriesResult(timeSeriesResult.RollupType,ret);
        }
コード例 #2
0
        public void SaveTimeseries(string site, int userId, TimeseriesResult result)
        {
            var tsResult = m_Entities.CreateTSResult();
            tsResult.Rollup = (int)result.RollupType;
            tsResult.UserId = userId;
            tsResult.Site = site;
            tsResult.LastFetched = DateTime.Now;

            SavePeriods(tsResult, result.Timeseries);

            m_Entities.AddTSResult(tsResult);
            m_Entities.SaveChanges();
        }
コード例 #3
0
        public void MyTestInitialize()
        {
            m_Result = new TimeseriesResult(Rollup.Weekly);

            m_Result.Timeseries.Add("Label1", new Timeseries(Rollup.Weekly, new Dictionary<DateTime, TimeseriesPeriod> {
                {new DateTime(2009, 04, 23), new TimeseriesPeriod(1,0,0) },
                {new DateTime(2009, 04, 24), new TimeseriesPeriod(6,0,0) },
                {new DateTime(2009, 04, 25), new TimeseriesPeriod(3,0,0) }})
            );

            m_Result.Timeseries.Add("Label2", new Timeseries(Rollup.Weekly, new Dictionary<DateTime, TimeseriesPeriod> {
                {new DateTime(2009, 04, 23), new TimeseriesPeriod(4,0,0) },
                {new DateTime(2009, 04, 24), new TimeseriesPeriod(5,0,0) }})
            );
        }
コード例 #4
0
ファイル: SummarizerTest.cs プロジェクト: izevaka/stacktagz
        public void GetTimeSeriesShouldCallPersistRepoWithSameParams()
        {
            string site = string.Empty;
            int userId = 123;
            Nullable<DateTime> start = new Nullable<DateTime>();
            Nullable<DateTime> end = new Nullable<DateTime>();

            var expected = new TimeseriesResult(Rollup.Daily);
            Mock<IPersistTimeseriesRepository> persistTsRepo = new Mock<IPersistTimeseriesRepository>();
            persistTsRepo.Setup(r => r.GetTimeSeries(site, userId, start, end, Rollup.Weekly)).Returns(expected);

            Summarizer target = new Summarizer(m_questionRepo.Object, m_answerRepo.Object, m_PersistQuestionsRepo.Object, persistTsRepo.Object, m_commentsRepositoryMock.Object, m_commentsProcessorMock.Object);
            TimeseriesResult actual;
            actual = target.GetTimeSeries(site, userId, start, end, Rollup.Weekly);
            persistTsRepo.VerifyAll();
        }
コード例 #5
0
ファイル: SummarizerTest.cs プロジェクト: izevaka/stacktagz
        public void GetTimeSeriesReturnPersistRepoDataIfNotNull()
        {
            var expected = new TimeseriesResult(Rollup.Daily);
            Mock<IPersistTimeseriesRepository> persistTsRepo = new Mock<IPersistTimeseriesRepository>();
            persistTsRepo.Setup(r => r.GetTimeSeries(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<Rollup>())).Returns(expected);

            Summarizer target = new Summarizer(m_questionRepo.Object, m_answerRepo.Object, m_PersistQuestionsRepo.Object, persistTsRepo.Object, m_commentsRepositoryMock.Object, m_commentsProcessorMock.Object);
            string site = string.Empty;
            int userId = 0;
            Nullable<DateTime> start = new Nullable<DateTime>();
            Nullable<DateTime> end = new Nullable<DateTime>();
            TimeseriesResult actual;
            actual = target.GetTimeSeries(site, userId, start, end, Rollup.Weekly);
            persistTsRepo.VerifyAll();
            Assert.AreEqual(expected, actual);
        }
コード例 #6
0
ファイル: DummySummarizer.cs プロジェクト: izevaka/stacktagz
        TimeseriesResult GetDummyTimeSeries()
        {
            var result = new TimeseriesResult(Rollup.Weekly);

            result.Timeseries.Add("C#", new Timeseries(Rollup.Weekly, new Dictionary<DateTime, TimeseriesPeriod> {
                {DateTime.Now.Date.AddDays(-3), new TimeseriesPeriod( 1,2,0)},
                {DateTime.Now.Date.AddDays(-2), new TimeseriesPeriod( 0,6,1)},
                {DateTime.Now.Date.AddDays(-1), new TimeseriesPeriod( 3,0,4)}
            }
            ));

            result.Timeseries.Add("C++", new Timeseries(Rollup.Weekly, new Dictionary<DateTime, TimeseriesPeriod> {
                {DateTime.Now.Date.AddDays(-3), new TimeseriesPeriod(1,7,5)},
                {DateTime.Now.Date.AddDays(-2), new TimeseriesPeriod(5,4,1)},
                {DateTime.Now.Date.AddDays(-1), new TimeseriesPeriod(1,1,8)}
            }
            ));

            return result;
        }
コード例 #7
0
ファイル: Summarizer.cs プロジェクト: izevaka/stacktagz
        public TimeseriesResult RequestTimeSeries(string site, int userId, DateTime? start, DateTime? end, Rollup rollup)
        {
            var timeSeriesResult = new TimeseriesResult(rollup);

            var questionInfos = m_QuestionRepo.Get(site, userId);
            m_questionPersitRepo.SaveQuestions(site, questionInfos);
            var questionPoints = from q in questionInfos
                                 select q.ToTimeseriesPoint();

            var questionIds = from answer in m_AnswerRepo.Get(site, userId)
                              select new InterestPoint { QuestionId = answer.QuestionId, Date = answer.CreationDate };

            var answerPoints = GetInterestPoints(site, questionPoints, questionIds, PointType.Answer);

            if (answerPoints != null)
                questionPoints = questionPoints.Concat(answerPoints);

            var commentIds = from comment in m_commentsProcessor.ConvertAnswersToQuestions(site, m_commentsRepository.Get(site, userId))
                              select new InterestPoint { QuestionId = comment.Id, Date = comment.CreationDate };

            var commentPoints = GetInterestPoints(site, questionPoints, commentIds, PointType.Comment);
            if(commentPoints != null)
                questionPoints = questionPoints.Concat(commentPoints);

            foreach(var dataPoint in questionPoints) {
                foreach(var tag in dataPoint.Tags) {

                    Timeseries ts;
                    if(!timeSeriesResult.Timeseries.TryGetValue(tag, out ts))
                        ts = timeSeriesResult.Timeseries[tag] = timeSeriesResult.CreateTimeseries();

                    ts.Add(dataPoint.Date, dataPoint);
                }
            }

            return Filter(timeSeriesResult);
        }
コード例 #8
0
        public void DataControllerShouldCallTimeSeriesFormatter()
        {
            var tsr = new TimeseriesResult(Rollup.Weekly);

            tsr.Timeseries.Add("Label1", new Timeseries(Rollup.Weekly));

            var timeseriesRepo = new Mock<ISummarizer>();
            timeseriesRepo.Setup(t => t.GetTimeSeries("siteaddr", 123, null, null, Rollup.Weekly)).Returns(tsr);

            var converter = new Mock<JsonConverter>();
            converter.Setup(c=>c.CanConvert(It.IsAny<Type>())).Returns(false);
            converter.Setup(c => c.CanConvert(typeof(TimeseriesResult))).Returns(true);

            var dataController = new DataController(new[] { converter.Object }, timeseriesRepo.Object, m_SitesRepoMock.Object, null, null);
            var result = dataController.Index("siteaddr", 123) as ContentResult;

            Assert.AreEqual("application/json", result.ContentType);

            converter.Verify(c => c.WriteJson(It.IsAny<JsonWriter>(), It.IsAny<TimeseriesResult>(), It.IsAny<JsonSerializer>()), Times.Exactly(1));
        }