public IActionResult GetImage(string participantID, int progress) { var phaseSets = _phaseSetsGetter.Get(participantID); var viewModel = GetViewModel(phaseSets, progress); return(Json(new { viewModel })); }
public IActionResult GetImageDataUrls(string participantID) { var phaseSets = _phaseSetsGetter.Get(participantID); var json = JsonSerializer.Serialize(phaseSets.Encoding); Response.Headers.Add("Content-Length", $"{json.Length}"); return(Content(json, "application/json")); }
public (DateTime Start, DateTime End) GetUtc(string participantID) { var phaseSets = _phaseSetsGetter.Get(participantID); var progress = _progressGetter.Get(participantID); var testName = _testNameGetter.Get(phaseSets, progress); var testStartDelays = new Dictionary <string, TimeSpan>() { { nameof(phaseSets.Delayed), new TimeSpan(_config.TestWaitDelayedDays, 0, 0, 0) }, { nameof(phaseSets.Followup), new TimeSpan(_config.TestWaitFollowupDays, 0, 0, 0) } }; var testStartDelay = testStartDelays.ContainsKey(testName) ? testStartDelays[testName] : default; bool testNameIsImmediate = string.Equals(testName, nameof(phaseSets.Immediate)); DateTime priorPhaseStartTimeUtc; if (testNameIsImmediate) { var encodingSessionMeta = _sessionMetaRepository.Get(participantID, "Encoding"); priorPhaseStartTimeUtc = encodingSessionMeta.FinishedWhenUtc.HasValue ? encodingSessionMeta.FinishedWhenUtc.Value : throw new Exception("Encoding's FinishedWhenUtc missing unexpectedly."); } else { var priorTestName = _testNameGetter.Get(phaseSets, progress - 1); var priorTestResponses = _testResponsesRepository.GetResponsesFromMostRecentSession(participantID, priorTestName); priorPhaseStartTimeUtc = priorTestResponses.Select(x => x.WhenUtc).Min(); } var middle = priorPhaseStartTimeUtc + testStartDelay; var result = (middle.AddMinutes(-_config.TestStartTimePlusMinusMinutes), middle.AddMinutes(_config.TestStartTimePlusMinusMinutes)); return(result); }
public int Get(string participantID) { int result; var phaseSets = _phaseSetsGetter.Get(participantID); var immediateResponsesCount = _testResponsesRepository.GetResponsesFromMostRecentSession(participantID, nameof(phaseSets.Immediate)).Count(); var immediateTestComplete = immediateResponsesCount == phaseSets.Immediate.Count(); if (immediateTestComplete) { var delayedResponsesCount = _testResponsesRepository.GetResponsesFromMostRecentSession(participantID, nameof(phaseSets.Delayed)).Count(); var delayedTestComplete = delayedResponsesCount == phaseSets.Delayed.Count(); if (delayedTestComplete) { var followupResponsesCount = _testResponsesRepository.GetResponsesFromMostRecentSession(participantID, nameof(phaseSets.Followup)).Count(); var followupTestComplete = followupResponsesCount == phaseSets.Followup.Count(); if (followupTestComplete) { result = phaseSets.Immediate.Count() + phaseSets.Delayed.Count() + phaseSets.Followup.Count(); } else { result = phaseSets.Immediate.Count() + phaseSets.Delayed.Count(); } } else { result = phaseSets.Immediate.Count(); } } else { result = 0; } return(result); }
public string Get(string participantID) { var phaseSets = _phaseSetsGetter.Get(participantID); var progress = _progressGetter.Get(participantID); var result = Get(phaseSets, progress); return(result); }
public IActionResult EncodingInstructions(string participantID, Sleepinesses?stanford, string nextActionAfterImageCheck, bool showSpacebarOrientation) { _stanfordRepository.Save(participantID, "Immediate", stanford); var stimuliCount = _phaseSetsGetter.Get(participantID).EncodingCount; var targetCount = stimuliCount / 2; return(View(new EncodingInstructionsViewModel(participantID, nextActionAfterImageCheck, showSpacebarOrientation, stanford, stimuliCount, targetCount))); }
public TestInstructionsViewModel Get(string participantID) { var phaseSets = _phaseSetsGetter.Get(participantID); var progress = _progressGetter.Get(participantID); var testName = _testNameGetter.Get(phaseSets, progress); var oldJudgementsDescription = _judgementsDescriptionGetter.Get(Judgements.Old); var newJudgementsDescription = _judgementsDescriptionGetter.Get(Judgements.New); var confidenceDescriptions = _confidencesDescriptionsGetter.Get().ToDictionary(x => $"{x.Key}", x => x.Value); var stimuliCount = Convert.ToInt32(phaseSets.GetType().GetProperty($"{testName}Count").GetValue(phaseSets, null)); var result = new TestInstructionsViewModel(oldJudgementsDescription, newJudgementsDescription, confidenceDescriptions, stimuliCount); return(result); }
public IReturningUserPhaseData Get(string participantID) { var phaseSets = _phaseSetsGetter.Get(participantID); var progress = _progressGetter.Get(participantID); var testName = _testNameGetter.Get(phaseSets, progress); var stanford = _stanfordRepository.Get(participantID); DateTime? nextTestWhenUtc = default; ReturningUserAction action; var testNameIsImmediate = string.Equals(testName, nameof(phaseSets.Immediate)); var encodingRequired = !_encodingFinishedChecker.IsFinished(participantID); if (encodingRequired) { action = ReturningUserAction.NewUser; } else if (testName == default) { action = ReturningUserAction.Done; } else { var nextTestStartTime = _testStartTimeGetter.GetUtc(participantID); DateTime utcNow = DateTime.UtcNow; bool mustWait = nextTestStartTime.Start > utcNow; bool tooLate = nextTestStartTime.End < utcNow; if (mustWait) { action = ReturningUserAction.Wait; nextTestWhenUtc = nextTestStartTime.Start; } else if (tooLate) { action = ReturningUserAction.TooLate; } else { action = ReturningUserAction.Test; } } var result = new ReturningUserPhaseData(action, progress, testName, nextTestWhenUtc); return(result); }