/// <summary> /// Cycle with checpoint scores /// </summary> /// <param name="cycleIdentifier"></param> /// <param name="timestampTicks"></param> /// <param name="scores"></param> public CycleScore(CycleIdentifier cycleIdentifier, long timestampTicks, params KeyValuePair <int, CpScore>[] scores) { _timestampTicks = timestampTicks; Cycle = cycleIdentifier; _scores = scores.ToDictionary(score => score.Key, val => val.Value); }
/// <summary> /// Cycle with checpoint scores /// </summary> /// <param name="cycleIdentifier"></param> /// <param name="timestampTicks"></param> /// <param name="scores"></param> public CycleScore(CycleIdentifier cycleIdentifier, long timestampTicks, params KeyValuePair<int, CpScore>[] scores) { _timestampTicks = timestampTicks; Cycle = cycleIdentifier; _scores = scores.ToDictionary(score => score.Key, val=>val.Value); }
protected CpStatus(CycleIdentifier cycle, int cp) { Cp = cp; //var localTime = new CheckPoint(cycle, cp).DateTime.ToLocalTime(); //DateTime = localTime.ToShortDateString() + " " + localTime.ToShortTimeString(); DateTime = new CheckPoint(cycle, cp).DateTime; Type = this.GetType().ToString(); }
protected CpStatus(CycleIdentifier cycle, int cp) { Cp = cp; //var localTime = new CheckPoint(cycle, cp).DateTime.ToLocalTime(); //DateTime = localTime.ToShortDateString() + " " + localTime.ToShortTimeString(); DateTime = new CheckPoint(cycle, cp).DateTime; Type = GetType().ToString(); }
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 CycleScore GetScoreForCycle(CycleIdentifier cycle) { ScoreEntity scoreEntity; if (_cycleScoresCache.TryGetValue(cycle.Id, out scoreEntity)) { return scoreEntity.CycleScore(); } scoreEntity = ScoreForCycleFromStorage(cycle); _cycleScoresCache[cycle.Id] = scoreEntity; return scoreEntity.CycleScore(); }
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; }
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 CheckPoint(DateTime dateTime) { var timesincezero = dateTime.Subtract(_zeroTime); var cps = (timesincezero.Days * 24 + timesincezero.Hours) / 5; CP = cps % 35; //rather than say this is CP 0 of cycle 2, consider it CP 35 of cycle 1 if (CP == 0) { CP = 35; Cycle = new CycleIdentifier((cps / 35) - 1); } else { Cycle = new CycleIdentifier(cps / 35); } }
private ScoreEntity ScoreForCycleFromStorage(CycleIdentifier cycle) { var scoreEntity = new ScoreEntity(cycle); var retrieveOperation = TableOperation.Retrieve<ScoreEntity>(ScoreEntity.CincinnatiArea, scoreEntity.RowKey); var retrievedResult = _cloudTable.Execute(retrieveOperation); if (retrievedResult.Result == null) { // Execute the insert operation. //don't insert yet //_cloudTable.Execute(TableOperation.Insert(scoreEntity)); return scoreEntity; } scoreEntity = (ScoreEntity) retrievedResult.Result; return scoreEntity; }
public CheckPoint(DateTime dateTime) { var timesincezero = dateTime.Subtract(_zeroTime); var cps = (timesincezero.Days*24 + timesincezero.Hours)/5; CP = cps%35; //rather than say this is CP 0 of cycle 2, consider it CP 35 of cycle 1 if (CP == 0) { CP = 35; Cycle = new CycleIdentifier((cps / 35) - 1); } else { Cycle = new CycleIdentifier(cps / 35); } }
/// <summary> /// Cycle with checpoint scores /// </summary> /// <param name="cycleIdentifier"></param> /// <param name="timestampTicks"></param> /// <param name="isSnoozed"></param> /// <param name="currentCheckPoint"></param> /// <param name="scores"></param> public CycleScore(CycleIdentifier cycleIdentifier, long timestampTicks, bool isSnoozed, CheckPoint currentCheckPoint, params KeyValuePair<int, CpScore>[] scores) { _timestampTicks = timestampTicks; Cycle = cycleIdentifier; IsSnoozed = isSnoozed; _scores = scores.ToDictionary(score => score.Key, val=>val.Value); if (Cycle.Id > currentCheckPoint.Cycle.Id) { _maxCheckPoint = 0; } else if (Cycle.Id == currentCheckPoint.Cycle.Id) { _maxCheckPoint = currentCheckPoint.CP; } else { _maxCheckPoint = 35;//past cycles } }
public bool UpdateScore(CycleIdentifier cycle, long? timestampTicks, params KeyValuePair<int, CpScore>[] cpScores) { var scoreEntity = _cycleScoresCache[cycle.Id]; if (timestampTicks.HasValue && scoreEntity.Timestamp.Ticks != timestampTicks.Value)//final check before we overwrite something we didn't mean to { return false; } if (cpScores==null || cpScores.Length == 0) { return false; } foreach (var keyValuePair in cpScores) { scoreEntity.SaveScores(keyValuePair.Key, keyValuePair.Value); } //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 }
/// <summary> /// create a new checkpoint /// </summary> /// <param name="cycleScore"></param> public ScoreEntity(CycleIdentifier cycleScore) { PartitionKey = CincinnatiArea; RowKey = cycleScore.Id.ToString(); Timestamp = DateTimeOffset.MinValue; }
public MissingScore(int cp, CycleIdentifier cycleIdentifier) : base(cycleIdentifier, cp) { }
public FutureScore(int cp, CycleIdentifier cycleIdentifier) : base(cycleIdentifier, cp) { }
public CheckPoint(CycleIdentifier cycle, int cp) { Cycle = cycle; CP = cp; }
public bool SetSnooze(CycleIdentifier cycle, long timestampTicks, bool isSnooze) { return true; }
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 CheckPoint(CycleIdentifier cycle, int cp) { Cycle = cycle; CP = cp; }
public RecordedScore(CpScore cpScore, CycleIdentifier cycleIdentifier, int cp) : base(cycleIdentifier, cp) { ResistanceScore = cpScore.ResistanceScore; EnlightenedScore = cpScore.EnlightenedScore; }
public FutureScore(int cp, CycleIdentifier cycleIdentifier) : base(cycleIdentifier, cp) { }
public MissingScore(int cp, CycleIdentifier cycleIdentifier) : base(cycleIdentifier, cp) { }