public bool SetTimePeriodMachinery2StockJointCalculations(ref XElement currentCalculationsElement, ref XElement currentElement) { //miscellaneous aggregations (i.e. inputgroup, operationgroup) bool bHasCalculations = false; //standard getally calcs will retrieve resource 01 calculator //(because finds relatedcalculatortype=agmachinery) //which must not be overwritten if UseSameCalcInChildren = true currentCalculationsElement = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement, Calculator1.cAnalyzerType, this.GCCalculatorParams.AnalyzerParms.AnalyzerType); //CalculatorHelpers.ReplaceAnalyzerCalculator(this.GCCalculatorParams, currentElement, // ARSAnalyzerHelper.ANALYZER_TYPES.resources02a.ToString(), // ref currentCalculationsElement); if (currentCalculationsElement == null) { //either a base resource01 calculation was not run //or it was never added to base npv calculator currentCalculationsElement = new XElement(this.GCCalculatorParams.LinkedViewElement); } //Step 1. set both stock collections int iFPIndex = this.GCCalculatorParams.AnalyzerParms.FilePositionIndex; int iTimeIndex = this.TimePeriodStartingFileIndex; this.SetTimePeriodMachineryStockCalculations(ref currentCalculationsElement, ref currentElement); this.GCCalculatorParams.AnalyzerParms.FilePositionIndex = iFPIndex; this.TimePeriodStartingFileIndex = iTimeIndex; bHasCalculations = SetTimePeriodMachinery2StockCalculations(ref currentCalculationsElement, ref currentElement); //keep the newly set fileposition index //note that 02a supplements this method with with calculations that use the Timeliness collections return(bHasCalculations); }
public void AdjustJointOutputCalculations( Output output, ref XElement currentCalculationsElement, CalculatorParameters calcParameters) { //transfer changes found in calcParams.ParentOutcome.Outputs[] //to this output, prior to discounting if (calcParameters.ParentOutcome.Outputs != null) { int iOutputId = output.Id; Output adjustedOutput = calcParameters.ParentOutcome.Outputs .FirstOrDefault(i => i.Id == iOutputId && i.Type == CostBenefitCalculator.TYPE_NEWCALCS); if (adjustedOutput != null) { //replace output output.CopyOutput(adjustedOutput); //output = new Output(adjustedOutput); if (adjustedOutput.XmlDocElement != null) { //adjustments can change fuel amounts, AOHAmounts ... output.XmlDocElement = new XElement(adjustedOutput.XmlDocElement); string sId = CalculatorHelpers.GetAttribute(currentCalculationsElement, Calculator1.cId); currentCalculationsElement = CalculatorHelpers.GetChildLinkedViewUsingAttribute( adjustedOutput.XmlDocElement, Calculator1.cId, sId); } } } }
public void ChangeCalculator(XElement currentElement, ref XElement calculator) { //these analyzers use atts from calculators only if (this.GCCalculatorParams.AnalyzerParms.AnalyzerType == ME2AnalyzerHelper.ANALYZER_TYPES.mechangealt.ToString() || this.GCCalculatorParams.AnalyzerParms.AnalyzerType == ME2AnalyzerHelper.ANALYZER_TYPES.meprogress1.ToString()) { //don't change the starting calculator if (this.GCCalculatorParams.StartingDocToCalcNodeName == currentElement.Name.LocalName) { return; } bool bIsChildren = CalculatorHelpers.IsSelfOrChildNode(this.GCCalculatorParams, currentElement.Name.LocalName); bool bIsTPGrandChild = (currentElement.Name.LocalName == BudgetInvestment.BUDGET_TYPES.budgettimeperiod.ToString() || currentElement.Name.LocalName == BudgetInvestment.INVESTMENT_TYPES.investmenttimeperiod.ToString()) ? true : false; //need the alt or target type from mecalcs if (bIsChildren || bIsTPGrandChild) { bool bIsMECalculator = false; string sCurrentCalcType = string.Empty; if (calculator != null) { sCurrentCalcType = CalculatorHelpers.GetAttribute(calculator, Calculator1.cCalculatorType); } if (!string.IsNullOrEmpty(sCurrentCalcType)) { //see if it matches a real me calctype CalculatorHelpers.CALCULATOR_TYPES calcType = CalculatorHelpers.GetCalculatorType(sCurrentCalcType); if (calcType != CalculatorHelpers.CALCULATOR_TYPES.none) { bIsMECalculator = true; } } if (calculator == null || bIsMECalculator == false) { calculator = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement, Calculator1.cCalculatorType, currentElement.Name.LocalName); } } } }
private XElement GetHealthCareCalculator(CalculatorParameters calcParameters, string calculatorType, XElement outputElement) { XElement oCalculationsElement = null; if (outputElement.Name.LocalName == Constants.LINKEDVIEWS_TYPES.linkedview.ToString()) { if (calculatorType == HCCalculatorHelper.CALCULATOR_TYPES.hcbenefit1.ToString()) { oCalculationsElement = outputElement; } } else { oCalculationsElement = CalculatorHelpers.GetChildLinkedViewUsingAttribute(outputElement, Calculator1.cCalculatorType, HCCalculatorHelper.CALCULATOR_TYPES.hcbenefit1.ToString()); if (oCalculationsElement == null) { } } return(oCalculationsElement); }
private void ChangeLinkedViewCalculator(XElement currentElement, ref XElement linkedViewElement) { //v137 pattern allows analyzers to update descendents using dbupdates //i.e. need i/o calculators to get totals, but don't want to //overwrite those calculations in db if (this.GCCalculatorParams.ExtensionCalcDocURI.URIDataManager.HostName == DevTreks.Data.Helpers.AddInHelper.HOSTS.extensionanalyzersteps.ToString() && this.GCCalculatorParams.NeedsCalculators && CalculatorHelpers.IsSelfOrChildNode(this.GCCalculatorParams, currentElement.Name.LocalName)) { //100% Rule 1: Analyzers never, ever, update calculators string sCalculatorType = CalculatorHelpers.GetAttribute(linkedViewElement, Calculator1.cCalculatorType); //pure calculators never have an analysis type string sAnalysisType = CalculatorHelpers.GetAttribute(linkedViewElement, Calculator1.cAnalyzerType); if (!string.IsNullOrEmpty(sCalculatorType) && string.IsNullOrEmpty(sAnalysisType)) { //order of lv retrieval gets calulators before analyzers XElement analyzerLV = CalculatorHelpers.GetChildLinkedViewUsingAttribute( currentElement, Calculator1.cAnalyzerType, this.GCCalculatorParams.AnalyzerParms.AnalyzerType); if (analyzerLV != null) { if (this.GCCalculatorParams.LinkedViewElement != null) { //keep the id and calculatorid, but update the rest of the atts with new lv string sId = CalculatorHelpers.GetAttribute(analyzerLV, Calculator1.cId); string sCalcId = CalculatorHelpers.GetAttribute(analyzerLV, Calculator1.cCalculatorId); analyzerLV = new XElement(this.GCCalculatorParams.LinkedViewElement); CalculatorHelpers.SetAttribute(analyzerLV, Calculator1.cId, sId); CalculatorHelpers.SetAttribute(analyzerLV, Calculator1.cCalculatorId, sCalcId); } //use it to update db (not the calculator) linkedViewElement = new XElement(analyzerLV); } else { //use the base linked view standard pattern //avoids updating the wrong lvs linkedViewElement = CalculatorHelpers.GetNewCalculator(this.GCCalculatorParams, currentElement); } } } //100% Rule 2: Analyzers and Calculators never, ever, allow descendent lvs //to have parent Overwrite or UseSameCalc properties if (this.GCCalculatorParams.StartingDocToCalcNodeName != currentElement.Name.LocalName) { if (linkedViewElement != null) { string sAttValue = CalculatorHelpers.GetAttribute(linkedViewElement, Calculator1.cUseSameCalculator); if ((!string.IsNullOrEmpty(sAttValue)) && sAttValue != Constants.NONE) { CalculatorHelpers.SetAttribute(linkedViewElement, Calculator1.cUseSameCalculator, string.Empty); } sAttValue = CalculatorHelpers.GetAttribute(linkedViewElement, Calculator1.cOverwrite); if ((!string.IsNullOrEmpty(sAttValue)) && sAttValue != Constants.NONE) { CalculatorHelpers.SetAttribute(linkedViewElement, Calculator1.cOverwrite, string.Empty); } } } }
public ME2Stock SetME2Properties(CostBenefitCalculator baseElement, XElement currentCalculationsElement, XElement currentElement) { ME2Stock me2 = new ME2Stock(this.GCCalculatorParams, this.GCCalculatorParams.AnalyzerParms.AnalyzerType); //204 not used //if (this.ME2DescendentStock != null) //{ // //only property set by analyzer // me2.TotalME2Stage = this.ME2DescendentStock.TotalME2Stage; //} ME2Calculator me2Calc = new ME2Calculator(this.GCCalculatorParams); me2.CalcParameters.CurrentElementNodeName = currentElement.Name.LocalName; bool bHasCalcs = false; if (currentCalculationsElement != null) { //have to make sure its not a stockanalyzer string sCalculatorType = CalculatorHelpers.GetAttribute( currentCalculationsElement, Calculator1.cCalculatorType); if (sCalculatorType == ME2CalculatorHelper.CALCULATOR_TYPES.me2.ToString()) { //deserialize xml to object me2Calc.SetME2Properties(currentCalculationsElement, currentElement); //only need alttype and targettype (alts are groupedby using base elements) baseElement.AlternativeType = me2Calc.AlternativeType; baseElement.TargetType = me2Calc.TargetType; bHasCalcs = true; } } if (!bHasCalcs) { //see if a sibling holds the calculations (currentCalcs could be the analyzer) XElement lv = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement, Calculator1.cCalculatorType, ME2CalculatorHelper.CALCULATOR_TYPES.me2.ToString()); if (lv != null) { //deserialize xml to object me2Calc.SetME2Properties(lv, currentElement); //only need alttype and targettype (alts are groupedby using base elements) baseElement.AlternativeType = me2Calc.AlternativeType; baseElement.TargetType = me2Calc.TargetType; bHasCalcs = true; } } if (!bHasCalcs) { //else don't need the ids from calculator me2.CopyCalculatorProperties(baseElement); } //all calcs and analyses are stored in the appropriate analysis object (i.e. me2.Total, me2.Stat) me2.InitTotalME2StocksProperties(); //copy the initial calculator to the appropriate analysis object.ME2Indicators collection me2.CopyME2CalculatorToME2Stock(me2Calc); me2.AnalyzerType = this.GCCalculatorParams.AnalyzerParms.AnalyzerType; //label and date comes from baseelement me2.Label = baseElement.Label; me2.Date = baseElement.Date; //kiss with the multipliers me2.Multiplier = baseElement.Multiplier; me2.CalculatorId = me2Calc.Id; //adjust id if children analyzers are being inserted/updated ChangeCalculatorIdForUpdatedChildren(currentElement, ref currentCalculationsElement, me2); return(me2); }
private void ChangeCalculatorIdForUpdatedChildren(XElement currentElement, ref XElement calculator, ME2Stock me2) { //alternatives are set using ME calculators (or input/output calculators) bool bIsChildrenUpdate = CalculatorHelpers.IsSelfOrChildNode(this.GCCalculatorParams, currentElement.Name.LocalName); if (bIsChildrenUpdate) { //don't change the starting calculator if (this.GCCalculatorParams.StartingDocToCalcNodeName == currentElement.Name.LocalName) { return; } XElement lv = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement, Calculator1.cAnalyzerType, this.GCCalculatorParams.AnalyzerParms.AnalyzerType.ToString()); //init with random calculator id if (this.GCCalculatorParams.RndGenerator == null) { this.GCCalculatorParams.RndGenerator = new Random(); } int iCalcId = this.GCCalculatorParams.RndGenerator.Next(); if (lv != null) { //switch to a calc that needs to be updated iCalcId = CalculatorHelpers.GetAttributeInt(lv, Calculator1.cId); } else { if (calculator != null) { //use the existing calc (gencalcsubscriber will replace with a new one anyway) lv = new XElement(calculator); } } if (lv != null) { //change analyzer so that it can be inserted or updated (instead of the existing me calc) CalculatorHelpers.SetAttributeInt(lv, Calculator1.cId, iCalcId); CalculatorHelpers.SetAttributeInt(lv, Calculator1.cCalculatorId, iCalcId); //important for updates that this get set to string.empty CalculatorHelpers.SetAttribute(lv, Calculator1.cCalculatorType, string.Empty); CalculatorHelpers.SetAttribute(lv, Calculator1.cAnalyzerType, this.GCCalculatorParams.AnalyzerParms.AnalyzerType); //tells subscriber to update/insert child calculator = new XElement(lv); } if (iCalcId != 0) { me2.Id = iCalcId; me2.CalculatorId = iCalcId; if (me2.Total1 != null) { me2.Total1.Id = iCalcId; me2.Total1.CalculatorId = iCalcId; } if (me2.Stat1 != null) { me2.Stat1.Id = iCalcId; me2.Stat1.CalculatorId = iCalcId; } if (me2.Change1 != null) { me2.Change1.Id = iCalcId; me2.Change1.CalculatorId = iCalcId; } if (me2.Progress1 != null) { me2.Progress1.Id = iCalcId; me2.Progress1.CalculatorId = iCalcId; } } } }
public bool SetOpOrCompMachinery2StockJointCalculations(ref XElement currentCalculationsElement, ref XElement currentElement) { bool bHasCalculations = false; if (this.GCCalculatorParams.SubApplicationType == Constants.SUBAPPLICATION_TYPES.operationprices || this.GCCalculatorParams.SubApplicationType == Constants.SUBAPPLICATION_TYPES.componentprices) { string sAnalyzerType = CalculatorHelpers.GetAnalyzerType(currentCalculationsElement); if (sAnalyzerType != this.GCCalculatorParams.AnalyzerParms.AnalyzerType) { //standard getally calcs may retrieve resource 01 calculator //(because finds relatedcalculatortype=agmachinery) //which must not be overwritten if UseSameCalcInChildren = true currentCalculationsElement = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement, Calculator1.cAnalyzerType, this.GCCalculatorParams.AnalyzerParms.AnalyzerType); //CalculatorHelpers.ReplaceAnalyzerCalculator(this.GCCalculatorParams, currentElement, // this.GCCalculatorParams.AnalyzerParms.AnalyzerType, // ref currentCalculationsElement); } } //step 4. Run both mach1stock and mach2stock calculations keeping both indices synch string sCalculatorType = CalculatorHelpers.CALCULATOR_TYPES.operation2.ToString(); if (currentElement.Name.LocalName.EndsWith(OperationComponent.OPERATION_PRICE_TYPES.operation.ToString())) { sCalculatorType = CalculatorHelpers.CALCULATOR_TYPES.operation2.ToString(); } else if (currentElement.Name.LocalName.EndsWith(OperationComponent.COMPONENT_PRICE_TYPES.component.ToString())) { sCalculatorType = CalculatorHelpers.CALCULATOR_TYPES.component2.ToString(); } if (currentCalculationsElement == null) { //either a base resource01 calculation was not run //or it was never added to base npv calculator currentCalculationsElement = new XElement(this.GCCalculatorParams.LinkedViewElement); } //i.e. make sure to use the baseNPV linked view holding base machinery cost and timeliness penalty information XElement baseNPVCalculation = CalculatorHelpers.GetChildLinkedViewUsingAttribute(currentElement, Calculator1.cCalculatorType, sCalculatorType); if (baseNPVCalculation == null) { //the display will point out bad params if currentCalcEl is wrong baseNPVCalculation = currentCalculationsElement; } ////set machinery cost totals //int iFPIndex = this.GCCalculatorParams.AnalyzerParms.FilePositionIndex; //when this method is called from opcomp or input group if (this.TimelinessOpComp == null) { this.TimelinessOpComp = new TimelinessOpComp1(); } //note that the machnpvoc calculator can not change Operation properties //but needs several properties from the Operation (i.e. Id, Amount) this.TimelinessOpComp.SetOperationComponentProperties(this.GCCalculatorParams, currentCalculationsElement, currentElement); //init mach2Stock props this.Machinery2Stock.SetCalculatorProperties(currentCalculationsElement); this.TimelinessOpComp.SetTimelinessOC1Properties(baseNPVCalculation); //baseNPVCalc must be used to set machinery calcs this.SetOpOrCompMachineryStockCalculations(ref currentCalculationsElement, ref currentElement); //reset opcomp.amount to base (not the stored linkedview amount) this.TimelinessOpComp.SetTimelinessBaseProperties(currentElement); //set machinery cost totals int iFPIndex = this.GCCalculatorParams.AnalyzerParms.FilePositionIndex; this.GCCalculatorParams.AnalyzerParms.FilePositionIndex = iFPIndex; //set timeliness penalty totals bHasCalculations = SetOpOrCompMachinery2StockCalculations(ref currentCalculationsElement, ref currentElement); //keep the newly set fileposition index return(bHasCalculations); }