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 string Get(string participantID) { var phaseSets = _phaseSetsGetter.Get(participantID); var progress = _progressGetter.Get(participantID); var result = Get(phaseSets, progress); return(result); }
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 IActionResult Index(string participantID, Sleepinesses?stanford) { var progress = _progressGetter.Get(participantID); var testName = _testNameGetter.Get(participantID); if (stanford.HasValue) { _stanfordRepository.Save(participantID, testName, stanford.Value); } var testAllImageTypes = PhaseSetsGetter.TestOldImageTypes.Union(PhaseSetsGetter.TestNewImageTypes); var testInstructionsViewModel = _testInstructionsViewModelGetter.Get(participantID); var sessionID = Guid.NewGuid(); var viewModel = new TestIndexViewModel(participantID, progress, testName, sessionID, _config.AttentionResetDisplayDurationInMilliseconds, _config.AutomateTests, _config.TestAutomationDelayInMilliseconds, testAllImageTypes, testInstructionsViewModel, _config.ImageTypesImageUrlTemplate, _config.ImageTypesAudioUrlTemplate); return(View(viewModel)); }
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); }