Read a Task's Timephased Data
Contents
[
Hide
Show
]In Microsoft Project, time-phased data is displayed on the right side of the Task Usage and Resource Usage views. Users can write this data manually and with Aspose.Tasks for Java, you can write it programmatically, or get it from a project into your application.
Working with Timephased Data
Aspose.Tasks for Java supports reading a task’s time-phased data from Microsoft Project (MPP) files. The time-phased data is retrieved using the Task object’s TimeScaleData method.
- To retrieve the task work’s time-phased data, the TimeScaleData method takes the project’s start and finish dates as input parameters.
- To retrieve the task cost’s time-phased data, it takes an additional input parameter that specifies the type of time phase data as TaskCost.
The following piece of code shows how to read a task’s time-phased data.
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir(TaskTimephasedData.class);
4
5Project project = new Project(dataDir + "New project 2010.mpp");
6
7java.util.Calendar cal = java.util.Calendar.getInstance();
8cal.set(2013, 7, 17, 8, 0, 0);
9project.set(Prj.START_DATE, cal.getTime());
10project.set(Prj.NEW_TASKS_ARE_MANUAL, new NullableBool(false));
11
12Task task = project.getRootTask().getChildren().add("Task");
13Resource rsc = project.getResources().add("Rsc");
14rsc.set(Rsc.STANDARD_RATE, BigDecimal.valueOf(10));
15rsc.set(Rsc.OVERTIME_RATE, BigDecimal.valueOf(15));
16// 6 days duration
17task.set(Tsk.DURATION, project.getDuration(6));
18
19ResourceAssignment assn = project.getResourceAssignments().add(task, rsc);
20Date d = new Date(0);
21assn.set(Asn.STOP, new Date(0));
22assn.set(Asn.RESUME, new Date(0));
23
24// backloaded contour increases task duration from 6 to 10 days
25assn.set(Asn.WORK_CONTOUR, WorkContourType.BackLoaded);
26
27project.setBaseline(BaselineType.Baseline);
28
29task.set(Tsk.PERCENT_COMPLETE, 50);
30
31List<TimephasedData> td = assn.getTimephasedData(assn.get(Asn.START), assn.get(Asn.FINISH),
32 TimephasedDataType.AssignmentRemainingWork).toList();
33
34System.out.println(td.size());
35System.out.println(td.get(0).getValue());
36System.out.println(td.get(0).getValue());
37System.out.println(td.get(0).getValue());
38System.out.println(td.get(0).getValue());
39System.out.println(td.get(0).getValue());
40System.out.println(td.get(0).getValue());
41System.out.println(td.get(0).getValue());