/** * Returns the task in the series that has the specified description. * * @param description the name (<code>null</code> not permitted). * @return The task (possibly <code>null</code>). */ public Task get(String description) { Task result = null; int count = this.tasks.size(); for (int i = 0; i < count; i++) { Task t = (Task) this.tasks.get(i); if (t.getDescription().equals(description)) { result = t; break; } } return result; }
@Override protected Object[] createItemArray(XYDataset dataset, int series, int item) { if (dataset instanceof XYTaskDataset) { Task t = ((XYTaskDataset) dataset).getTasks().getSeries(series).get(item); Object[] result = new Object[4]; result[0] = t.getDescription(); result[1] = xformat(t.getDuration().getStart().getTime()); double y = dataset.getYValue(series, item); if (Double.isNaN(y) && dataset.getY(series, item) == null) { result[2] = this.getNullYString(); } else { result[2] = yformat(y); } result[3] = xformat(t.getDuration().getEnd().getTime()); return result; } else { return super.createItemArray(dataset, series, item); } }
private ArrayList<DefaultXYZDataset> getXYBlockChartDatasetList( HashMap<String, TaskSeries> tsMap) { ArrayList<DefaultXYZDataset> datasetList = new ArrayList<DefaultXYZDataset>(); DefaultXYZDataset datasetOverall = new DefaultXYZDataset(); datasetList.add(datasetOverall); maxArray = new double[tsMap.keySet().size() + 1]; maxArray[0] = Double.MIN_VALUE; int k = 0; if (performanceUI.isConsiderHoliday()) { holidays = performanceUI.getHolidayArray(); } int startTime = 0; int endTime = 23; if (performanceUI.isConsiderWorkingHour()) { startTime = performanceUI.getStartHour(); endTime = performanceUI.getEndHour(); } for (String key : tsMap.keySet()) { // for the individual dataset Date startDate = null; Date endDate = null; maxArray[k + 1] = Double.MIN_VALUE; TaskSeries ts = tsMap.get(key); for (int i = 0; i < ts.getTasks().size(); i++) { Task task = ts.get(i); SimpleTimePeriod stp = (SimpleTimePeriod) task.getDuration(); if (startDate == null || startDate.after(stp.getStart())) { startDate = stp.getStart(); } if (endDate == null || endDate.before(stp.getEnd())) { endDate = stp.getEnd(); } } int duration; if (endDate != null && startDate != null) { duration = (int) ((endDate.getTime() / 86400000L - startDate.getTime() / 86400000L)) + 1; } else { duration = -1; } if (duration == -1) continue; double[] xvalues = new double[duration * 24]; double[] yvalues = new double[duration * 24]; double[] zvalues = new double[duration * 24]; RegularTimePeriod t = new Day(startDate); for (int days = 0; days < duration; days++) { for (int hour = 0; hour < 24; hour++) { xvalues[days * 24 + hour] = t.getFirstMillisecond(); yvalues[days * 24 + hour] = hour; zvalues[days * 24 + hour] = 0.0; } t = t.next(); } for (int i = 0; i < ts.getTasks().size(); i++) { Task task = ts.get(i); SimpleTimePeriod stp = (SimpleTimePeriod) task.getDuration(); int day1 = (int) ((stp.getStart().getTime() / 86400000L) - (startDate.getTime() / 86400000L)); int hour1 = (int) ((stp.getStart().getTime() - (stp.getStart().getTime() / 86400000L) * 86400000L) / 3600000L); double time1 = (double) (stp.getStart().getTime() - (stp.getStart().getTime() / 3600000L) * 3600000L) / ((double) getTimeUnit()); time1 = ((double) (3600000L - time1)) / (double) getTimeUnit(); int day2 = (int) ((stp.getEnd().getTime() / 86400000L) - (startDate.getTime() / 86400000L)); int hour2 = (int) ((stp.getEnd().getTime() - (stp.getEnd().getTime() / 86400000L) * 86400000L) / 3600000L); double time2 = ((double) (stp.getEnd().getTime() - (stp.getEnd().getTime() / 3600000L) * 3600000L)) / ((double) getTimeUnit()); zvalues[day1 * 24 + hour1] = zvalues[day1 * 24 + hour1] + time1; maxArray[k + 1] = Math.max(zvalues[day1 * 24 + hour1], maxArray[k + 1]); if ((day1 * 24 + hour1) != (day2 * 24 + hour2)) { zvalues[day2 * 24 + hour2] = zvalues[day2 * 24 + hour2] + time2; maxArray[k + 1] = Math.max(zvalues[day2 * 24 + hour2], maxArray[k + 1]); } for (int j = (day1 * 24 + hour1) + 1; j < (day2 * 24 + hour2); j++) { if (!performanceUI.isConsiderHoliday() || holidays[j / 24]) { if ((j % 24) >= startTime && (j % 24) <= endTime) { zvalues[j] = zvalues[j] + (3600000.0 / getTimeUnit()); maxArray[k + 1] = Math.max(zvalues[j], maxArray[k + 1]); } } } } DefaultXYZDataset dataset = new DefaultXYZDataset(); dataset.addSeries(key, new double[][] {xvalues, yvalues, zvalues}); datasetList.add(dataset); k++; if (startDateOverall == null || startDateOverall.after(startDate)) { startDateOverall = startDate; } if (endDateOverall == null || endDateOverall.before(endDate)) { endDateOverall = endDate; } } int duration; if (endDateOverall != null && startDateOverall != null) { duration = (int) ((endDateOverall.getTime() / 86400000L - startDateOverall.getTime() / 86400000L)) + 1; } else { duration = -1; } if (duration == -1) return datasetList; double[] xvalues = new double[duration * 24]; double[] yvalues = new double[duration * 24]; double[] zvalues = new double[duration * 24]; RegularTimePeriod t = new Day(startDateOverall); for (int days = 0; days < duration; days++) { for (int hour = 0; hour < 24; hour++) { xvalues[days * 24 + hour] = t.getFirstMillisecond(); yvalues[days * 24 + hour] = hour; zvalues[days * 24 + hour] = 0.0; } t = t.next(); } for (TaskSeries ts : tsMap.values()) { for (int i = 0; i < ts.getTasks().size(); i++) { Task task = ts.get(i); SimpleTimePeriod stp = (SimpleTimePeriod) task.getDuration(); int day1 = (int) ((stp.getStart().getTime() / 86400000L) - (startDateOverall.getTime() / 86400000L)); int hour1 = (int) ((stp.getStart().getTime() - (stp.getStart().getTime() / 86400000L) * 86400000L) / 3600000L); double time1 = (double) (stp.getStart().getTime() - (stp.getStart().getTime() / 3600000L) * 3600000L) / ((double) getTimeUnit()); time1 = ((double) (3600000L - time1)) / (double) getTimeUnit(); int day2 = (int) ((stp.getEnd().getTime() / 86400000L) - (startDateOverall.getTime() / 86400000L)); int hour2 = (int) ((stp.getEnd().getTime() - (stp.getEnd().getTime() / 86400000L) * 86400000L) / 3600000L); double time2 = ((double) (stp.getEnd().getTime() - (stp.getEnd().getTime() / 3600000L) * 3600000L)) / ((double) getTimeUnit()); zvalues[day1 * 24 + hour1] = zvalues[day1 * 24 + hour1] + time1; maxArray[0] = Math.max(zvalues[day1 * 24 + hour1], maxArray[0]); if ((day1 * 24 + hour1) != (day2 * 24 + hour2)) { zvalues[day2 * 24 + hour2] = zvalues[day2 * 24 + hour2] + time2; maxArray[0] = Math.max(zvalues[day2 * 24 + hour2], maxArray[0]); } for (int j = (day1 * 24 + hour1) + 1; j < (day2 * 24 + hour2); j++) { if (!performanceUI.isConsiderHoliday() || holidays[j / 24]) { if ((j % 24) >= startTime && (j % 24) <= endTime) { zvalues[j] = zvalues[j] + (3600000.0 / getTimeUnit()); maxArray[0] = Math.max(zvalues[j], maxArray[0]); } } } } } datasetOverall.addSeries("Overall", new double[][] {xvalues, yvalues, zvalues}); return datasetList; }