private AttemptLog CreateAttemptLog(ISpunkSearchLog spunkSearchLog) { var attemptLog = new AttemptLog { AttemptName = spunkSearchLog.AttemptName, UserName = spunkSearchLog.UserName, KataName = _kataHelper.GetKataName(spunkSearchLog.AttemptName), AttemptDate = Convert.ToDateTime(spunkSearchLog.KataStartTime), LengthInMinutes = Math.Round(Convert.ToDecimal(spunkSearchLog.TotalDuration) / 60, 2, MidpointRounding.AwayFromZero), HighestLevelAchieved = Convert.ToInt32(spunkSearchLog.HighestLevelAchieved) }; var kataMaxLevel = _kataHelper.GetKataMaxLevel(attemptLog.KataName); if (kataMaxLevel != 0) { attemptLog.PercentCompleted = Math.Round((Convert.ToDecimal(attemptLog.HighestLevelAchieved) / kataMaxLevel * 100), 2, MidpointRounding.AwayFromZero); } if (spunkSearchLog.TotalDuration == null) { SetDuration(spunkSearchLog, attemptLog); } if (attemptLog.HighestLevelAchieved == kataMaxLevel) { attemptLog.Completed = true; } return(attemptLog); }
private void SetDuration(ISpunkSearchLog spunkSearchLog, AttemptLog attemptLog) { var timestamp = Convert.ToDateTime(spunkSearchLog.Timestamp); if (timestamp == DateTime.MinValue) { return; } var totalDuration = (timestamp - attemptLog.AttemptDate).GetValueOrDefault().TotalSeconds; attemptLog.LengthInMinutes = Math.Round(Convert.ToDecimal(totalDuration) / 60, 2, MidpointRounding.AwayFromZero); }