private void PrepareIterationPar() { ParTU parEligUnit = GetUniquePar <ParTU>(DefPar.UnitLoop.Elig_Unit); if (parEligUnit != null) { eligUnit = parEligUnit.name; } parEligUnitCond = GetUniquePar <ParCond>(DefPar.UnitLoop.Elig_Unit_Cond); ParCateg parWho = GetUniquePar <ParCateg>(DefPar.UnitLoop.Elig_Unit_Cond_Who); if (parWho != null) { who = parWho.GetCateg(); } }
protected override void PrepareNonCommonPar() { // get parameters ParIL parOperatorIL = GetUniquePar <ParIL>(DefPar.IlVarOp.Operator_IL); if (parOperatorIL == null) { return; // error is handled by global check } ParFormula parOperand = GetUniquePar <ParFormula>(DefPar.IlVarOp.Operand); bool useFactors = GetParBoolValueOrDefault(DefFun.IlVarOp, DefPar.IlVarOp.Operand_Factors); ParIL parOperandIL = GetUniquePar <ParIL>(DefPar.IlVarOp.Operand_IL); ParCateg parMulAdd = GetUniquePar <ParCateg>(DefPar.IlVarOp.Operation); if (parMulAdd != null) { mulAdd = parMulAdd.GetCateg(); } ParCateg parSelVar = GetUniquePar <ParCateg>(DefPar.IlVarOp.Sel_Var); if (parSelVar != null) { selVar = parSelVar.GetCateg(); } // assess what to do and check for insufficient or contradictory information if (parOperand != null) { //if (parOperand.IsGlobal()) opTask = OPERAND_TYPE.SCALAR; // out-commented to replace by the weaker condtion below, otherwise it produces an error with constants if (double.TryParse(parOperand.xmlValue, out double x)) { opTask = OPERAND_TYPE.SCALAR; } else { opTask = OPERAND_TYPE.FORMULA; formulaOperand = parOperand; } } else if (parOperandIL != null) { if (!CheckDoubleDef(OPERAND_TYPE.IL)) { return; } } if (useFactors) { if (!CheckDoubleDef(OPERAND_TYPE.FACTORS)) { return; } } if (mulAdd == DefPar.Value.ILVAROP_NEGTOZERO) { if (!CheckDoubleDef(OPERAND_TYPE.NEGTOZERO)) { return; } } if (opTask == OPERAND_TYPE.INVALID) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: missing definition of operand" }); return; } if (opTask == OPERAND_TYPE.IL && parOperandIL.GetFlatContent().Count != parOperatorIL.GetFlatContent().Count) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: incomelists {parOperatorIL.name} and {parOperandIL.name} do not have the same number of variables, operation is not possible" }); return; } // prepare information for run for (int i = 0; i < parOperatorIL.GetFlatContent().Count; ++i) { OpItem oi = new OpItem() { varOperator = parOperatorIL.GetFlatContent()[i].varSpec }; switch (opTask) { case OPERAND_TYPE.FACTORS: oi.numOperand = parOperatorIL.GetFlatContent()[i].addFactor; break; case OPERAND_TYPE.SCALAR: oi.numOperand = parOperand.GetGlobalValue(); break; case OPERAND_TYPE.IL: oi.varOperand = parOperandIL.GetFlatContent()[i].varSpec; break; } opItems.Add(oi); } bool CheckDoubleDef(OPERAND_TYPE ot) { if (opTask == OPERAND_TYPE.INVALID) { opTask = ot; return(true); } infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: contradictory definition of operand" }); return(false); } }
protected void PrepareLimPar() { coParLowLim = GetUniquePar <ParFormula>(DefPar.Common.LowLim); coParUpLim = GetUniquePar <ParFormula>(DefPar.Common.UpLim); coParThres = GetUniquePar <ParFormula>(DefPar.Common.Threshold); ParCateg coParLimpriority = GetUniquePar <ParCateg>(DefPar.Common.Limpriority); // the following tries to optimise by getting the values here, if they are read-time-available (e.g. 600#y, GetSystemYear, ...) // and by checking for implausible values (e.g. upLim = 10, lowLim = 100) if already possible if (coParLowLim != null) { if (coParLowLim.IsGlobal(true)) { lowLim = coParLowLim.GetGlobalValue(); coParLowLim = null; } else { doRunTimeLimCheck = true; } } if (coParUpLim != null) { if (coParUpLim.IsGlobal(true)) { upLim = coParUpLim.GetGlobalValue(); coParUpLim = null; } else { doRunTimeLimCheck = true; } } bool checkThres = coParThres != null; if (coParThres != null) { if (coParThres.IsGlobal(true)) { thres = coParThres.GetGlobalValue(); coParThres = null; } else { doRunTimeThresCheck = true; } } if (coParLimpriority != null) { limPri = coParLimpriority.GetCateg(); } if (!doRunTimeLimCheck) // both limits available (might be double.MinValue and/or double.MaxValue, but does no harm here) { CheckLimits(ref lowLim, ref upLim); if (checkThres && !doRunTimeThresCheck) // threshold and both limits available { if (!CheckThreshold(thres, lowLim, upLim)) { thres = lowLim; } } } }
protected override void PrepareNonCommonPar() { ParCateg parType = GetUniquePar <ParCateg>(DefPar.DefTu.Type); if (parType != null) { tuType = parType.GetCateg(); } if (tuType != DefPar.Value.TUTYPE_IND) { // get the INCOME used to define the head headDefInc = GetUniquePar <ParVarIL>(DefPar.DefTu.HeadDefInc); if (headDefInc == null) // if no income defined, use ils_origy as default { headDefInc = new ParVarIL(infoStore); headDefInc.xmlValue = infoStore.country.sys.headDefInc == string.Empty ? DefVarName.ILSORIGY : infoStore.country.sys.headDefInc; headDefInc.description = description; headDefInc.CheckAndPrepare(this); } // get all the conditions and set the defaults if they did not exist before if (extHeadCond == null) { extHeadCond = new ParCond(infoStore) { xmlValue = DefPar.DefTu.DEFAULT_CONDITION.EXTHEAD, description = description }; extHeadCond.CheckAndPrepare(this); } } if (partnerCond == null) { partnerCond = new ParCond(infoStore) { xmlValue = DefPar.DefTu.DEFAULT_CONDITION.PARTNER, description = description }; partnerCond.CheckAndPrepare(this); } if (depChildCond == null) { depChildCond = new ParCond(infoStore) { xmlValue = "{0}", description = description }; depChildCond.CheckAndPrepare(this); } if (ownChildCond == null) { ownChildCond = new ParCond(infoStore) { xmlValue = DefPar.DefTu.DEFAULT_CONDITION.OWNCHILD, description = description }; ownChildCond.CheckAndPrepare(this); } if (ownDepChildCond == null) { ownDepChildCond = new ParCond(infoStore) { xmlValue = DefPar.DefTu.DEFAULT_CONDITION.OWNDEPCHILD, description = description }; ownDepChildCond.CheckAndPrepare(this); } if (looseDepChildCond == null) { looseDepChildCond = new ParCond(infoStore) { xmlValue = DefPar.DefTu.DEFAULT_CONDITION.LOOSEDEPCHILD, description = description }; looseDepChildCond.CheckAndPrepare(this); } if (depParentCond == null) { depParentCond = new ParCond(infoStore) { xmlValue = DefPar.DefTu.DEFAULT_CONDITION.DEPPARENT, description = description }; depParentCond.CheckAndPrepare(this); } if (depRelativeCond == null) { depRelativeCond = new ParCond(infoStore) { xmlValue = DefPar.DefTu.DEFAULT_CONDITION.DEPRELATIVE, description = description }; depRelativeCond.CheckAndPrepare(this); } if (loneParentCond == null) { loneParentCond = new ParCond(infoStore) { xmlValue = DefPar.DefTu.DEFAULT_CONDITION.LONEPARENT, description = description }; loneParentCond.CheckAndPrepare(this); } // get all the booleans and set the values ParBool noChildIfHeadPar = GetUniquePar <ParBool>(DefPar.DefTu.NoChildIfHead); noChildIfHead = noChildIfHeadPar != null && noChildIfHeadPar.GetBoolValue(); ParBool noChildIfPartnerPar = GetUniquePar <ParBool>(DefPar.DefTu.NoChildIfPartner); noChildIfPartner = noChildIfPartnerPar != null && noChildIfPartnerPar.GetBoolValue(); ParBool assignDepChOfDependentsPar = GetUniquePar <ParBool>(DefPar.DefTu.AssignDepChOfDependents); assignDepChOfDependents = assignDepChOfDependentsPar != null && assignDepChOfDependentsPar.GetBoolValue(); ParBool assignPartnerOfDependentsPar = GetUniquePar <ParBool>(DefPar.DefTu.AssignPartnerOfDependents); assignPartnerOfDependents = assignPartnerOfDependentsPar != null && assignPartnerOfDependentsPar.GetBoolValue(); ParBool stopIfNoHeadFoundPar = GetUniquePar <ParBool>(DefPar.DefTu.StopIfNoHeadFound); stopIfNoHeadFound = stopIfNoHeadFoundPar != null && stopIfNoHeadFoundPar.GetBoolValue(); ParCateg multiplePartnersPar = GetUniquePar <ParCateg>(DefPar.DefTu.MultiplePartners); multiplePartners = multiplePartnersPar == null ? string.Empty : multiplePartnersPar.GetCateg(); }
protected virtual bool IsEligCondMet(HH hh, List <Person> tu) { return(coParWho == null ? true : IsCondMetByTU(hh, tu, indexEligVar, coParWho.GetCateg())); }
/// <summary> /// checks if the standard footnote-parameters, i.e. #_LowLim, #_UpLim, #_Level, are applied on the parameter /// if so, stores them in lowLim, upLim and alternativeTU (see above) /// also provides the "cleaned" value (e.g. yem#1 -> yem) /// note that the footnote-parameters are assessed via the (mother)function (parameter fun) /// also note that the only other (not here handled) footnote-parameters are 'amount', which is handled by ParFormula /// and query parameters which will not issue a "missing" (see below) but let the query check if it can use the footnote /// </summary> protected void ExtractStandardFootnotes(string value, out string cleanedValue, FunBase fun) { List <string> numbers = GetFootnoteNumbers(value, out cleanedValue); // it's unlikely, but yem#1#3 is possible (see GetFootnoteNumbers) if (numbers.Count == 0) { return; // no footnotes } // limits (see remark in _FunInSpineBase_Lim wrt not using a common implementation for limits) pLowLim = fun.GetFootnotePar <ParFormula>(DefPar.Footnote.LowLim, numbers); if (pLowLim != null) { if (pLowLim.IsGlobal(true)) { lowLim = pLowLim.GetGlobalValue(); pLowLim = null; } else { doRunTimeLimCheck = true; } } pUpLim = fun.GetFootnotePar <ParFormula>(DefPar.Footnote.UpLim, numbers); if (pUpLim != null) { if (pUpLim.IsGlobal(true)) { upLim = pUpLim.GetGlobalValue(); pUpLim = null; } else { doRunTimeLimCheck = true; } } ParCateg pLimpriority = fun.GetFootnotePar <ParCateg>(DefPar.Footnote.LimPriority, numbers); if (pLimpriority != null) { limPri = pLimpriority.GetCateg(); } if (!doRunTimeLimCheck) // both limits available (might be double.MinValue and/or double.MaxValue, but does no harm here) { CheckLimits(ref lowLim, ref upLim); } // alternative TU ParBase parAltTU = fun.GetFootnotePar <ParBase>(DefPar.Footnote.Level, numbers); if (parAltTU != null) { alternativeTU = parAltTU.xmlValue; } // if none of the standard footnotes is defined in the function #x points to nowhere ... if (GetType() == typeof(ParQuery)) // ... except for queries, which may have own footnotes { return; // (this is slightly negligent, as it accepts e.g. IsMarried#1 without respective footnote-parameter) } if (pLowLim == null && lowLim == double.MinValue && pUpLim == null && upLim == double.MaxValue && parAltTU == null) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = true, message = $"{description.Get()}: missing footnote parameter for {value}" }); } }
protected override void PrepareNonCommonPar() { aggs = GetNonUniquePar <ParVarIL>(DefPar.Totals.Agg); if (aggs.Count == 0) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: missing required parameter AGG" }); return; } foreach (string t in new List <string> { DefPar.Totals.Varname_Sum, DefPar.Totals.Varname_Mean, DefPar.Totals.Varname_Median, DefPar.Totals.Varname_Decile, DefPar.Totals.Varname_Quintile, DefPar.Totals.Varname_Count, DefPar.Totals.Varname_PosCount, DefPar.Totals.Varname_NegCount, DefPar.Totals.Varname_Min, DefPar.Totals.Varname_Max }) { ParBase par = GetUniquePar <ParBase>(t); if (par == null) { continue; } actions.Add(t); foreach (ParVarIL agg in aggs) { string aggName = agg.GetName(); agg.CheckAndPrepare(this); int n = 1; if (t == DefPar.Totals.Varname_Decile) { n = 9; } if (t == DefPar.Totals.Varname_Quintile) { n = 4; } for (int i = 1; i <= n; ++i) { string counter = t == DefPar.Totals.Varname_Decile || t == DefPar.Totals.Varname_Quintile ? i.ToString() : string.Empty; string varName = $"{par.xmlValue}{counter}_{aggName}"; infoStore.operandAdmin.RegisterVar( // generate the variable that will take the total name: varName, creatorFun: DefFun.Totals, description: par.description, isMonetary: false, // not really clear, but adding over TU does not make sense isGlobal: true, // equal for each person isWriteable: false, // cannot be use as output-variable setInitialised: true); if (infoStore.operandAdmin.Exists(varName)) { totals.Add(t + (n > 1 ? i.ToString() : "") + aggName, new VarSpec() { name = varName }); } } } } // setup booleans hasMedian = actions.Contains(DefPar.Totals.Varname_Median); hasQuint = actions.Contains(DefPar.Totals.Varname_Quintile); hasDec = actions.Contains(DefPar.Totals.Varname_Decile); hasSum = actions.Contains(DefPar.Totals.Varname_Sum); hasMean = actions.Contains(DefPar.Totals.Varname_Mean); // check if there is a condition for inclusion ParCond inclCond = GetUniquePar <ParCond>(DefPar.Totals.Incl_Cond); if (inclCond != null) { ParCateg inclWho = GetUniquePar <ParCateg>(DefPar.Totals.Incl_Cond_Who); string inclWhoVal = (inclWho == null) ? DefPar.Value.WHO_ALL : inclWho.GetCateg(); include = new Tuple <ParCond, string>(inclCond, inclWhoVal); } // check if results should be weighted useWeights = GetParBoolValueOrDefault(DefFun.Totals, DefPar.Totals.Use_Weights); if (useWeights) // get the weight var, if null use dwt { ParVar dwtPar = GetUniquePar <ParVar>(DefPar.Totals.Weight_Var); dwtName = dwtPar != null ? dwtPar.name : DefVarName.DWT; infoStore.operandAdmin.CheckRegistration(dwtName, false, false, description); } // }
protected override void PrepareNonCommonPar() { ParVar fv = GetUniquePar <ParVar>(DefPar.AddHHMembers.FlagVar); if (fv != null) { flagVar = new VarSpec() { name = fv.name } } ; foreach (var g in GetParGroups(DefPar.AddHHMembers.GROUP_MAIN)) { var group = g.Value; int groupNo = g.Key; AddInstruction addInstruction = new AddInstruction(); // first find out whether we are adding children or partners or other persons ... ParCateg parWho = GetUniqueGroupPar <ParCateg>(DefPar.AddHHMembers.Add_Who, group); if (parWho == null) { continue; // compulsory parameter, error already issued } addInstruction.addWho = parWho.GetCateg(); // ... depending on that, check the add-condition ParCond parParent = GetUniqueGroupPar <ParCond>(DefPar.AddHHMembers.ParentCond, group); ParCond parPartner = GetUniqueGroupPar <ParCond>(DefPar.AddHHMembers.PartnerCond, group); ParCond parOther = GetUniqueGroupPar <ParCond>(DefPar.AddHHMembers.HHCond, group); string missing = string.Empty; string tooMuch = string.Empty; switch (addInstruction.addWho) { case DefPar.Value.ADDHHMEMBERS_CHILD: if (parParent != null) { addInstruction.cond = parParent; } else { missing = DefPar.AddHHMembers.ParentCond; } if (parPartner != null) { tooMuch = DefPar.AddHHMembers.PartnerCond + " "; } if (parOther != null) { tooMuch = DefPar.AddHHMembers.HHCond; } ParBool parIsPP = GetUniqueGroupPar <ParBool>(DefPar.AddHHMembers.IsPartnerParent, group); if (parIsPP != null) { addInstruction.isPartnerParent = parIsPP.GetBoolValue(); } break; case DefPar.Value.ADDHHMEMBERS_PARTNER: if (parParent != null) { tooMuch = DefPar.AddHHMembers.ParentCond + " "; } if (parPartner != null) { addInstruction.cond = parPartner; } else { missing = DefPar.AddHHMembers.PartnerCond; } if (parOther != null) { tooMuch = DefPar.AddHHMembers.HHCond; } break; case DefPar.Value.ADDHHMEMBERS_OTHER: if (parParent != null) { tooMuch = DefPar.AddHHMembers.ParentCond + " "; } if (parPartner != null) { tooMuch = DefPar.AddHHMembers.PartnerCond; } if (parOther != null) { addInstruction.cond = parOther; } else { missing = DefPar.AddHHMembers.HHCond; } break; default: continue; // error is caught by general error handling } if (missing != string.Empty) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()} (group {groupNo}): {DefPar.AddHHMembers.Add_Who}={addInstruction.addWho} requires parameter {missing}" }); } if (tooMuch != string.Empty) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = true, message = $"{description.Get()} (group {groupNo}): {DefPar.AddHHMembers.Add_Who}={addInstruction.addWho} does not require {tooMuch}" }); } // here we are only gathering the variables that are to be set, but do not evaluate whether they exist // note: this function does not "register" variables, i.e. if a variable is not used anywhere else, it cannot be set foreach (ParFormula parVarDefinition in GetPlaceholderGroupPar <ParFormula>(group)) { string varName = parVarDefinition.description.GetParName(); if (addInstruction.prepVarDefinitions.ContainsKey(varName)) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{parVarDefinition.description.Get()}: double definition of variable {varName}" }); continue; } if (varName == DefVarName.IDHH || varName == DefVarName.IDPERSON || varName == DefVarName.DWT || varName == DefVarName.DCT) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{parVarDefinition.description.Get()}: variable {varName} is system-set and cannot be changed" }); continue; } addInstruction.prepVarDefinitions.Add(varName, parVarDefinition); } addInstructions.Add(addInstruction); } }