ResourceAssignment timephaseData loaded from MPP file is not correct

Hello,

I have a code to import data from MPP a file. Everything works fine except for one thing: all data is loaded correctly, but sometimes the resource assignment daily effort hours are not correct.

Here is pertinent part of my code (this is done for everyone of the tasks of the project, loaded from the MPP file), where I use timePhasedData:

private void loadResourceAssignments(final Workpackage task,
final ResourceAssignmentCollection assignments,
final Map<Long, ProjectResource> allResourcesUniqueIdMap)
throws SystemAlertException {
LOG.info("Loading Resource Assignments... WP ID = " + task.getId());

for (com.aspose.tasks.ResourceAssignment assignment : assignments) {

if (assignment.get(Asn.RESOURCE).get(Rsc.UID) != null) {
ProjectResource resource = allResourcesUniqueIdMap.get(
assignment.get(Asn.RESOURCE).get(Rsc.UID).longValue());

ProjectWorker worker = new ProjectWorker();

worker.setWorkpackage(task);
worker.setProjectResource(resource);
com.aspose.tasks.Duration work = assignment.get(Asn.WORK);
if (work != null) {
worker.setEffortValue(work.toDouble());
worker.setEffortType(getEffortType(work.getTimeUnit()));
}

com.aspose.tasks.Duration remainingWork = assignment.get(Asn.REMAINING_WORK);
if (remainingWork != null) {
worker.setDone(remainingWork.toDouble() == 0);
}

List allocationMap = new ArrayList();

TimephasedDataCollection timePhasedDataList =
assignment.getTimephasedData(assignment.get(Asn.START),
assignment.get(Asn.FINISH), TimephasedDataType.AssignmentWork);

if (timePhasedDataList != null){
for (TimephasedData timePhasedData : timePhasedDataList) {
Date timePhaseDay = timePhasedData.getStart();

ProjectWorkerAllocation allocation =
checkIfAllocationMapContainsDayAllocation(allocationMap,
timePhaseDay);

// If specific day allocation doesn't exist create a new one
if (allocation == null) {
allocation = new ProjectWorkerAllocation();
allocation.setDate(timePhaseDay);
allocation.setProjectWorker(worker);
allocation.setRate(0D);
allocationMap.add(allocation);
}
// Save work per day in minutes
allocation.setAllocation(getDayAllocationInMinutes(
timePhasedData.getValue()));
}
worker.setAllocationMap(allocationMap);
}

projectDAO.persist(worker);

}

}

}

I'm only considering the start date of the timePhasedData, since I want to save the effort hours for every day of the assignment.

So, what I get with this code is: for some projects the daily effort hours are persisted OK in the data base, but for others, I get wrong data.

I did some debugging and there is something wrong happening with the timePhasedData: instead of getting the list of all days between the start day and the end day of the resource assignment, some of the days (with effort hours in the MPP) are missing from the list.

I thought then that maybe the timePhasedData statement:

TimephasedDataCollection timePhasedDataList =assignment.getTimephasedData(
assignment.get(Asn.START),assignment.get(Asn.FINISH), TimephasedDataType. AssignmentWork);

was wrong, so I tried this statement instead:

TimephasedDataCollection timePhasedDataList = assignment.getTimephasedData();

With this change, there is now no missing day in the list of timePhaseData, but now I get repeated days in the list. I notice that for some cases I can simply add the effort hours of timePhaseData for the same day and the total was in fact the effort hour total present in the MPP file (for example for 2016/4/19 - in the MPP it has 8 hours - I got two timePhaseData with 3h36 and 4h24, respectely), but the problem was that for other repeated days I got also repeated effort hours (for example for 2016/4/4 - in the MPP it has 8 hours - I got two timePhasedData with 8 hours both, so adding them would get me 16 hours for that day, what is completly wrong).


So, am I doing something wrong here? Can you help me, please?

Hi Renata,



Thank you for writing to Aspose Support team.



We have looked into your sample code but, unfortunately, could not compile it due to missing references. Please share your sample running code along with your input MPP files with us so that we can further investigate the issue and assist you.

Thanks for you answer Kashif.


I am sorry but my code is to complex to send you for you to compile…

So, can you instead please send me an example code where I can get from the MPP file (I send as attachment an MPP that I am using for input) the daily effort hours for each of the resource assignment (i.e., the daily hours correspondent to the WORK of each resource by task).

Thank you very much!


Hi Renata,


I have checked the scenario using your sample MPP file using following code:

Project proj = <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>new
Project(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Project.mpp”
);

ChildTasksCollector collector =
<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:navy”>new
ChildTasksCollector(); <span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:gray”>//
Create a ChildTasksCollector instance

TaskUtils.apply(proj.getRootTask(),
collector,
<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>5); <span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:gray”>// Collect all the tasks from RootTask using TaskUtils

<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>for
(Task tsk : collector.getTasks())

{
System.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>out
.println(tsk.get(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>NAME
));

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>for
(ResourceAssignment assn
: tsk.getAssignments())

{

TimephasedDataCollection coll =
tsk.getTimephasedData(assn.get(Asn.
<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>START
), assn.get(Asn.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>FINISH
), TimephasedDataType.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>AssignmentWork
);

<span style=“font-size:
9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:navy”>for
(TimephasedData tm :
coll)

{

System.
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>out
.print(tm.getStart());

System.
<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>out
.println(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>", "
+
tm.getFinish());

}

}

}



It is observed that for none of the tasks, AssignmentWork type values are displayed. Could you please confirm that are there any TimephasedDataType.AssignmentWork entries present in the timephased data collection for any resource assignment in your MPP file? It seems that no such timephased data entry is present which you have used in your code. Ensure that right MPP file is sent and test above code using the MPP file which contains TimephasedDataType.AssignmentWork and share the output and issues detail in the output of above sample code with us. We will analyze the problem and provide assistance accordingly.

Dear Kashif,


Thanks for you reply.

Apparently there was some kind of incompatibility between the MPP file that I sent you and the aspose lib. The <span style=“color: rgb(51, 51, 51); font-size: 9pt; line-height: 18px; font-family: “Courier New”;”>TimephasedDataType.<span style=“font-size: 9pt; font-family: “Courier New”; color: rgb(102, 14, 122);”>AssignmentWork was not working for that specific file.

I don’t know the reason for this but I did a workaround that seems to resolve the issue. I use the <span style=“color: rgb(51, 51, 51); font-size: 9pt; line-height: 18px; font-family: “Courier New”;”>TimephasedDataType.<span style=“font-size: 9pt; font-family: “Courier New”; color: rgb(102, 14, 122);”>AssignmentRemainingWork and the <span style=“color: rgb(51, 51, 51); font-size: 9pt; line-height: 18px; font-family: “Courier New”;”>TimephasedDataType.<span style=“font-size: 9pt; font-family: “Courier New”; color: rgb(102, 14, 122);”>AssignmentActualWork to ge all the data for the ResourceAssignment and then I gether the information (to get the total assigment work).

So thanks again, everything is fine for now!

Best wishes,
Renata


Hi Renata,


Thank you for the feedback and should you have any other query related to Aspose.Tasks, please feel free to write us back.