//current analyzer does not need this and isn't used private bool SetBaseIOAnalyses(NPV1Stock npv1Stock) { bool bHasAnalysis = false; //initial calculators are added to stock.Total1, stock.Stat1 ... if (npv1Stock.Total1 != null) { //will double count first member, so skip sending first member of collections here npv1Stock.Total1.TotalAMOC += npv1Stock.Total1.TotalOC; npv1Stock.Total1.TotalAMAOH += npv1Stock.Total1.TotalAOH; npv1Stock.Total1.TotalAMCAP += npv1Stock.Total1.TotalCAP; //this is not plus equal npv1Stock.Total1.TotalAMTOTAL += npv1Stock.Total1.TotalAMOC + npv1Stock.Total1.TotalAMAOH + npv1Stock.Total1.TotalAMCAP; //when machinery, lca, or meaningful unit amounts are on hand (no input.Times in base Inputs) npv1Stock.Total1.TotalOCAmount += npv1Stock.Total1.TotalOCAmount; npv1Stock.Total1.TotalOCPrice += npv1Stock.Total1.TotalOCPrice; //benefits npv1Stock.Total1.TotalAMR += npv1Stock.Total1.TotalR; //cost effectiveness analysis (no output.compositionamount in base Outputs) npv1Stock.Total1.TotalRAmount += npv1Stock.Total1.TotalRAmount; npv1Stock.Total1.TotalRPrice += npv1Stock.Total1.TotalRPrice; npv1Stock.Total1.TotalRCompositionAmount += npv1Stock.Total1.TotalRCompositionAmount; } bHasAnalysis = true; return(bHasAnalysis); }
private static void SetNETStatistics(NPV1Stock npv1Stock, List <NPV1Stat1> stats) { //reorder for median IEnumerable <NPV1Stat1> stat2s = stats.OrderByDescending(s => s.TotalAMNET); double j = 1; //variance double dbMemberSquaredTotalQ1 = 0; double dbMemberSquaredQ1 = 0; dbMemberSquaredTotalQ1 = 0; double db_MEDQ1 = stat2s.Count() / 2; double dbRemainderQ1 = Math.IEEERemainder(stat2s.Count(), 2); double dbLastTotalQ1 = 0; foreach (NPV1Stat1 stat in stat2s) { dbMemberSquaredQ1 = Math.Pow((stat.TotalAMNET - npv1Stock.Stat1.TotalAMNET_MEAN), 2); dbMemberSquaredTotalQ1 += dbMemberSquaredQ1; if (j > db_MEDQ1 && j != 0) { if (dbRemainderQ1 == 0) { //divide the middle two numbers npv1Stock.Stat1.TotalAMNET_MED = (stat.TotalAMNET + dbLastTotalQ1) / 2; } else { //use the middle number npv1Stock.Stat1.TotalAMNET_MED = stat.TotalAMNET; } j = 0; } if (j != 0) { j = j + 1; } dbLastTotalQ1 = stat.TotalAMNET; } //don't divide by zero if (npv1Stock.Stat1.TotalCostN > 1) { //sample variance double dbCount = (1 / (npv1Stock.Stat1.TotalCostN - 1)); npv1Stock.Stat1.TotalAMNET_VAR2 = dbMemberSquaredTotalQ1 * dbCount; if (npv1Stock.Stat1.TotalAMNET_MEAN != 0) { //sample standard deviation npv1Stock.Stat1.TotalAMNET_SD = Math.Sqrt(npv1Stock.Stat1.TotalAMNET_VAR2); } } else { npv1Stock.Stat1.TotalAMNET_VAR2 = 0; npv1Stock.Stat1.TotalAMNET_SD = 0; } }
public virtual void InitTotalNPV1StocksProperties(NPV1Stock calculator) { //this is called during the initial calculator collections //it adds those initial calcs to correct agg stock //base calculator holds totals if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvstat1.ToString()) { this.Stat1 = new NPV1Stat1(); //each analysis stores data according to analyzertype and nowehere else if (calculator.Stat1 != null) { this.Stat1.CalcParameters = new CalculatorParameters(calculator.Stat1.CalcParameters); this.Stat1.CopyCalculatorProperties(calculator.Stat1); this.Stat1.CopyTotalCostsProperties(calculator.Stat1); this.Stat1.CopyTotalBenefitsProperties(calculator.Stat1); } } else if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangeyr.ToString() || this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangeid.ToString() || this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangealt.ToString()) { this.Change1 = new NPV1Change1(); if (calculator.Change1 != null) { this.Change1.CalcParameters = new CalculatorParameters(calculator.Change1.CalcParameters); this.Change1.CopyCalculatorProperties(calculator.Change1); this.Change1.CopyTotalCostsProperties(calculator.Change1); this.Change1.CopyTotalBenefitsProperties(calculator.Change1); } } else if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvprogress1.ToString()) { this.Progress1 = new NPV1Progress1(); if (calculator.Progress1 != null) { this.Progress1.CalcParameters = new CalculatorParameters(calculator.Progress1.CalcParameters); this.Progress1.CopyCalculatorProperties(calculator.Progress1); this.Progress1.CopyTotalCostsProperties(calculator.Progress1); this.Progress1.CopyTotalBenefitsProperties(calculator.Progress1); } } else { this.Total1 = new NPV1Total1(); if (calculator.Total1 != null) { this.Total1.CalcParameters = new CalculatorParameters(calculator.Total1.CalcParameters); this.Total1.CopyCalculatorProperties(calculator.Total1); this.Total1.CopyTotalCostsProperties(calculator.Total1); this.Total1.CopyTotalBenefitsProperties(calculator.Total1); } } }
//run the analyses for everything else //keep this for future use in case more data needs to be taken //out of input and output calcs public bool RunAnalyses(NPV1Stock npv1Stock, List <Calculator1> calcs) { bool bHasAnalyses = false; //don't use npv1Stock totals, use calcs SetAnalyses(npv1Stock); //consistent pattern followed by LCA, NPV, M&E bHasAnalyses = SetAnalyses(npv1Stock, calcs); return(bHasAnalyses); }
//run the analyses for inputs an outputs public bool RunAnalyses(NPV1Stock npv1Stock) { //only used for base input and output analysis //the base inputs and outputs were copied to calculators //do not use for op.inputs, outcome.outputs bool bHasAnalyses = false; //set npv1Stock.Total1 //bHasAnalyses = SetBaseIOAnalyses(npv1Stock); return(bHasAnalyses); }
private bool SetStatsAnalysis(List <NPV1Stat1> stats2, NPV1Stock statStock, int costN, int benN) { bool bHasTotals = false; //set the total observations total foreach (var stat in stats2) { //add each stat to statStock.Stat1 bHasTotals = AddSubTotalToTotalStock(statStock.Stat1, 1, stat); } if (costN > 0) { statStock.Stat1.TotalCostN = costN; //set the cost means statStock.Stat1.TotalAMOC_MEAN = statStock.Stat1.TotalAMOC / costN; statStock.Stat1.TotalAMAOH_MEAN = statStock.Stat1.TotalAMAOH / costN; statStock.Stat1.TotalAMCAP_MEAN = statStock.Stat1.TotalAMCAP / costN; statStock.Stat1.TotalAMINCENT_MEAN = statStock.Stat1.TotalAMINCENT / costN; statStock.Stat1.TotalAMTOTAL_MEAN = statStock.Stat1.TotalAMTOTAL / costN; statStock.Stat1.TotalAMNET_MEAN = statStock.Stat1.TotalAMNET / costN; //set the median, variance, and standard deviation costs SetOCStatistics(statStock, stats2); SetAOHStatistics(statStock, stats2); SetCAPStatistics(statStock, stats2); SetINCENTStatistics(statStock, stats2); //total costs SetTOTALStatistics(statStock, stats2); //net returns (benefits have to be set first) SetNETStatistics(statStock, stats2); } if (benN > 0) { statStock.Stat1.TotalBenefitN = benN; //set the benefit means statStock.Stat1.TotalAMR_MEAN = statStock.Stat1.TotalAMR / benN; statStock.Stat1.TotalAMRINCENT_MEAN = statStock.Stat1.TotalAMRINCENT / benN; statStock.Stat1.TotalAMINCENT_NET_MEAN = statStock.Stat1.TotalAMINCENT_NET / benN; //r ps and qs statStock.Stat1.TotalRAmount_MEAN = statStock.Stat1.TotalRAmount / benN; statStock.Stat1.TotalRCompositionAmount_MEAN = statStock.Stat1.TotalRCompositionAmount / benN; //don't adjust prices by multiplier statStock.Stat1.TotalRPrice_MEAN = statStock.Stat1.TotalRPrice / benN; //benefits SetRStatistics(statStock, stats2); SetRINCENTStatistics(statStock, stats2); SetINCENT_NETStatistics(statStock, stats2); //ps and qs SetRAmountStatistics(statStock, stats2); SetRPriceStatistics(statStock, stats2); SetRCompositionAmountStatistics(statStock, stats2); } return(bHasTotals); }
public static bool CopyStockCalculator(NPV1Stock oldStock, NPV1Stock newStock) { bool bHasCopy = false; if (oldStock != null && newStock != null) { //copying stocks should all take place uniformly here newStock.CopyTotalNPV1StocksProperties(oldStock); //newStock.AnalyzerType = this.GCCalculatorParams.AnalyzerParms.AnalyzerType; bHasCopy = true; } return(bHasCopy); }
public static void CopyStockCalculator(List <Calculator1> calcs, NPV1Stock newStock) { if (calcs != null) { foreach (Calculator1 calc in calcs) { bool bHasCopy = CopyStockCalculator(calc, newStock); if (bHasCopy) { break; } } } }
//calcs holds the collections needing statistical analysis public bool RunAnalyses(NPV1Stock npv1Stock, List <Calculator1> calcs) { bool bHasAnalyses = false; //add totals to npv1stock.Stat1 if (npv1Stock.Stat1 == null) { npv1Stock.Stat1 = new NPV1Stat1(); } //don't use npv1Stock totals, use calcs SetAnalyses(npv1Stock); bHasAnalyses = SetBaseAnalyses(npv1Stock, calcs); return(bHasAnalyses); }
private bool SetAnalyses(NPV1Stock npv1Stock) { bool bHasAnalysis = false; npv1Stock.Stat1.CalcParameters = npv1Stock.CalcParameters; //totals were added to npv1stock, but those totals result //in double counting when calcs are being summed //set them to zero npv1Stock.Stat1.InitTotalBenefitsProperties(); npv1Stock.Stat1.InitTotalCostsProperties(); npv1Stock.Stat1.TotalRAmount = 0; //times is already in comp amount npv1Stock.Stat1.TotalRCompositionAmount = 0; npv1Stock.Stat1.TotalRPrice = 0; bHasAnalysis = true; return(bHasAnalysis); }
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 void CopyTotalNPV1Total1Properties(NPV1Total1 ind, NPV1Stock calculator) { if (calculator != null) { ind.ErrorMessage = calculator.ErrorMessage; //includes summary data ind.CopyCalculatorProperties(calculator); ind.CopyTotalBenefitsProperties(calculator); ind.CopyTotalCostsProperties(calculator); if (calculator.CalcParameters == null) { calculator.CalcParameters = new CalculatorParameters(); } if (ind.CalcParameters == null) { ind.CalcParameters = new CalculatorParameters(); } ind.CalcParameters = new CalculatorParameters(calculator.CalcParameters); } }
public static void CopyStockCalculator(List <Calculator1> oldcalcs, List <Calculator1> newcalcs) { if (oldcalcs != null) { if (newcalcs == null) { newcalcs = new List <Calculator1>(); } foreach (Calculator1 calc in oldcalcs) { //don't init newstock with this.GCCalcParam, use the oldcalc.CalcParams NPV1Stock newStock = new NPV1Stock(); //NPV1Stock newStock = new NPV1Stock(this.GCCalculatorParams, this.GCCalculatorParams.AnalyzerParms.AnalyzerType); bool bHasCopy = CopyStockCalculator(calc, newStock); if (bHasCopy) { newcalcs.Add(newStock); } } } }
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); }
public virtual void CopyTotalNPV1StocksProperties( NPV1Stock calculator) { //this is called after the initial calculator collections have been built //it adds those initial calcs to correct agg stock this.CopyCalculatorProperties(calculator); this.CalcParameters = calculator.CalcParameters; //base calculator holds totals (always inits with calculator.Total) if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvstat1.ToString()) { this.Stat1 = new NPV1Stat1(); this.Stat1.CopyTotalNPV1Stat1Properties( this.Stat1, calculator.Stat1); } else if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangeyr.ToString() || this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangeid.ToString() || this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangealt.ToString()) { this.Change1 = new NPV1Change1(); this.Change1.CopyTotalNPV1Change1Properties( this.Change1, calculator.Change1); } else if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvprogress1.ToString()) { this.Progress1 = new NPV1Progress1(); this.Progress1.CopyTotalNPV1Progress1Properties( this.Progress1, calculator.Progress1); } else { //calculator stores starting npv totals in calculator.Total1 this.Total1 = new NPV1Total1(); this.Total1.CopyTotalNPV1Total1Properties( this.Total1, calculator.Total1); } }
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); }
//copy constructor public NPV1Stock(NPV1Stock calculator) { CopyTotalNPV1StocksProperties(calculator); }
//note this must only copy the R Props (TRAmount) not TRAM, because the NPV calculator originally ran that calc public virtual void CopyTotalNPV1RPropertiesToCalc(Calculator1 calc) { if (calc == null) { return; } if (calc.GetType().Equals(this.GetType())) { NPV1Stock toCalcStock = (NPV1Stock)calc; if (toCalcStock != null) { if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvstat1.ToString()) { if (this.Stat1 == null) { return; } if (toCalcStock.Stat1 == null) { toCalcStock.Stat1 = new NPV1Stat1(); } toCalcStock.Stat1.CopyTotalNPV1Stat1RProperties(this.Stat1); } else if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangeyr.ToString() || this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangeid.ToString() || this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvchangealt.ToString()) { if (this.Change1 == null) { return; } if (toCalcStock.Change1 == null) { toCalcStock.Change1 = new NPV1Change1(); } toCalcStock.Change1.CopyTotalNPV1Change1RProperties(this.Change1); } else if (this.AnalyzerType == NPV1AnalyzerHelper.ANALYZER_TYPES.npvprogress1.ToString()) { if (this.Progress1 == null) { return; } if (toCalcStock.Progress1 == null) { toCalcStock.Progress1 = new NPV1Progress1(); } toCalcStock.Progress1.CopyTotalNPV1Progress1RProperties(this.Progress1); } else { if (this.Total1 == null) { return; } if (toCalcStock.Total1 == null) { toCalcStock.Total1 = new NPV1Total1(); } toCalcStock.Total1.CopyTotalNPV1Total1RProperties(this.Total1); } } } }