Example #1
0
        protected override void PrepareNonCommonPar()
        {
            ParBase parFileName = GetUniquePar <ParBase>(DefPar.DefOutput.File);

            if (parFileName != null) // if null the programme is stopped after reading parameters (missing compulsory parameter)
            {
                fileName = Path.Combine(infoStore.runConfig.pathOutput, parFileName.xmlValue);
                if (!fileName.ToLower().EndsWith(".txt"))
                {
                    fileName += ".txt";
                }

                if (infoStore.runConfig.stdOutputFilenameSuffix != string.Empty) // e.g. uk_2017_std -> uk_2017_BTAoff
                {
                    AdaptFileNameForNonStdExtensionSwitches(infoStore.runConfig.stdOutputFilenameSuffix);
                }

                if (infoStore.runConfig.outFileDate != string.Empty) // e.g. hu_2017_std.txt -> hu_2017_std_201805301954.txt
                {
                    fileName = fileName.Insert(fileName.Length - 4, "_" + infoStore.runConfig.outFileDate);
                }

                // * * *   T O D O   * * *
                // check at this point if file is ready for writting, i.e. valid file-name, not used by another file, ...
                // to avoid running the whole thing and then cannot write (probably requires try-catch on attempt to open)
                // also if the file is available, lock it now?
            }

            // in future probably replaced by Scale function, but currently still needed, in particular for PET
            ParFormula parMultipleMonetaryBy = GetUniquePar <ParFormula>(DefPar.DefOutput.MultiplyMonetaryBy);

            if (parMultipleMonetaryBy != null)
            {
                multiplyMonetaryBy = parMultipleMonetaryBy.GetGlobalValue();
            }

            PrepareVarILPar();
            PrepareDefILPar();
            PrepareUnitInfoPar();
            append = GetParBoolValueOrDefault(DefFun.DefOutput, DefPar.DefOutput.Append);
            suppressVoidMessage = GetParBoolValueOrDefault(DefFun.DefOutput, DefPar.DefOutput.Suppress_Void_Message);

            nDecimals      = (int)GetParNumberValueOrDefault(DefFun.DefOutput, DefPar.DefOutput.nDecimals);
            formatDecimals = "0."; for (int i = 0; i < nDecimals; i++)
            {
                formatDecimals += "#";
            }

            parWho     = GetUniquePar <ParCateg>(DefPar.Common.Who_Must_Be_Elig);
            parEligVar = GetUniquePar <ParVar>(DefPar.Common.Elig_Var);

            ParNumber parReplaceUnitLoopVoidBy = GetUniquePar <ParNumber>(DefPar.DefOutput.Replace_Void_By);

            if (parReplaceUnitLoopVoidBy != null)
            {
                doReplaceUnitLoopVoidBy = true;
                replaceUnitLoopVoidBy   = parReplaceUnitLoopVoidBy.GetValue();
            }
        }
Example #2
0
 /// <summary> used for assessing global conditions, e.g. RunCond, Loop.BreakCond </summary>
 internal bool GetGlobalValue()
 {
     if (infoStore.hhAdmin == null && !IsGlobal(true))
     {
         return(true); // note: this allows calling the function at read-time
     }
     // which is ok with things like {IsUsedDatabase#1}, {GetSystemYear=2016}, {1}, etc. (IsGlobal(true) == true)
     // but does not work with global variables, which may change over run-time (IsGlobal(true) == false)
     // as the function returns true for the latter at read-time it must be called again at run-time (see e.g. FunDefVar)
     return(parFormula.GetGlobalValue() != 0);
 }
Example #3
0
        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;
                    }
                }
            }
        }
