private static int?CalculateCPsToLeadChange(CpScore lastCpScore, int enlightenedScoreTotal, int resistanceScoreTotal)
        {
            var gainEachCp         = Math.Abs(lastCpScore.EnlightenedScore - lastCpScore.ResistanceScore);
            var amountNeededToGain = Math.Abs(resistanceScoreTotal - enlightenedScoreTotal);

            return(CPsToLeadChange(gainEachCp, amountNeededToGain));
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="checkpoint"></param>
        /// <param name="cpScore"></param>
        /// <param name="update"></param>
        /// <returns></returns>
        public bool SetScore(int checkpoint, UpdateScore updateScore, ICycleScoreUpdater update)
        {
            var cpScore = new CpScore(updateScore.ResistanceScore.Value, updateScore.EnlightenedScore.Value);

            _scores[checkpoint] = cpScore;
            //this saves it
            return(update.UpdateScore(Cycle, checkpoint, long.Parse(updateScore.TimeStamp), cpScore));
        }
Beispiel #3
0
 public OverallScore(ICollection <CpScore> cpScores, CpScore latestCpScore, int latestCp)
 {
     _cps = cpScores.Count;
     EnlightenedScoreTotal = cpScores.Sum(item => item.EnlightenedScore);
     ResistanceScoreTotal  = cpScores.Sum(item => item.ResistanceScore);
     LastCpScore           = latestCpScore;
     LastCp = latestCp;
 }
 public OverallScore(ICollection<CpScore> cpScores, CpScore latestCpScore, int latestCp)
 {
     _cps = cpScores.Count;
     EnlightenedScoreTotal = cpScores.Sum(item => item.EnlightenedScore);
     ResistanceScoreTotal = cpScores.Sum(item => item.ResistanceScore);
     LastCpScore = latestCpScore;
     LastCp = latestCp;
 }
 public bool UpdateScore(CycleIdentifier cycle, int checkpoint, long timestampTicks, CpScore cpScore)
 {
     if (_timeStamps[cycle.Id] == timestampTicks)
     {
         //shouldn't need to update _cycleScores since the CycleScore is updated elsewhere. This method is for persisting somewhere
         _timeStamps[cycle.Id] = DateTimeOffset.Now.Ticks;
         return true;
     }
     return false;
 }
 public bool UpdateScore(CycleIdentifier cycle, int checkpoint, long timestampTicks, CpScore cpScore)
 {
     var scoreEntity = _cycleScoresCache[cycle.Id];
     if (scoreEntity.Timestamp.Ticks != timestampTicks)//final check before we overwrite something we didn't mean to
     {
         return false;
     }
     scoreEntity.SaveScores(checkpoint,cpScore);
     //this does update scoreEntity.TimeStamp
     _cloudTable.Execute(scoreEntity.Timestamp == DateTimeOffset.MinValue ? TableOperation.Insert(scoreEntity) : TableOperation.Replace(scoreEntity));
     //should we check the _cloudTable.Execute().HttpStatusCode ??
     return true;
     //what is the new TimeStamp??
     //else it's not the right timestamp
 }
        public FinalScoreProjection(OverallScore overallScore, CpScore latestCheckpoint)
        {
            if (latestCheckpoint == null)
            {
                throw new ArgumentNullException("latestCheckpoint");
            }

            var cpsleft = overallScore.CheckPointsLeft;

            FinalEnlightenedScore = (overallScore.EnlightenedScoreTotal + latestCheckpoint.EnlightenedScore * cpsleft) / 35;
            FinalResistanceScore  = (overallScore.ResistanceScoreTotal + latestCheckpoint.ResistanceScore * cpsleft) / 35;

            if (FinalEnlightenedScore > FinalResistanceScore ^ overallScore.EnlightenedScoreTotal > overallScore.ResistanceScoreTotal)
            {
                CpsToLeadChange = CalculateCPsToLeadChange(latestCheckpoint, overallScore.EnlightenedScoreTotal, overallScore.ResistanceScoreTotal);
            }
        }
 private void SetResistanceScore(int cp, int resistanceScore)
 {
     CpScore cpScore;
     if (!_scores.TryGetValue(cp, out cpScore))
     {
         cpScore = new CpScore(resistanceScore, 0,null);
         _scores.Add(cp, cpScore);
         return;
     }
     _scores[cp] = new CpScore(resistanceScore, cpScore.EnlightenedScore, cpScore.Kudos);//kind od a hack, but trying to keep the CpScore immutable
 }
 private void SetKudos(int cp, string kudos)
 {
     CpScore cpScore;
     if (!_scores.TryGetValue(cp, out cpScore))
     {
         cpScore = new CpScore(0, 0, kudos);
         _scores.Add(cp, cpScore);
         return;
     }
     _scores[cp] = new CpScore(cpScore.ResistanceScore, cpScore.EnlightenedScore,kudos);
 }
 private void SetEnlightenedScore(int cp, int enlightenedScore)
 {
     CpScore cpScore;
     if (!_scores.TryGetValue(cp, out cpScore))
     {
         cpScore = new CpScore(0, enlightenedScore, null);
         _scores.Add(cp, cpScore);
     }
     _scores[cp] = new CpScore(cpScore.ResistanceScore, enlightenedScore, cpScore.Kudos);
 }
 private void SetResistanceScore(int cp, int resistanceScore)
 {
     CpScore cpScore;
     if (!_scores.TryGetValue(cp, out cpScore))
     {
         cpScore = new CpScore(resistanceScore, 0);
         _scores.Add(cp, cpScore);
         return;
     }
     cpScore.ResistanceScore = resistanceScore;
 }
 private void SetEnlightenedScore(int cp, int enlightenedScore)
 {
     CpScore cpScore;
     if (!_scores.TryGetValue(cp, out cpScore))
     {
         cpScore = new CpScore(0, enlightenedScore);
         _scores.Add(cp, cpScore);
         return;
     }
     cpScore.EnlightenedScore = enlightenedScore;
 }
 /// <summary>
 /// </summary>
 /// <param name="checkpoint"></param>
 /// <param name="cpScore"></param>
 /// <param name="update"></param>
 /// <returns></returns>
 public bool SetScore(int checkpoint, UpdateScore updateScore, ICycleScoreUpdater update)
 {
     var cpScore = new CpScore(updateScore.ResistanceScore.Value, updateScore.EnlightenedScore.Value);
     _scores[checkpoint] = cpScore;
     //this saves it
     return update.UpdateScore(Cycle, checkpoint, long.Parse(updateScore.TimeStamp), cpScore);
 }
Beispiel #14
0
 public RecordedScore(CpScore cpScore, CycleIdentifier cycleIdentifier, int cp)
     : base(cycleIdentifier, cp)
 {
     ResistanceScore  = cpScore.ResistanceScore;
     EnlightenedScore = cpScore.EnlightenedScore;
 }
Beispiel #15
0
 public UpdateScore(CpScore cpScore, long timeStamp)
     : this(timeStamp)
 {
     TimeStamp = timeStamp.ToString();
     ResistanceScore = cpScore.ResistanceScore;
     EnlightenedScore = cpScore.EnlightenedScore;
 }
Beispiel #16
0
 public RecordedScore(CpScore cpScore, CycleIdentifier cycleIdentifier, int cp)
     : base(cycleIdentifier, cp)
 {
     ResistanceScore = cpScore.ResistanceScore;
     EnlightenedScore = cpScore.EnlightenedScore;
 }
 public bool UpdateScore(CycleIdentifier cycle, int checkpoint, long timestampTicks, CpScore cpScore)
 {
     return UpdateScore(cycle, timestampTicks, new KeyValuePair<int, CpScore>(checkpoint,cpScore));
 }
 public void SaveScores(int checkpoint, CpScore cpScore)
 {
     _scores[checkpoint] = cpScore;
 }
 /// <summary>
 /// </summary>
 /// <param name="checkpoint"></param>
 /// <param name="updateScore"></param>
 /// <param name="update"></param>
 /// <returns></returns>
 public bool SetScore(int checkpoint, UpdateScore updateScore, ICycleScoreUpdater update)
 {
     var cpScore = new CpScore(updateScore.ResistanceScore.Value, updateScore.EnlightenedScore.Value, updateScore.Kudos);
     _scores[checkpoint] = cpScore;
     //this persists it
     return update.UpdateScore(Cycle, checkpoint, updateScore.ConvertTimeStamp(), cpScore);
 }
Beispiel #20
0
 public UpdateScore(CpScore cpScore, long timeStamp) : this(timeStamp)
 {
     TimeStamp        = timeStamp.ToString();
     ResistanceScore  = cpScore.ResistanceScore;
     EnlightenedScore = cpScore.EnlightenedScore;
 }