-
Notifications
You must be signed in to change notification settings - Fork 321
Tkt 405 comment3 total work load #1448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bfdab24
7ad17e4
fc0893d
f7062b5
b144ae4
245c21b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| Copyright 2017 Christoph Schneider, BarD Software s.r.o | ||
|
|
||
| This file is part of GanttProject, an opensource project management tool. | ||
|
|
||
| GanttProject is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| GanttProject is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with GanttProject. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package net.sourceforge.ganttproject.task.algorithm; | ||
|
|
||
| import net.sourceforge.ganttproject.TestSetupHelper; | ||
| import net.sourceforge.ganttproject.TestSetupHelper.TaskManagerBuilder; | ||
| import net.sourceforge.ganttproject.resource.HumanResource; | ||
| import net.sourceforge.ganttproject.task.Task; | ||
| import net.sourceforge.ganttproject.task.TaskContainmentHierarchyFacade; | ||
| import net.sourceforge.ganttproject.test.task.TaskTestCase; | ||
|
|
||
| /** | ||
| * Tests for cost calculations | ||
| * | ||
| * @author schch (Christoph Schneider) | ||
| */ | ||
| public class LoadAlgorithmTest extends TaskTestCase { | ||
| public void testSupertaskLoad() { | ||
| Task supertask = createTask(); | ||
| Task subtask1 = createTask(); | ||
| Task subtask2 = createTask(); | ||
| TaskContainmentHierarchyFacade hierarchy = getTaskManager().getTaskHierarchy(); | ||
| hierarchy.move(subtask1, supertask); | ||
| hierarchy.move(subtask2, supertask); | ||
|
|
||
| TaskManagerBuilder builder = TestSetupHelper.newTaskManagerBuilder(); | ||
| setTaskManager(builder.build()); | ||
| HumanResource joe = new HumanResource("Joe", 1, builder.getResourceManager()); | ||
|
|
||
| HumanResource jane = new HumanResource("Jane", 1, builder.getResourceManager()); | ||
|
|
||
| builder.getResourceManager().add(joe); | ||
| builder.getResourceManager().add(jane); | ||
|
|
||
| subtask1.setDuration(subtask1.getManager().createLength(5)); | ||
| subtask2.setDuration(subtask1.getManager().createLength(10)); | ||
| assertEquals(0.0, supertask.getLoad().getValue()); | ||
|
|
||
| subtask1.getAssignmentCollection().addAssignment(joe).setLoad(100f); | ||
| subtask1.getAssignmentCollection().addAssignment(jane).setLoad(50f); | ||
| assertEquals(7.5, supertask.getLoad().getValue()); | ||
| assertEquals(7.5, subtask1.getLoad().getValue()); | ||
| assertEquals(0.0, subtask2.getLoad().getValue()); | ||
|
|
||
| subtask2.getAssignmentCollection().addAssignment(jane).setLoad(50f); | ||
| assertEquals(12.5, supertask.getLoad().getValue()); | ||
| assertEquals(7.5, subtask1.getLoad().getValue()); | ||
| assertEquals(5.0, subtask2.getLoad().getValue()); | ||
| } | ||
|
|
||
| public void testTaskLoad() { | ||
| TaskManagerBuilder builder = TestSetupHelper.newTaskManagerBuilder(); | ||
| setTaskManager(builder.build()); | ||
| HumanResource joe = new HumanResource("Joe", 1, builder.getResourceManager()); | ||
|
|
||
| HumanResource jane = new HumanResource("Jane", 1, builder.getResourceManager()); | ||
|
|
||
| builder.getResourceManager().add(joe); | ||
| builder.getResourceManager().add(jane); | ||
|
|
||
| Task t = createTask(); | ||
| t.setDuration(t.getManager().createLength(2)); | ||
| assertEquals(0.0, t.getLoad().getValue()); | ||
|
|
||
| t.getAssignmentCollection().addAssignment(joe).setLoad(100f); | ||
| t.getAssignmentCollection().addAssignment(jane).setLoad(50f); | ||
| assertEquals(3.0, t.getLoad().getValue()); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,8 @@ public void setValue(Double value) { | |
| }; | ||
| private final GPOptionGroup myCostGroup = new GPOptionGroup("task.cost", myCostIsCalculated, myCostValue); | ||
|
|
||
| private final GPOptionGroup myLoadGroup = new GPOptionGroup("task.load"); | ||
|
|
||
| private JTable myTable; | ||
|
|
||
| public TaskAllocationsPanel(Task task, HumanResourceManager hrManager, RoleManager roleMgr) { | ||
|
|
@@ -78,7 +80,7 @@ public JPanel getComponent() { | |
| CommonPanel.setupComboBoxEditor(getTable().getColumnModel().getColumn(4), myRoleManager.getEnabledRoles()); | ||
|
|
||
| JPanel tablePanel = CommonPanel.createTableAndActions(myTable, myModel); | ||
| String layoutDef = "(ROW weight=1.0 (LEAF name=resources weight=0.5) (LEAF name=cost weight=0.5))"; | ||
| String layoutDef = "(ROW weight=1.0 (LEAF name=resources weight=0.5) (COLUMN weight=0.5 (LEAF name=cost weight=0.5) (LEAF name=load weight=0.5)))"; | ||
|
|
||
| JXMultiSplitPane result = new JXMultiSplitPane(); | ||
| result.setDividerSize(0); | ||
|
|
@@ -87,6 +89,7 @@ public JPanel getComponent() { | |
| result.getMultiSplitLayout().setModel(modelRoot); | ||
| result.add(tablePanel, "resources"); | ||
| result.add(UIUtil.border(createCostPanel(), 10, UIUtil.LEFT), "cost"); | ||
| result.add(UIUtil.border(createLoadPanel(), 10, UIUtil.LEFT), "load"); | ||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -122,6 +125,21 @@ public void changeValue(ChangeValueEvent event) { | |
| return result; | ||
| } | ||
|
|
||
| private JComponent createLoadPanel() { | ||
| OptionsPageBuilder builder = new OptionsPageBuilder(); | ||
|
|
||
| JPanel optionsPanel = new JPanel(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is either over- or under- engineered :) In order to use it, remove all code at lines 130-140 and replace it with Also, add the option instance: and pass it to You're almost done, the remaining thing is to set the value of |
||
| optionsPanel.add(new JLabel(GanttLanguage.getInstance().getText("option.taskProperties.load.value.label"))); | ||
| optionsPanel.add(new JLabel(myTask.getLoad().getValue().toString())); | ||
| OptionsPageBuilder.TWO_COLUMN_LAYOUT.layout(optionsPanel, 1); | ||
|
|
||
| UIUtil.createTitle(optionsPanel, builder.getI18N().getOptionGroupLabel(myLoadGroup)); | ||
|
|
||
| JPanel result = new JPanel(new BorderLayout()); | ||
| result.add(optionsPanel, BorderLayout.NORTH); | ||
| return result; | ||
| } | ||
|
|
||
| public void commit() { | ||
| if (myTable.isEditing()) { | ||
| myTable.getCellEditor().stopCellEditing(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ of the License, or (at your option) any later version. | |
| import net.sourceforge.ganttproject.task.algorithm.AlgorithmCollection; | ||
| import net.sourceforge.ganttproject.task.algorithm.AlgorithmException; | ||
| import net.sourceforge.ganttproject.task.algorithm.CostAlgorithmImpl; | ||
| import net.sourceforge.ganttproject.task.algorithm.LoadAlgorithmImpl; | ||
| import net.sourceforge.ganttproject.task.algorithm.ShiftTaskTreeAlgorithm; | ||
| import net.sourceforge.ganttproject.task.dependency.TaskDependencyException; | ||
| import net.sourceforge.ganttproject.task.dependency.TaskDependencySlice; | ||
|
|
@@ -130,6 +131,8 @@ public class TaskImpl implements Task { | |
|
|
||
| private final CostImpl myCost = new CostImpl(); | ||
|
|
||
| private final LoadImpl myLoad = new LoadImpl(); | ||
|
|
||
| private boolean isUnplugged = false; | ||
|
|
||
| public final static int NONE = 0; | ||
|
|
@@ -1277,4 +1280,19 @@ public void setCalculated(boolean calculated) { | |
| public Cost getCost() { | ||
| return myCost; | ||
| } | ||
|
|
||
| private class LoadImpl implements Load { | ||
|
|
||
| @Override | ||
| public Double getValue() { | ||
| return new LoadAlgorithmImpl().getCalculatedLoad(TaskImpl.this); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, is it possible to cache the calculated result? If it is always calculated then we're going to use CPU heavily in big projects. Probably a good place to store load, cache it and invalidate the cache is |
||
| } | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public Load getLoad() { | ||
| return myLoad; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls replace tab with 2 spaces |
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| Copyright 2017 Christoph Schneider, BarD Software s.r.o | ||
| This file is part of GanttProject, an opensource project management tool. | ||
| GanttProject is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
| GanttProject is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
| You should have received a copy of the GNU General Public License | ||
| along with GanttProject. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package net.sourceforge.ganttproject.task.algorithm; | ||
|
|
||
| import net.sourceforge.ganttproject.task.ResourceAssignment; | ||
| import net.sourceforge.ganttproject.task.Task; | ||
| import net.sourceforge.ganttproject.task.TaskContainmentHierarchyFacade; | ||
|
|
||
| /** | ||
| * Algorithm for calculating task load | ||
| * | ||
| * @author schch (Christoph Schneider) | ||
| */ | ||
| public class LoadAlgorithmImpl { | ||
| public Double getCalculatedLoad(Task t) { | ||
| Double total = new Double(0.0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any sense to use primitive type while calculating? Not sure if it matters these days from performance point, but summing non-primitive Double's in the loops below must heavily and pointlessly use autoboxing and unboxing |
||
| TaskContainmentHierarchyFacade taskHierarchy = t.getManager().getTaskHierarchy(); | ||
| if (taskHierarchy.hasNestedTasks(t)) { | ||
| for (Task child : taskHierarchy.getNestedTasks(t)) { | ||
| total = total + child.getLoad().getValue(); | ||
| } | ||
| } | ||
| for (ResourceAssignment assignment : t.getAssignments()) { | ||
| total = total + assignment.getLoad() * t.getDuration().getLength() / 100.0; | ||
| } | ||
| return total; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the weights of cost and load to 0.1 -- this will group them in the upper part of the column closer to each other