From: Hirzel P. <ph...@us...> - 2008-05-15 20:27:34
|
Update of /cvsroot/tcotool/TCO-Tool/src/org/tcotool/tools In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9446/src/org/tcotool/tools Modified Files: Calculator.java Log Message: Feature: calculating Cost#baseOffset (n*12 months) Index: Calculator.java =================================================================== RCS file: /cvsroot/tcotool/TCO-Tool/src/org/tcotool/tools/Calculator.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Calculator.java 14 May 2008 11:09:23 -0000 1.7 --- Calculator.java 15 May 2008 20:27:35 -0000 1.8 *************** *** 230,233 **** --- 230,274 ---- } /** + * Depending on given base-offset the cost impact might happen later. + * @param cost + * @param yearOffset + * @param factor + * @return + * @deprecated + */ + public static double calcTcoCostInYear(Cost cost, int yearOffset, double factor) { + double totalCost = cost.getAmount().doubleValue() * factor; + + if (yearOffset == INDEX_TOTAL) { + // overall cost independent of yearly base-offset + return totalCost; + } else { + double costPerMonth = -1.0; + if (cost instanceof FactCost) { + costPerMonth = totalCost / ((FactCost)cost).getUsageDuration().doubleValue(); + } else { + // PersonalCost are on a yearly usage + //TODO PersonalCost#getUsageDuration() + costPerMonth = totalCost / 12.0; + } + + int currentYearInMonth = yearOffset * 12; // 1st year = 12 [month] + int baseOffset = cost.getBaseOffset() == null ? 0 : cost.getBaseOffset().intValue(); // in [month] + if (baseOffset == 0) { + + } + if (currentYearInMonth <= baseOffset) { + // cost relevant after baseOffset only + return 0.0; + } else { + if (currentYearInMonth > baseOffset) { + + } + //TODO consider Cost#BaseOffset + return totalCost; + } + } + } + /** * Summarize total (PersonalCost + FactCost + DependencyCost) in tree for given object (inclusive). */ *************** *** 430,493 **** private void calcTco(Service service, CostDriver driver, Cost cost, double factor) { double totalCost = cost.getAmount().doubleValue() * factor; ! if (cost instanceof PersonalCost) { ! // [0] total PersonalCost for a year cummulateCodes(service, driver, cost, PERSONAL_TCO, INDEX_TOTAL, totalCost); ! // [1..n years] personal effort is added to each following TCO-Year ! if ((cost.getRepeatable() != null) && cost.getRepeatable().booleanValue()) { ! calcTcoRepeatable(service, driver, cost, PERSONAL_TCO, totalCost); ! } else { ! // at least charge personal Cost ONCE ! //TODO find the year of the baseOffset ! cummulateCodes(service, driver, cost, PERSONAL_TCO, INDEX_TOTAL + 1, totalCost); ! } } else { FactCost fCost = (FactCost)cost; ! if ((fCost.getUsageDuration() != null) && (fCost.getUsageDuration().longValue() > 0)) { ! // [0] total FactCost independent of usage cummulateCodes(service, driver, cost, FACT_TCO, INDEX_TOTAL, totalCost); ! // [1..n years] FactCost's divided by usage ! double costPerMonth = totalCost / fCost.getUsageDuration().doubleValue(); ! if ((cost.getRepeatable() != null) && cost.getRepeatable().booleanValue()) { // usageDuration is in maxUsage range anyway if (fCost.getUsageDuration().longValue() < 12) { // the given cost-amount counts for whole year ! // calcTcoRepeatable(costTypeValues, cost.getAmount().doubleValue()); ! calcTcoRepeatable(service, driver, cost, FACT_TCO, totalCost); } else { ! calcTcoRepeatable(service, driver, cost, FACT_TCO, costPerMonth * 12.0); } } else { // once in maxUsage for whole UsageDuration - //TODO find the year of the baseOffset long completeYears = fCost.getUsageDuration().longValue() / 12; ! int year = 0; for (; year<completeYears; year++) { // usage over full year ! cummulateCodes(service, driver, cost, FACT_TCO, year + INDEX_TOTAL + 1, costPerMonth * 12.0); } long partialMonthInYear = fCost.getUsageDuration().longValue() % 12; if (partialMonthInYear > 0) { // last Usage year adds only fraction part ! cummulateCodes(service, driver, cost, FACT_TCO, year + INDEX_TOTAL + 1, costPerMonth * (double)partialMonthInYear); year++; } } } } } - private static double getCostInYear(Cost cost, int yearOffset) { - return 0.0; - } /** ! * Repeatable Cost's must be reconsidered after UsageDuration. */ ! private void calcTcoRepeatable(Service service, CostDriver driver, Cost cost, final String keyPrefix, double costPerYear) { ! //??? Map serviceMap = getServiceMap(costs, service); // [1..n years] personal effort is added to each following TCO-Year long completeYears = getMaxDurationMonths() / 12; ! int year = 0; for (; year<completeYears; year++) { cummulateCodes(service, driver, cost, keyPrefix, year + INDEX_TOTAL + 1, costPerYear); --- 471,585 ---- private void calcTco(Service service, CostDriver driver, Cost cost, double factor) { double totalCost = cost.getAmount().doubleValue() * factor; + boolean repeatable = (cost.getRepeatable() != null) && cost.getRepeatable().booleanValue(); + int baseOffset = (cost.getBaseOffset() == null ? 0 : cost.getBaseOffset().intValue()); + int baseYear = baseOffset / 12; + int year = INDEX_TOTAL + 1 + baseYear; ! if (cost instanceof PersonalCost) { // usage=12 months! ! // 1) [0] total PersonalCost for a year (baseOffset irrelevant) cummulateCodes(service, driver, cost, PERSONAL_TCO, INDEX_TOTAL, totalCost); ! // [1..n years] personal effort is the SAME for each following TCO-Year (usage=12 months!) ! /*if (repeatable) { ! calcTcoRepeatable(service, driver, cost, PERSONAL_TCO, totalCost, baseOffset); ! } else {*/ ! // 2) calc [1+baseOffset] year ! if (baseOffset % 12.0 == 0) { ! cummulateCodes(service, driver, cost, PERSONAL_TCO, year++, totalCost); ! } else { ! // treat first year partially ONLY! ! double part = totalCost / 12.0 * (12.0 - (double)(baseOffset - baseYear * 12.0)); ! cummulateCodes(service, driver, cost, PERSONAL_TCO, year++, part); ! if (!repeatable) { ! // 3.1) book rest part of the costs in the following year ! cummulateCodes(service, driver, cost, PERSONAL_TCO, year, totalCost - part); ! } ! } ! // 3.2) [2+baseOffset..n] years personal cost is the SAME for each following TCO-Year ! if (repeatable) { ! long completeYears = getMaxDurationMonths() / 12; ! ! for (; year<completeYears+1; year++) { ! cummulateCodes(service, driver, cost, PERSONAL_TCO, year, totalCost); ! } ! // if the last year is not even in maxUsage ! long partialMonthInYear = getMaxDurationMonths() % 12; ! if (partialMonthInYear > 0) { ! // ignore partial costs in case of (baseOffset%12!=0) because repeatable anyway ! cummulateCodes(service, driver, cost, PERSONAL_TCO, year, totalCost / 12.0 * partialMonthInYear); ! } ! } ! //} } else { FactCost fCost = (FactCost)cost; ! if ((fCost.getUsageDuration() != null) && (fCost.getUsageDuration().longValue() > 0)) { ! // 1) [0] total FactCost independent of usage (baseOffset irrelevant) cummulateCodes(service, driver, cost, FACT_TCO, INDEX_TOTAL, totalCost); ! // 2) [1+baseOffset..n] year ! double costPerMonth = totalCost / fCost.getUsageDuration().doubleValue(); ! for (int month=0; month<getMaxDurationMonths(); month++) { ! if ((month<fCost.getUsageDuration().intValue()) || repeatable) { ! if ((month > 0) && (month % 12 == 0)) { ! // next year ! year++; ! } ! cummulateCodes(service, driver, cost, FACT_TCO, year, costPerMonth); ! } else { ! break; ! } ! } ! /* ! // [1..n years] FactCost's divided by usage ! if (repeatable) { // usageDuration is in maxUsage range anyway if (fCost.getUsageDuration().longValue() < 12) { // the given cost-amount counts for whole year ! calcTcoRepeatable(service, driver, cost, FACT_TCO, totalCost, baseOffset); } else { ! calcTcoRepeatable(service, driver, cost, FACT_TCO, costPerMonth * 12.0, baseOffset); } } else { // once in maxUsage for whole UsageDuration long completeYears = fCost.getUsageDuration().longValue() / 12; ! double correctionCosts = 0.0; ! if (baseYear > 0) { ! // if baseOffset points to middle of year, only calculate costs partially in first relevant year ! double months = 12.0 - (double)(baseOffset % 12); ! correctionCosts = correctionCosts + costPerMonth * months; ! cummulateCodes(service, driver, cost, FACT_TCO, year, costPerMonth * months); ! year++; ! } for (; year<completeYears; year++) { // usage over full year ! correctionCosts = correctionCosts + costPerMonth * 12.0; ! cummulateCodes(service, driver, cost, FACT_TCO, year, costPerMonth * 12.0); } long partialMonthInYear = fCost.getUsageDuration().longValue() % 12; if (partialMonthInYear > 0) { // last Usage year adds only fraction part ! correctionCosts = correctionCosts + costPerMonth * (double)partialMonthInYear; ! cummulateCodes(service, driver, cost, FACT_TCO, year, costPerMonth * (double)partialMonthInYear); year++; } + if (correctionCosts > totalCost) { + // NASTY: because of baseOffset to many costs were booked in last year + cummulateCodes(service, driver, cost, FACT_TCO, year - 1, totalCost - correctionCosts); + } } + */ } } } /** ! * Repeatable Cost's must be reconsidered after UsageDuration in years 1..n. ! * @deprecated */ ! private void calcTcoRepeatable(Service service, CostDriver driver, Cost cost, final String keyPrefix, double costPerYear, int baseOffset) { ! int baseYear = baseOffset / 12; ! // [1..n years] personal effort is added to each following TCO-Year long completeYears = getMaxDurationMonths() / 12; ! int year = 0 + baseYear; for (; year<completeYears; year++) { cummulateCodes(service, driver, cost, keyPrefix, year + INDEX_TOTAL + 1, costPerYear); *************** *** 650,660 **** */ private void storeIntoCodeList(Map serviceMap, final String kind, Object code, int year, double amount) { ! // 1) keep the costs for service, year and code ! List codeList = getCodeList(serviceMap, createCodeKey(kind, code)); ! if (codeList.size() > year) { ! codeList.set(year, new Double(((Double)codeList.get(year)). doubleValue() + amount)); ! } else { ! codeList.add(new Double(amount)); } } /** --- 742,752 ---- */ private void storeIntoCodeList(Map serviceMap, final String kind, Object code, int year, double amount) { ! // keep the costs for service, year and code ! List codeList = getCodeList(serviceMap, createCodeKey(kind, code)); ! for (int i=codeList.size(); i<=year; i++) { ! // (first entry in this year) || (Cost#baseOffset > 1 year) ! codeList.add(new Double(0.0)); } + codeList.set(year, new Double(((Double)codeList.get(year)). doubleValue() + amount)); } /** *************** *** 820,824 **** // repeat the costs until maxDuration while (year < getDurationYears()) { ! //TODO Check: probably degressive depreciation costs from duration before are not calculated further on, which would go infinitely down to 0 year = calcDepreciation(service, driver, fCost, capital, year); } --- 912,916 ---- // repeat the costs until maxDuration while (year < getDurationYears()) { ! //TODO Check: probably degressive depreciation costs from duration before are not calculated further on, which would go infinitely down to 0 year = calcDepreciation(service, driver, fCost, capital, year); } |