001: /*
002: The contents of this file are subject to the Common Public Attribution License
003: Version 1.0 (the "License"); you may not use this file except in compliance with
004: the License. You may obtain a copy of the License at
005: http://www.projity.com/license . The License is based on the Mozilla Public
006: License Version 1.1 but Sections 14 and 15 have been added to cover use of
007: software over a computer network and provide for limited attribution for the
008: Original Developer. In addition, Exhibit A has been modified to be consistent
009: with Exhibit B.
010:
011: Software distributed under the License is distributed on an "AS IS" basis,
012: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
013: specific language governing rights and limitations under the License. The
014: Original Code is OpenProj. The Original Developer is the Initial Developer and
015: is Projity, Inc. All portions of the code written by Projity are Copyright (c)
016: 2006, 2007. All Rights Reserved. Contributors Projity, Inc.
017:
018: Alternatively, the contents of this file may be used under the terms of the
019: Projity End-User License Agreeement (the Projity License), in which case the
020: provisions of the Projity License are applicable instead of those above. If you
021: wish to allow use of your version of this file only under the terms of the
022: Projity License and not to allow others to use your version of this file under
023: the CPAL, indicate your decision by deleting the provisions above and replace
024: them with the notice and other provisions required by the Projity License. If
025: you do not delete the provisions above, a recipient may use your version of this
026: file under either the CPAL or the Projity License.
027:
028: [NOTE: The text of this license may differ slightly from the text of the notices
029: in Exhibits A and B of the license at http://www.projity.com/license. You should
030: use the latest text at http://www.projity.com/license for your modifications.
031: You may not remove this license text from the source files.]
032:
033: Attribution Information: Attribution Copyright Notice: Copyright © 2006, 2007
034: Projity, Inc. Attribution Phrase (not exceeding 10 words): Powered by OpenProj,
035: an open source solution from Projity. Attribution URL: http://www.projity.com
036: Graphic Image as provided in the Covered Code as file: openproj_logo.png with
037: alternatives listed on http://www.projity.com/logo
038:
039: Display of Attribution Information is required in Larger Works which are defined
040: in the CPAL as a work which combines Covered Code or portions thereof with code
041: not governed by the terms of the CPAL. However, in addition to the other notice
042: obligations, all copies of the Covered Code in Executable and Source Code form
043: distributed must, as a form of attribution of the original author, include on
044: each user interface screen the "OpenProj" logo visible to all users. The
045: OpenProj logo should be located horizontally aligned with the menu bar and left
046: justified on the top left of the screen adjacent to the File menu. The logo
047: must be at least 100 x 25 pixels. When users click on the "OpenProj" logo it
048: must direct them back to http://www.projity.com.
049: */
050: package com.projity.pm.costing;
051:
052: import com.projity.configuration.CalculationPreference;
053: import com.projity.datatype.ImageLink;
054: import com.projity.pm.calendar.HasCalendar;
055: import com.projity.pm.snapshot.BaselineScheduleFields;
056: import com.projity.pm.snapshot.Snapshottable;
057: import com.projity.pm.time.HasStartAndEnd;
058: import com.projity.strings.Messages;
059: import com.projity.util.DateTime;
060:
061: /**
062: * Implements the earned value calculation algorithms. Currently, standard calculations
063: * are implemented, with TCPI being calculated like Project 2003 (it was different in earlier versions).
064: * Other instances can be created to implement variaions, such as Primavera's
065: */
066: public class EarnedValueCalculator {
067: private static final long defaultStart = 0;
068: private static final long defaultEnd = DateTime.getMaxDate()
069: .getTime();
070: private static EarnedValueCalculator instance = null;
071:
072: private double getDivideByZeroValue() {
073: return CalculationPreference.getActive()
074: .getEarnedValueDivideByZeroValue();
075: }
076:
077: public double acwp(EarnedValueValues ev) {
078: return ev.acwp(defaultStart, defaultEnd);
079: }
080:
081: public double bac(EarnedValueValues ev) {
082: return ev.bac(defaultStart, defaultEnd);
083: }
084:
085: public double bcwp(EarnedValueValues ev) {
086: return ev.acwp(defaultStart, defaultEnd);
087: }
088:
089: public double bcws(EarnedValueValues ev) {
090: return ev.bcws(defaultStart, defaultEnd);
091: }
092:
093: public static EarnedValueCalculator getInstance() {
094: if (instance == null)
095: instance = new EarnedValueCalculator();
096: return instance;
097: }
098:
099: private EarnedValueCalculator() {
100: }
101:
102: public double cv(EarnedValueValues ev, long start, long end) {
103: // return ev.acwp(start,end) - ev.bcwp(start,end);
104: return ev.bcwp(start, end) - ev.acwp(start, end);
105: }
106:
107: public double cv(EarnedValueValues ev) {
108: return cv(ev, defaultStart, defaultEnd);
109: }
110:
111: public double sv(EarnedValueValues ev, long start, long end) {
112: return ev.bcwp(start, end) - ev.bcws(start, end);
113: }
114:
115: public double sv(EarnedValueValues ev) {
116: return sv(ev, defaultStart, defaultEnd);
117: }
118:
119: public double eac(EarnedValueValues ev, long start, long end) {
120: double bcwp = ev.bcwp(start, end);
121: if (bcwp == 0.0D) {
122: if (getDivideByZeroValue() == 0)// prevent divide by 0
123: return 0;
124: bcwp = ev.cost(start, end); // use cost for bcwp in case no bcwp
125: }
126: double acwp = ev.acwp(start, end);
127: if (acwp == 0) {
128: if (getDivideByZeroValue() != 0)
129: return ev.cost(start, end); // use cost eac
130: }
131: return acwp + acwp * (ev.bac(start, end) - bcwp) / bcwp;
132: }
133:
134: public double eac(EarnedValueValues ev) {
135: return eac(ev, defaultStart, defaultEnd);
136: }
137:
138: public double vac(EarnedValueValues ev, long start, long end) {
139: return ev.bac(start, end) - eac(ev, start, end);
140: }
141:
142: public double vac(EarnedValueValues ev) {
143: return vac(ev, defaultStart, defaultEnd);
144: }
145:
146: public double cpi(EarnedValueValues ev, long start, long end) {
147: double acwp = ev.acwp(start, end);
148: if (acwp == 0.0D) // prevent divide by 0
149: return getDivideByZeroValue();
150: return ev.bcwp(start, end) / acwp;
151: }
152:
153: public double cpi(EarnedValueValues ev) {
154: return cpi(ev, defaultStart, defaultEnd);
155: }
156:
157: public double spi(EarnedValueValues ev, long start, long end) {
158: double bcws = ev.bcws(start, end);
159: if (bcws == 0.0D) // prevent divide by 0
160: return getDivideByZeroValue();
161: return ev.bcwp(start, end) / bcws;
162: }
163:
164: public double spi(EarnedValueValues ev) {
165: return spi(ev, defaultStart, defaultEnd);
166: }
167:
168: public double csi(EarnedValueValues ev, long start, long end) {
169: return spi(ev, start, end) * cpi(ev, start, end);
170: }
171:
172: public double csi(EarnedValueValues ev) {
173: return spi(ev) * cpi(ev);
174: }
175:
176: public double cvPercent(EarnedValueValues ev, long start, long end) {
177: double bcwp = ev.bcwp(start, end);
178: if (bcwp == 0.0D) // prevent divide by 0
179: return getDivideByZeroValue();
180:
181: return (bcwp - ev.acwp(start, end)) / bcwp;
182: }
183:
184: public double cvPercent(EarnedValueValues ev) {
185: return cvPercent(ev, defaultStart, defaultEnd);
186: }
187:
188: public double svPercent(EarnedValueValues ev, long start, long end) {
189: double bcws = ev.bcws(start, end);
190: if (bcws == 0.0D) // prevent divide by 0
191: return getDivideByZeroValue();
192: return (ev.bcwp(start, end) - bcws) / bcws;
193: }
194:
195: public double svPercent(EarnedValueValues ev) {
196: return svPercent(ev, defaultStart, defaultEnd);
197: }
198:
199: public double tcpi(EarnedValueValues ev, long start, long end) {
200: double bac = ev.bac(start, end);
201: double acwp = ev.acwp(start, end);
202: if (bac == acwp) // prevent divide by 0
203: return getDivideByZeroValue();
204:
205: return (bac - ev.bcwp(start, end)) / (bac - acwp);
206: }
207:
208: public double tcpi(EarnedValueValues ev) {
209: return tcpi(ev, defaultStart, defaultEnd);
210: }
211:
212: //non microsoft
213: public double bcwr(EarnedValueValues ev, long start, long end) {
214: return ev.bac(start, end) - ev.bcwp(start, end);
215: }
216:
217: public double bcwr(EarnedValueValues ev) {
218: return bcwr(ev, defaultStart, defaultEnd);
219: }
220:
221: public long getStartOffset(EarnedValueValues ev) {
222: int numBaseline = Snapshottable.BASELINE.intValue(); // TODO use EV baseline?
223: if (!(ev instanceof HasStartAndEnd))
224: return 0L;
225: if (!(ev instanceof BaselineScheduleFields))
226: return 0L;
227: if (!(ev instanceof HasCalendar))
228: return 0L;
229: long baselineStart = ((BaselineScheduleFields) ev)
230: .getBaselineStart(numBaseline);
231: if (baselineStart == 0)
232: return 0L;
233: long start = ((HasStartAndEnd) ev).getStart();
234: return ((HasCalendar) ev).getEffectiveWorkCalendar().compare(
235: start, baselineStart, false);
236: }
237:
238: public long getFinishOffset(EarnedValueValues ev) {
239: int numBaseline = Snapshottable.BASELINE.intValue(); // TODO use EV baseline?
240: if (!(ev instanceof HasStartAndEnd))
241: return 0L;
242: if (!(ev instanceof BaselineScheduleFields))
243: return 0L;
244: if (!(ev instanceof HasCalendar))
245: return 0L;
246: long baselineFinish = ((BaselineScheduleFields) ev)
247: .getBaselineFinish(numBaseline);
248: if (baselineFinish == 0)
249: return 0L;
250: long finish = ((HasStartAndEnd) ev).getEnd();
251: return ((HasCalendar) ev).getEffectiveWorkCalendar().compare(
252: finish, baselineFinish, false);
253:
254: }
255:
256: private static final String NO_BASELINE = "There is no Earned Value data"; //$NON-NLS-1$
257:
258: public ImageLink getScheduleStatusIndicator(double spi) {
259:
260: return ImageLink
261: .trafficLight(
262: spi == 0.0D ? NO_BASELINE
263: : Messages
264: .getString("EarnedValueCalculator.SPI") + "=" + spi, spi, 1.0D, 0.9D); //$NON-NLS-1$ //$NON-NLS-2$
265: }
266:
267: public ImageLink getBudgetStatusIndicator(double cpi) {
268: return ImageLink
269: .trafficLight(
270: cpi == 0.0D ? NO_BASELINE
271: : Messages
272: .getString("EarnedValueCalculator.CPI") + "=" + cpi, cpi, 1.0D, 0.9D); //$NON-NLS-1$ //$NON-NLS-2$
273: }
274:
275: public ImageLink getStatusIndicator(double csi) {
276: return ImageLink
277: .trafficLight(
278: csi == 0.0D ? NO_BASELINE
279: : Messages
280: .getString("EarnedValueCalculator.CSI") + "=" + csi, csi, 1.0D, 0.81D); //$NON-NLS-1$ //$NON-NLS-2$
281: }
282:
283: }
|