public static bool CopyStockCalculator(Calculator1 calc, NPV1Stock newStock) { bool bHasCopy = false; if (calc != null) { if (calc.GetType().Equals(newStock.GetType())) { NPV1Stock oldStock = (NPV1Stock)calc; if (oldStock != null) { //only one npv1stock is initialized in object model bHasCopy = CopyStockCalculator(oldStock, newStock); } } } return(bHasCopy); }
public static bool CopyandInitStockCalculator(Calculator1 calc, NPV1Stock newStock) { bool bHasCopy = false; if (calc != null) { if (calc.GetType().Equals(newStock.GetType())) { NPV1Stock oldStock = (NPV1Stock)calc; if (oldStock != null) { //copy initial totals newStock.InitTotalNPV1StocksProperties(oldStock); //but keep calc props newStock.CopyCalculatorProperties(oldStock); bHasCopy = true; } } } return(bHasCopy); }
private bool SetAnalyses(NPV1Stock npv1Stock, List <Calculator1> calcs) { bool bHasAnalysis = false; bool bHasTotals = false; //only the totStocks are used in results //calcs holds a collection of npv1stocks for base element foreach (Calculator1 calc in calcs) { if (calc.GetType().Equals(npv1Stock.GetType())) { NPV1Stock stock = (NPV1Stock)calc; if (stock != null) { //make sure it already has a total1 (set by SetBaseIO, or during InitTotal1) if (stock.Total1 != null) { npv1Stock.Total1.CalcParameters = new CalculatorParameters(stock.Total1.CalcParameters); //npv1Stock.Total1.CalcParameters = npv1Stock.CalcParameters; //these totals were multiplied in base npv calcs //don't use calc.Multiplier again double iMultiplier = 1; //these need to be multiplied because arbitrary ocstocks are being aggregated //into time periods; the timeperiod totals can't be used AddSubTotalToTotalStock(npv1Stock.Total1, iMultiplier, stock.Total1); bHasTotals = true; if (bHasTotals) { bHasAnalysis = true; } } } } } return(bHasAnalysis); }
private bool SetBaseAnalyses(NPV1Stock npv1Stock, List <Calculator1> calcs) { bool bHasAnalysis = false; bool bHasTotals = false; //set the calc totals in each observation int iCostN2 = 0; int iBenefitN2 = 0; List <NPV1Stat1> stats2 = new List <NPV1Stat1>(); double dbMultiplier = 1; //this is the IO pattern: test if the Alt2 Pattern is still needed //make sure this does not need IEnumerable<System.Linq.IGrouping<int, Calculator1>> //calcsByAlt2 = calcs.GroupBy(c => c.Alternative2); //inputs and outputs use calc for each observation (not the Grouping.Alternative) foreach (Calculator1 calc in calcs) { if (calc.GetType().Equals(npv1Stock.GetType())) { NPV1Stock stock = (NPV1Stock)calc; if (stock != null) { if (stock.Stat1 != null) { //set the calc totals in each observation NPV1Stock observation2Stock = new NPV1Stock(stock.Stat1.CalcParameters, stock.Stat1.CalcParameters.AnalyzerParms.AnalyzerType); observation2Stock.Stat1 = new NPV1Stat1(); observation2Stock.Stat1.CalcParameters = new CalculatorParameters(stock.Stat1.CalcParameters); //since Stat1 is new, this method will not accrue totals //but it will set N //calc.Multiplier not used because base calcs used it bHasTotals = AddSubTotalToTotalStock(observation2Stock.Stat1, dbMultiplier, stock.Stat1); if (bHasTotals) { //add to the stats collection stats2.Add(observation2Stock.Stat1); bool bIsCostNode = CalculatorHelpers.IsCostNode(stock.CalcParameters.CurrentElementNodeName); bool bIsBenefitNode = CalculatorHelpers.IsBenefitNode(stock.CalcParameters.CurrentElementNodeName); if (bIsCostNode) { iCostN2++; } else if (bIsBenefitNode) { iBenefitN2++; } else { iCostN2++; iBenefitN2++; } } } } } } if (iCostN2 > 0 || iBenefitN2 > 0) { bHasAnalysis = true; bHasTotals = SetStatsAnalysis(stats2, npv1Stock, iCostN2, iBenefitN2); } return(bHasAnalysis); }