1). Remove the days from timeline which are Saturday/Sunday or holidays
2). Remove the intra-day gaps for shifts, from the timeline. There are 3 shifts in any working day as following:
a) shift1: - 0000 – 0759 ( i.e. from midnight to 8 am in morning)
b) shift2: - 0800 – 1559 ( i.e. from 8 am in morning to 1559 pm in evening)
c) shift3: - 1600 – 2359 ( i.e. from 16 pm in evening to 2359 pm in night)
I am using the SegmentedTimeLine class to achieve the removal of gaps from time line.
There is a Calendar UI, which enables a user to select the start date and end date as a date range for which he wants to see data. The user selected criterion is represented by class FilterCriteria.
Calendar UI also allow user to de-select the week-days ( i.e. any day from Monday – Friday) for which he do not want to see the data and also provides the user to select any of the 3 shifts in a day (shift1, shift2 or shift3) for which he want data. Any shift selection requires removal of intra-day gaps.
For a test data I am taking the range as:
Start Date: - 14 Dec 2007 00:00:00
End Date: - 20 Dec 2007 23:59:59
The above dates are in 24 hour format.
There are 2 cases as below:
Case 1) User only de-selects the days for which he do not want to see data, for e.g. Saturday, Sunday and any other
holiday. Let’s say user de-selects Saturday( 15 Dec 2007 ) and Sunday ( 16 Dec 2007 )
Case 2) Along with the holidays, user also de-selects the shifts for which he do not want data i.e. intra-day charts. Let’s
say he de-selects Saturday, Sunday and Tuesday (18 Dec 2007) and selects only shift 2 (0800 – 1559) and shift 3
(1600 – 2359)
I am using two segmented time lines to form a compounded segmented time line to take care of Case 2 above. I have extended the class BaseDateAxis to override the method refreshTicksHorizontal, for removing the overlapping on time axis.
The code is as shown below:
Code: Select all
private void removeGapsFromXAxis(HttpSession httpSession) {
// FilterCriteria is a class that represent the user chosen
// holidays or shifts
long oneDaySegmentsIncluded = filterCriteria.getlstWeekDaysSelected().size() ;
long oneDaySegmentsExcluded = 7 - oneDaySegmentsIncluded;
SegmentedTimeline segTimelineWithSegSizeAsOneDay =
new SegmentedTimeline(SegmentedTimeline.DAY_SEGMENT_SIZE
, (int) oneDaySegmentsIncluded , (int) oneDaySegmentsExcluded);
segTimelineWithSegSizeAsOneDay.setStartTime(myModel.getTimebase().getTime());
if(shiftSelected){
int oneHourSegmentsIncluded =
getTotalShiftHoursIncluded(filterCriteria.getTimeIntervals());
int oneHourSegmentsExcluded = 24 - oneHourSegmentsIncluded;
int selectedShiftStartTime = filterCriteria.getStartTimeHr();
SegmentedTimeline segTimeLineWithSegSizeAsOneHour =
new SegmentedTimeline(SegmentedTimeline.HOUR_SEGMENT_SIZE
, oneHourSegmentsIncluded, oneHourSegmentsExcluded);
segTimeLineWithSegSizeAsOneHour.setStartTime(myModel.getTimebase().getTime()
+ selectedShiftStartTime * segTimeLineWithSegSizeAsOneHour.getSegmentSize());
segTimeLineWithSegSizeAsOneHour.setBaseTimeline(segTimelineWithSegSizeAsOneDay);
for (Calendar calendar : lstHolidays) {
Calendar gapCalendar = (Calendar)calendar.clone();
segTimeLineWithSegSizeAsOneHour.addBaseTimelineException(gapCalendar.getTime());
}
// IntraDayHourGap is a class that represent the shifts
//(0000 - 0759), (0800 - 1559), (1600 - 2359), that user has selected
List<IntraDayHourGap> lsIntraDayHrGap = filterCriteria.getIntraDayHourGap();
for (IntraDayHourGap intraDayHourGap : lsIntraDayHrGap) {
segTimeLineWithSegSizeAsOneHour.addException
(intraDayHourGap.getStartDate().getTime(), intraDayHourGap.getEndDate().getTime());
// e.g 14/Dec/2007 08:00:00 - 14/Dec/2007 16:00:00
}
double start = new Double(myModel.getTimebase().getTime()
+ selectedShiftStartTime *
segTimeLineWithSegSizeAsOneHour.getSegmentSize()).doubleValue();
double end = new Double(myModel.getTimebaseEnd().getTime()).doubleValue();
Range range = new Range(start, end);
xaxis.setRange(range, true, true); // xaxis is of type DateAxis
xaxis.setTimeline(segTimeLineWithSegSizeAsOneHour);
} else { //when no shift are selected, only holidays are selected
List<Date> lstGapDates = new ArrayList<Date>();
for(Calendar calendar : lstHolidays){
Calendar cal = (Calendar)calendar.clone();
lstGapDates.add(cal.getTime());
}
segTimelineWithSegSizeAsOneDay.addExceptions(lstGapDates);
}
double start = new Double(myModel.getTimebase().getTime());
double end = new Double(myModel.getTimebaseEnd().getTime()).doubleValue();
Range range = new Range(start, end);
xaxis.setRange(range, true, true);
xaxis.setTimeline(segTimelineWithSegSizeAsOneDay);
}
}
For the case 2 which, is an intra-day gap removal case, suppose user has de-selected Saturday (15 Dec 2007), Sunday (16 Dec 2007), and Tuesday (18 Dec 2007) and wants data only for shift 2 (0800 – 1559) and shift 3 (1600 – 2359). In this case the resulting chart rightly removes the intra-day gap i.e shift1 and also correctly removes the days Saturday (15 Dec 2007) and Sunday (16 Dec 2007) from the resulting timeline, but it does not removes the 18 Dec 2007, which come as a gap in a chart. I do not understand this anomalous behavior. Any help will be appreciated. Thanks in advance.
I had posted this query earlier but I am doing it again to elaborate the situation more clearly.
Regards,
Junaid