use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.
the class SchedulerTest method twoOneTimeSessions.
@Test
public void twoOneTimeSessions() {
Schedule2 schedule = createSchedule("P2W");
Session session1 = createOneTimeSession(null);
Session session2 = createOneTimeSession("P2D");
session2.setGuid(SESSION_GUID_4);
schedule.setSessions(ImmutableList.of(session1, session2));
Timeline timeline = INSTANCE.calculateTimeline(schedule);
assertEquals(timeline.getSchedule().size(), 2);
assertEquals(timeline.getAssessments().size(), 1);
assertEquals(timeline.getSessions().size(), 2);
assertDayRange(timeline, 0, 0, 0);
assertDayRange(timeline, 1, 2, 2);
}
use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.
the class SchedulerTest method timeWindowStartExpiresAfterDayUsingDays.
@Test
public void timeWindowStartExpiresAfterDayUsingDays() {
Schedule2 schedule = createSchedule("P5D");
Session session = createOneTimeSession(null);
session.getTimeWindows().get(0).setExpiration(Period.parse("P4D"));
schedule.setSessions(ImmutableList.of(session));
Timeline timeline = INSTANCE.calculateTimeline(schedule);
assertEquals(timeline.getSchedule().size(), 1);
ScheduledSession schSession = timeline.getSchedule().get(0);
assertEquals(schSession.getStartDay(), Integer.valueOf(0));
assertEquals(schSession.getEndDay(), Integer.valueOf(4));
assertEquals(schSession.getStartTime(), LocalTime.parse("08:00"));
assertEquals(schSession.getExpiration(), Period.parse("P4D"));
}
use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.
the class SchedulerTest method timeWindowStartExpiresWithinDay.
@Test
public void timeWindowStartExpiresWithinDay() {
Schedule2 schedule = createSchedule("P2D");
// This is the default configuration of the test time window as we expect it to be typical
Session session = createOneTimeSession(null);
schedule.setSessions(ImmutableList.of(session));
Timeline timeline = INSTANCE.calculateTimeline(schedule);
assertEquals(timeline.getSchedule().size(), 1);
ScheduledSession schSession = timeline.getSchedule().get(0);
assertEquals(schSession.getStartDay(), Integer.valueOf(0));
assertEquals(schSession.getEndDay(), Integer.valueOf(0));
assertEquals(schSession.getStartTime(), LocalTime.parse("08:00"));
assertEquals(schSession.getExpiration(), Period.parse("PT8H"));
}
use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.
the class SchedulerTest method assessmentsCopiedToTimeline.
@Test
public void assessmentsCopiedToTimeline() throws Exception {
// must respect configuration differences and create separate entries in the timeline,
// and line up the $ref values between ScheduledAssessments and AssessmentInfo
// stanzas. We don't have to test the copy factory methods for ScheduledAssessment as
// this is tested separately.
Schedule2 schedule = createSchedule("P1W");
AssessmentReference ref1 = createAssessmentRef(ASSESSMENT_1_GUID);
AssessmentReference ref2 = createAssessmentRef(ASSESSMENT_2_GUID);
AssessmentReference ref3 = createAssessmentRef(ASSESSMENT_2_GUID);
ref3.setColorScheme(new ColorScheme("#111111", "#222222", "#333333", "#444444"));
AssessmentReference ref4 = createAssessmentRef(ASSESSMENT_3_GUID);
AssessmentReference ref5 = createAssessmentRef(ASSESSMENT_3_GUID);
ref5.setLabels(ImmutableList.of(new Label("en", "English")));
AssessmentReference ref6 = createAssessmentRef(ASSESSMENT_4_GUID);
Session session1 = createOneTimeSession(null);
session1.setAssessments(ImmutableList.of(ref1, ref2, ref3, ref4));
Session session2 = createRepeatingSession(null, "P10W");
session2.setAssessments(ImmutableList.of(ref3, ref4, ref5, ref6));
schedule.setSessions(ImmutableList.of(session1, session2));
Timeline timeline = INSTANCE.calculateTimeline(schedule);
assertEquals(timeline.getAssessments().size(), 6);
AssessmentInfo info1 = getByKey(timeline.getAssessments(), "932e4de6932e4de6");
assertEquals(info1.getGuid(), ASSESSMENT_1_GUID);
AssessmentInfo info2 = getByKey(timeline.getAssessments(), "5fa66c675fa66c67");
assertEquals(info2.getGuid(), ASSESSMENT_2_GUID);
assertNotNull(info2.getColorScheme());
AssessmentInfo info3 = getByKey(timeline.getAssessments(), "24df134324df1343");
assertEquals(info3.getGuid(), ASSESSMENT_3_GUID);
assertEquals(info3.getLabel(), "English");
AssessmentInfo info4 = getByKey(timeline.getAssessments(), "fa3150eafa3150ea");
assertEquals(info4.getGuid(), ASSESSMENT_2_GUID);
assertNull(info4.getColorScheme());
AssessmentInfo info5 = getByKey(timeline.getAssessments(), "75705eb175705eb1");
assertEquals(info5.getGuid(), ASSESSMENT_4_GUID);
AssessmentInfo info6 = getByKey(timeline.getAssessments(), "ae40875fae40875f");
assertEquals(info6.getGuid(), ASSESSMENT_3_GUID);
assertEquals(info6.getLabel(), "Assessment 3");
Set<String> infoRefs = timeline.getAssessments().stream().map(AssessmentInfo::getKey).collect(toSet());
Set<String> schAsmtRefs = new HashSet<>();
timeline.getSchedule().stream().forEach(schSession -> {
for (ScheduledAssessment schAsmt : schSession.getAssessments()) {
schAsmtRefs.add(schAsmt.getRefKey());
}
});
assertEquals(infoRefs, schAsmtRefs);
}
use of org.sagebionetworks.bridge.models.schedules2.timelines.Timeline in project BridgeServer2 by Sage-Bionetworks.
the class SchedulerTest method sessionInstanceGuidsAreIdemptotent.
@Test
public void sessionInstanceGuidsAreIdemptotent() {
Schedule2 schedule = createComplexSchedule();
Set<String> sessionInstanceGuids = new HashSet<>();
Timeline timeline = INSTANCE.calculateTimeline(schedule);
for (ScheduledSession schSession : timeline.getSchedule()) {
sessionInstanceGuids.add(schSession.getInstanceGuid());
}
// Re-running gets you the same set of GUIDs
Set<String> secondSessionInstanceGuids = new HashSet<>();
timeline = INSTANCE.calculateTimeline(schedule);
for (ScheduledSession schSession : timeline.getSchedule()) {
secondSessionInstanceGuids.add(schSession.getInstanceGuid());
}
assertEquals(secondSessionInstanceGuids, sessionInstanceGuids);
}
Aggregations