Example #5
0
        /// <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()
        {
            if (GetParGroups(DefPar.SchedCalc.Band_XXX).Count < 1)
            {
                infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                {
                    isWarning = false, message = $"{description.Get()}: SchedCalc must have at least one band"
                });
                return;
            }
            foreach (KeyValuePair <int, List <ParBase> > bandParList in GetParGroups(DefPar.SchedCalc.Band_XXX))
            {
                Band band = new Band();
                // Prepare the Band Limits
                band.band    = bandParList.Key;
                band.pLowLim = GetUniqueGroupPar <ParFormula>(DefPar.SchedCalc.Band_LowLim, bandParList.Value);
                if (band.pLowLim != null)   // if there is a lowLim
                {
                    if (band.pLowLim.IsGlobal(true))
                    {
                        band.lowLim = band.pLowLim.GetGlobalValue(); band.pLowLim = null;
                    }
                    else
                    {
                        doRunTimeLimCheck = true;
                    }
                }
                band.pUpLim = GetUniqueGroupPar <ParFormula>(DefPar.SchedCalc.Band_UpLim, bandParList.Value);
                if (band.pUpLim != null)   // if there is a lowLim
                {
                    if (band.pUpLim.IsGlobal(true))
                    {
                        band.upLim = band.pUpLim.GetGlobalValue(); band.pUpLim = null;
                    }
                    else
                    {
                        doRunTimeLimCheck = true;
                    }
                }
                // Prepare the Band Rate/Amount
                band.pRate   = GetUniqueGroupPar <ParFormula>(DefPar.SchedCalc.Band_Rate, bandParList.Value);
                band.pAmount = GetUniqueGroupPar <ParFormula>(DefPar.SchedCalc.Band_Amount, bandParList.Value);
                if (band.pRate != null && band.pAmount != null) // Rate and Amount cannot co-exist
                {
                    infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                    {
                        isWarning = false, message = $"{description.Get()}: Rate and Amount cannot co-exist in group {band.band}"
                    });
                }
                if (band.pRate == null && band.pAmount == null) // Rate and Amount cannot both be missing
                {
                    infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                    {
                        isWarning = false, message = $"{description.Get()}: Rate and Amount cannot both be missing in group {band.band}"
                    });
                }
                if (band.pRate != null)
                {
                    if (band.pRate.IsGlobal(true))
                    {
                        band.rate = band.pRate.GetGlobalValue(); band.pRate = null;
                    }
                    else
                    {
                        doRunTimeRateCheck = true;
                    }
                }
                if (band.pAmount != null)
                {
                    if (band.pAmount.IsGlobal(true))
                    {
                        band.amount = band.pAmount.GetGlobalValue(); band.pAmount = null;
                    }
                    else
                    {
                        doRunTimeRateCheck = true;
                    }
                }
                bands.Add(band);
            }

            // check that all required limits exist
            for (int i = 1; i < bands.Count; i++)
            {
                // if both limits are missing then produce an error
                if (bands[i - 1].upLim == double.MaxValue && bands[i - 1].pUpLim == null && bands[i].lowLim == double.MinValue && bands[i].pLowLim == null)
                {
                    infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                    {
                        isWarning = false, message = $"{description.Get()}: Band {bands[i - 1].band}: insufficient definition of upper limit. Use parameters 'band_uplim' or 'band_lowlim'(+1)."
                    });
                }
                // if both limits are there, then produce an error
                else if ((bands[i - 1].upLim != double.MaxValue || bands[i - 1].pUpLim != null) && (bands[i].lowLim != double.MinValue || bands[i].pLowLim != null))
                {
                    infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                    {
                        isWarning = false, message = $"{description.Get()}: Double definition of upper limit as 'Band_UpLim {bands[i - 1].band}' and 'Band_LowLim {bands[i].band}'."
                    });
                }
                // else, make sure that the upper limit always exist (copy from Group+1 lower limit if required)
                else if (bands[i - 1].upLim == double.MaxValue && bands[i - 1].pUpLim == null)
                {
                    if (bands[i].pLowLim == null)
                    {
                        bands[i - 1].upLim = bands[i].lowLim;                           // copy the litteral limit if it exists
                    }
                    else
                    {
                        bands[i - 1].pUpLim = bands[i].pLowLim;                         // else copy the parameter to be run at run-time
                    }
                }
            }

            // if possible, check that limits are also in order
            if (!doRunTimeLimCheck)
            {
                CheckGroupLimits(bands);
            }

            // prepare the other parameters
            basePar = GetUniquePar <ParFormula>(DefPar.SchedCalc.Base);
            if (basePar == null)
            {
                infoStore.communicator.ReportError(new Communicator.ErrorInfo()
                {
                    isWarning = false, message = $"{description.Get()}: Missing required parameter Base"
                });
            }

            ParBool doAverageRatesPar = GetUniquePar <ParBool>(DefPar.SchedCalc.Do_Average_Rates);

            doAverageRates = doAverageRatesPar != null && doAverageRatesPar.GetBoolValue();
            ParBool simpleProgPar = GetUniquePar <ParBool>(DefPar.SchedCalc.Simple_Prog);

            simpleProg = simpleProgPar != null && simpleProgPar.GetBoolValue();

            quotientPar = GetUniquePar <ParFormula>(DefPar.SchedCalc.Quotient);
            if (quotientPar != null)
            {
                if (quotientPar.IsGlobal(true))
                {
                    quotient = quotientPar.GetGlobalValue(); quotientPar = null;
                }
            }

            baseThresholdPar = GetUniquePar <ParFormula>(DefPar.SchedCalc.BaseThreshold);
            if (baseThresholdPar != null)
            {
                if (baseThresholdPar.IsGlobal(true))
                {
                    baseThreshold = baseThresholdPar.GetGlobalValue(); baseThresholdPar = null;
                }
            }

            ParNumber roundBasePar = GetUniquePar <ParNumber>(DefPar.SchedCalc.Round_Base);

            if (roundBasePar != null)
            {
                roundBase = roundBasePar.GetValue();
            }
        }