Esempio n. 1
0
 public void setcp0()
 {
     var cp = new CheckPoint(new DateTime(2015, 6, 2, 13, 0, 0, DateTimeKind.Utc));
     var score = new CycleScore(cp.Cycle, DateTimeOffset.Now.Ticks);
     score.SetScore(0, new UpdateScore { EnlightenedScore = 1000, ResistanceScore = 0 }, new Mock<ICycleScoreUpdater>().Object);
     foreach (var summary in score.Summary(false))
     {
         Console.WriteLine(summary);
     }
 }
Esempio n. 2
0
        public void SkipCP()
        {
            var cp = CheckPoint.Current();
            var score = new CycleScore(cp.Cycle, DateTimeOffset.Now.Ticks);
            var updater = new Mock<ICycleScoreUpdater>().Object;

            score.SetScore(2, new UpdateScore { EnlightenedScore = 1000, ResistanceScore = 0 }, updater);
            score.SetScore(3, new UpdateScore { EnlightenedScore = 500, ResistanceScore = 0 }, updater);
            score.SetScore(4, new UpdateScore { EnlightenedScore = 500, ResistanceScore = 1999 }, updater);

            Console.WriteLine(string.Join("\n",score.Summary(false)));
        }
 public CycleScore GetScoreForCycle(CycleIdentifier cycle)
 {
     CycleScore cycleScore;
     if (!_cycleScores.TryGetValue(cycle.Id, out cycleScore))
     {
         var timestamp = DateTimeOffset.Now;
         cycleScore = new CycleScore(cycle, timestamp.Ticks);
         _timeStamps[cycle.Id] = timestamp.Ticks;
         _cycleScores[cycle.Id] = cycleScore;
     }
     return cycleScore;
 }
Esempio n. 4
0
 public void MissingCheckpoints()
 {
     var score = new CycleScore(CheckPoint.Current().Cycle,DateTimeOffset.Now.Ticks);
     foreach (var cp in score.MissingCPs())
     {
         Console.WriteLine(cp.Cp);
     }
     score.SetScore(2,new UpdateScore(new CpScore(1000, 0),0), new Mock<ICycleScoreUpdater>().Object);
     foreach (var cp in score.MissingCPs())
     {
         Console.WriteLine(cp.Cp);
     }
 }
Esempio n. 5
0
        public void CheckMessage()
        {
            var current = CheckPoint.Current();
            var score = new CycleScore(current.Cycle,DateTimeOffset.Now.Ticks);
            var updater = new Mock<ICycleScoreUpdater>().Object;

            score.SetScore(1,new UpdateScore {EnlightenedScore = 1000,ResistanceScore = 0}, updater);
            score.SetScore(2, new UpdateScore { EnlightenedScore = 1000, ResistanceScore = 0 }, updater);
            score.SetScore(3, new UpdateScore { EnlightenedScore = 1000, ResistanceScore = 0 }, updater);
            score.SetScore(4, new UpdateScore { EnlightenedScore = 1000, ResistanceScore = 0 }, updater);
            score.SetScore(5, new UpdateScore { EnlightenedScore = 1000, ResistanceScore = 0 }, updater);
            score.SetScore(6, new UpdateScore { EnlightenedScore = 1000, ResistanceScore = 0 }, updater);
            score.SetScore(7, new UpdateScore { EnlightenedScore = 1000, ResistanceScore = 0 }, updater);

            Console.WriteLine(score.ToString());
        }
        private void PostToSlack(CycleScore currentCycle)
        {
            IRestResponse response;
            if (currentCycle.HasMissingCPs())
            {
                var missingCPs = currentCycle.MissingCPs();
                //http://localhost:31790/#/6/1
                var missingMessages = missingCPs.Select(cp => string.Format("Missing CP {2}. Goto http://{0}/#/{1}/{2} to update the score", Request.RequestUri.Host.ToLower(), currentCycle.Cycle.Id,cp.Cp)).ToList();
                response = _slackSender.Send(string.Join("\n", missingMessages));
            }
            else
            {
                response = _slackSender.Send(currentCycle.ToString());
            }

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpException((int) response.StatusCode, "Error Sending To Slack. " + response.ErrorMessage);
            }
        }
        private void PostToSlack(CycleScore currentCycle)
        {
            var cp = CheckPoint.Current();
            if (currentCycle.IsSnoozed)
            {

                if (cp.IsFirstMessageOfDay())
                {
                    var snoozeMessage = string.Format("Shhh. Cycle bot is sleeping.\nGoto http://{0}/api/{1}/false to un-snooze me.\nIf you really want to know the score summary goto http://{0}/#/{1}\nI'll wake up again at {2}.", Request.RequestUri.Host.ToLower(), currentCycle.Cycle.Id, cp.NextUnsnoozeTime());
                    _slackSender.Send(snoozeMessage);
                }
                return;
            }
            if (currentCycle.Cycle.Id != cp.Cycle.Id)
            {
                return;
            }
            var missingCPs = currentCycle.MissingCPs().ToArray();

            if (missingCPs.Length == 0)
            {
                _slackSender.Send(currentCycle.ToString());
                return;
            }
            if (missingCPs.Length == 1)
            {

                _slackSender.Send(string.Format("Missing CP {2}. Goto http://{0}/#/{1}/{2} to update the score", Request.RequestUri.Host.ToLower(), currentCycle.Cycle.Id, missingCPs[0].Cp));
                return;
            }

            var cpString = ConvertToDashAndCommaString(missingCPs);

            var manymissing = string.Format("Missing CPs {2}. Goto http://{0}/#/{1} to update the score", Request.RequestUri.Host.ToLower(), currentCycle.Cycle.Id, cpString);
            _slackSender.Send(manymissing);
        }