private bool RunLCA1Calculation(LCA1CalculatorHelper.CALCULATOR_TYPES calculatorType, ref XElement currentElement, ref XElement currentCalculationsElement) { bool bHasCalculations = false; switch (calculatorType) { case LCA1CalculatorHelper.CALCULATOR_TYPES.buildcost1: //serialize, run calcs, and deserialize LCC1Calculator lcc1 = new LCC1Calculator(); bHasCalculations = lcc1.SetLCC1Calculations(calculatorType, this.GCCalculatorParams, ref currentCalculationsElement, ref currentElement); break; case LCA1CalculatorHelper.CALCULATOR_TYPES.buildbenefit1: //serialize, run calcs, and deserialize LCB1Calculator lcb1 = new LCB1Calculator(); bHasCalculations = lcb1.SetLCB1Calculations(calculatorType, this.GCCalculatorParams, ref currentCalculationsElement, ref currentElement); break; default: //should be running an analysis break; } return(bHasCalculations); }
private void AddSubBenefits(LCA1Total1 totStock, LCB1Calculator lcbOutput) { foreach (SubPrice1 subprice in lcbOutput.SubPrice1s) { AddSubBenefit(totStock, subprice, lcbOutput); } }
private void UpdateBaseOutputUnitPrices(LCB1Calculator lifeCycleOutput) { //they have to enter units, units should generally be "each" lifeCycleOutput.LCBOutput.Price = lifeCycleOutput.RTotalBenefit; //operating and capital budgets use TotalAMR lifeCycleOutput.LCBOutput.TotalAMR = lifeCycleOutput.EAATotalBenefit; }
private static void SetOutputBasePrice(LCB1Calculator lifeCycleOutput, string priceType, double benefit) { if (priceType == SubPrices.PRICE_TYPES.rev.ToString()) { lifeCycleOutput.RTotalBenefit += benefit; } }
private bool SetAnalyses(LCA1Stock lca1Stock) { bool bHasAnalysis = false; bool bHasTotals = false; bool adjustTotals = true; //only the totStocks are used to store numerical results //calcprops and analyzerprops stored in lca1stock lca1Stock.Total1 = new LCA1Total1(); //need one property set lca1Stock.Total1.SubApplicationType = lca1Stock.CalcParameters.SubApplicationType.ToString(); //these are the lcc and lcb calculations //the initial aggregation must have serialized them correctly as lcc or lcb calcors //costs foreach (SubPrice1 ind in lca1Stock.SubP1Stock.SubPrice1s) { if (ind.CalculatorType == LCA1CalculatorHelper.CALCULATOR_TYPES.buildcost1.ToString()) { LCC1Calculator lccInput = (LCC1Calculator)ind; //ind.SubPrice1s holds the subprices collection (which must also be totaled) bHasTotals = AddCostToTotalStock(lca1Stock.Total1, lca1Stock.Multiplier, lccInput, adjustTotals); //stock needs some calculator properties (date) BILCA1StockAnalyzer.CopyBaseElementProperties(lccInput.LCCInput, lca1Stock); lca1Stock.Date = lccInput.LCCInput.Date; if (bHasTotals) { bHasAnalysis = true; } } } //benefits foreach (SubPrice1 ind in lca1Stock.SubP2Stock.SubPrice1s) { if (ind.CalculatorType == LCA1CalculatorHelper.CALCULATOR_TYPES.buildbenefit1.ToString()) { LCB1Calculator lcbOutput = (LCB1Calculator)ind; //ind.SubPrice1s holds the subprices collection (which must also be totaled) bHasTotals = AddBenefitToTotalStock(lca1Stock.Total1, lca1Stock.Multiplier, lcbOutput, adjustTotals); //stock needs some calculator properties (date) BILCA1StockAnalyzer.CopyBaseElementProperties(lcbOutput.LCBOutput, lca1Stock); //lca1Stock.Date = lcbOutput.LCBOutput.Date; if (bHasTotals) { bHasAnalysis = true; } } } return(bHasAnalysis); }
private static double GetMultipliedTotal(LCB1Calculator lcbOutput, double total, string priceType, double multiplier) { double dbMultipliedTotal = total; if (priceType == SubPrices.PRICE_TYPES.rev.ToString()) { dbMultipliedTotal = total * lcbOutput.LCBOutput.Amount * multiplier; } else { //base table uses all three dbMultipliedTotal = total * lcbOutput.LCBOutput.Amount * multiplier; } return(dbMultipliedTotal); }
public virtual void CopyLCB1Properties( LCB1Calculator calculator) { this.CopyCalculatorProperties(calculator); this.CopySharedObjectProperties(calculator); this.CopySubPrice1sProperties(calculator); this.ServiceLifeYears = calculator.ServiceLifeYears; this.YearsFromBaseDate = calculator.YearsFromBaseDate; this.PlanningConstructionYears = calculator.PlanningConstructionYears; this.PerUnitAmount = calculator.PerUnitAmount; this.PerUnitUnit = calculator.PerUnitUnit; this.LCBOutput = new Output(calculator.LCBOutput); this.RTotalBenefit = calculator.RTotalBenefit; this.LCBTotalBenefit = calculator.LCBTotalBenefit; this.EAATotalBenefit = calculator.EAATotalBenefit; this.UnitTotalBenefit = calculator.UnitTotalBenefit; }
private void AddSubBenefit(LCA1Total1 totStock, SubPrice1 subprice, LCB1Calculator lcbOutput) { //make sure that each subprice has a corresponding stock2 //stock2 distinguishes benefits from costs in budget elements totStock.SubP2Stock.AddSubPrice2ToStocks(subprice); //add cumulative totals (rentals, commodities, sales) foreach (SubPrice2Stock stock in totStock.SubP2Stock.SubPrice2Stocks) { if ((stock.TotalSubP2Label == subprice.SubPLabel && subprice.SubPLabel != string.Empty)) { stock.TotalSubP2Total += subprice.SubPTotal; stock.TotalSubP2Price += subprice.SubPPrice; stock.TotalSubP2Amount += subprice.SubPAmount; stock.TotalSubP2TotalPerUnit = stock.TotalSubP2Total / lcbOutput.PerUnitAmount; } } }
public void SetDescendantLCA1StockOutputAttributes(string attNameExt, CalculatorParameters calcParams, ref XElement calculator, XElement currentElement) { //the lcatotal1 analyzer adds its totals to the base lcb1calculator linked view //less duplication and easier to extend if (calculator != null) { if (this.AnalyzerType == LCA1AnalyzerHelper.ANALYZER_TYPES.lcatotal1.ToString() || this.AnalyzerType == LCA1AnalyzerHelper.ANALYZER_TYPES.lcastat1.ToString() || this.AnalyzerType == LCA1AnalyzerHelper.ANALYZER_TYPES.lcachangeyr.ToString() || this.AnalyzerType == LCA1AnalyzerHelper.ANALYZER_TYPES.lcachangeid.ToString() || this.AnalyzerType == LCA1AnalyzerHelper.ANALYZER_TYPES.lcachangealt.ToString() || this.AnalyzerType == LCA1AnalyzerHelper.ANALYZER_TYPES.lcaprogress1.ToString()) { string sAttNameExt = string.Empty; this.SetAndRemoveCalculatorAttributes(sAttNameExt, ref calculator); bool bHasCalcs = false; if (this.SubP2Stock.SubPrice1s != null) { if (this.SubP2Stock.SubPrice1s.Count > 0) { LCB1Calculator lcb = (LCB1Calculator)this.SubP2Stock.SubPrice1s.FirstOrDefault(); if (lcb != null) { //set locals lcb.LCBOutput.Local.SetLocalAttributesForCalculator(calcParams, ref calculator); lcb.SetLCB1Attributes(string.Empty, ref calculator); bHasCalcs = true; } } } //don't need both subps and subpstock if (!bHasCalcs) { //set the analysis this.SetTotalLCA1StocksAttributes(attNameExt, ref calculator); } } } }
public static void ChangeOutputByOutputMultipliers(LCB1Calculator lcbOutput, double multiplier) { //lcbOutput.Amount is included to stay consistent with how input multipliers are used lcbOutput.RTotalBenefit = lcbOutput.RTotalBenefit * lcbOutput.LCBOutput.Amount * multiplier; //multiplicative, so ok to multiply; but final number is summation lcbOutput.LCBTotalBenefit = lcbOutput.LCBTotalBenefit * lcbOutput.LCBOutput.Amount * multiplier; lcbOutput.EAATotalBenefit = lcbOutput.EAATotalBenefit * lcbOutput.LCBOutput.Amount * multiplier; //unit totals are derived lcbOutput.UnitTotalBenefit = lcbOutput.LCBTotalBenefit / lcbOutput.PerUnitAmount; //subbenefits foreach (SubPrice1 subprice in lcbOutput.SubPrice1s) { subprice.SubPTotal = GetMultipliedTotal(lcbOutput, subprice.SubPTotal, subprice.SubPType, multiplier); subprice.SubPTotalPerUnit = subprice.SubPTotal / lcbOutput.PerUnitAmount; //display the multiplier-adjusted quantity of each subprice1 //this number can be used directly in statistical aggregations subprice.SubPAmount = GetMultipliedTotal(lcbOutput, subprice.SubPAmount, subprice.SubPType, multiplier); } }
public bool AddBenefitToTotalStock(LCA1Total1 totStock, double multiplier, LCB1Calculator lcbOutput, bool adjustTotals) { bool bHasCalculations = false; //inheriting classes usually run this class, but adjust their own totals if (adjustTotals) { //multipliers (output.times, out.compositionamount) //i.e. buildCostOutput.cost = output.amount * multiplier ChangeOutputByOutputMultipliers(lcbOutput, multiplier); } //multiplier adjusted benefits totStock.TotalRBenefit += lcbOutput.RTotalBenefit; totStock.TotalLCBBenefit += lcbOutput.LCBTotalBenefit; totStock.TotalREAABenefit += lcbOutput.EAATotalBenefit; //unit benefit is derived from totstock totStock.TotalRUnitBenefit = totStock.TotalLCBBenefit / lcbOutput.PerUnitAmount; //subbenefits AddSubBenefits(totStock, lcbOutput); bHasCalculations = true; return(bHasCalculations); }
//need to add the correct subbenefit price type with the correct parent pricetotal private static void SetBenefitTotals(LCB1Calculator lifeCycleOutput) { //init at zero (these get summed in npv and lcc comp and investment calcors) lifeCycleOutput.LCBOutput.Price = 0; lifeCycleOutput.RTotalBenefit = 0; //ok to use the default order of the subcosts foreach (SubPrice1 subprice in lifeCycleOutput.SubPrice1s) { SetOutputBasePrice(lifeCycleOutput, subprice.SubPType, subprice.SubPTotal); } //set lcc total lifeCycleOutput.LCBTotalBenefit = lifeCycleOutput.RTotalBenefit; //set eaa total lifeCycleOutput.EAATotalBenefit = GeneralRules.CalculateEquivalentAnnualAnnuity(lifeCycleOutput.LCBTotalBenefit, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.LCBOutput.Local.RealRate, lifeCycleOutput.LCBOutput.Local.NominalRate); //set unit benefit if (lifeCycleOutput.PerUnitAmount == 0) { lifeCycleOutput.PerUnitAmount = 1; } lifeCycleOutput.UnitTotalBenefit = lifeCycleOutput.LCBTotalBenefit / lifeCycleOutput.PerUnitAmount; }
public bool RunBenefitCalculations(LCB1Calculator lifeCycleOutput) { bool bHasCalcs = false; GeneralRules.GROWTH_SERIES_TYPES eGrowthType; //five subbenefits to calculate double dbSubPrice1Total = 0; double dbSubPrice2Total = 0; double dbSubPrice3Total = 0; double dbSubPrice4Total = 0; double dbSubPrice5Total = 0; double dbSubPrice6Total = 0; double dbSubPrice7Total = 0; double dbSubPrice8Total = 0; double dbSubPrice9Total = 0; double dbSubPrice10Total = 0; //only the real rate and constant dollars are used //but keep these for possible future use double dbNominalRate = 0; double dbRealRate = 0; double dbInflationRate = 0; //ok to use the default order of the subcosts int i = 1; foreach (SubPrice1 subprice in lifeCycleOutput.SubPrice1s) { if (i == 1) { dbSubPrice1Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 2) { dbSubPrice2Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 3) { dbSubPrice3Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 4) { dbSubPrice4Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 5) { dbSubPrice5Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 6) { dbSubPrice6Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 7) { dbSubPrice7Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 8) { dbSubPrice8Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 9) { dbSubPrice9Total = subprice.SubPAmount * subprice.SubPPrice; } else if (i == 10) { dbSubPrice10Total = subprice.SubPAmount * subprice.SubPPrice; } i++; } //init calculation parameters dbRealRate = lifeCycleOutput.LCBOutput.Local.RealRate; dbNominalRate = lifeCycleOutput.LCBOutput.Local.NominalRate; dbInflationRate = 0; GeneralRules.MissingRate(ref dbRealRate, ref dbNominalRate, ref dbInflationRate); if (dbRealRate > 0.999) { dbRealRate = dbRealRate / 100; } if (dbNominalRate > 0.999) { dbNominalRate = dbNominalRate / 100; } if (dbInflationRate > 0.999) { dbInflationRate = dbInflationRate / 100; } lifeCycleOutput.LCBOutput.Local.RealRate = dbRealRate; lifeCycleOutput.LCBOutput.Local.NominalRate = dbNominalRate; lifeCycleOutput.LCBOutput.Local.InflationRate = dbInflationRate; //ok to use the default order of the subcosts i = 1; foreach (SubPrice1 subprice in lifeCycleOutput.SubPrice1s) { eGrowthType = GeneralRules.GetGrowthType(subprice.SubPEscType); if (i == 1) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice1Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 2) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice2Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 3) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice3Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 4) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice4Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 5) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice5Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 6) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice6Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 7) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice7Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 8) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice8Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 9) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice9Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } else if (i == 10) { subprice.SubPTotal = GeneralRules.GetGradientRealDiscountValue(dbSubPrice10Total, dbRealRate, lifeCycleOutput.ServiceLifeYears, lifeCycleOutput.YearsFromBaseDate, lifeCycleOutput.PlanningConstructionYears, eGrowthType, subprice.SubPEscRate, subprice.SubPFactor, subprice.SubPYears, subprice.SubPYearTimes, subprice.SubPSalvValue); } subprice.SubPTotalPerUnit = subprice.SubPTotal / lifeCycleOutput.PerUnitAmount; i++; } //set lifeCyleOutput's total properties to these values SetBenefitTotals(lifeCycleOutput); //update the base output's prices (unit benefits, not full benefits) UpdateBaseOutputUnitPrices(lifeCycleOutput); bHasCalcs = true; return(bHasCalcs); }
//copy constructor public LCB1Calculator(LCB1Calculator lca1Calc) : base(lca1Calc) { CopyLCB1Properties(lca1Calc); }