static internal void ReplaceCountrySymbol(CountryConfig.PolicyRow policyRow, string countryShortName)
 {
     policyRow.Name = ReplaceCountrySymbol(policyRow.Name, countryShortName);
     foreach (CountryConfig.FunctionRow functionRow in policyRow.GetFunctionRows())
     {
         ReplaceCountrySymbol(functionRow, countryShortName);
     }
 }
Esempio n. 2
0
        void FillPolicyNodeWithFunctions(CountryConfig.SystemRow systemRow, CountryConfig.PolicyRow policyRow, TreeListNode policyNode, bool isFirstSystem)
        {
            //generate the functions of the policy
            int functionIndex = 0;
            var functionQuery = (from function in policyRow.GetFunctionRows() select function).OrderBy(function => long.Parse(function.Order));

            foreach (CountryConfig.FunctionRow functionRow in functionQuery.ToList <CountryConfig.FunctionRow>())
            {
                TreeListNode functionNode = isFirstSystem ? BuildFunctionNode(policyNode, functionRow) : policyNode.Nodes[functionIndex++];
                (functionNode.Tag as FunctionTreeListTag).AddFunctionRowOfSystem(systemRow.ID, functionRow);
                functionNode.SetValue(systemRow.Name, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(functionRow));

                //generate the parameters of the function
                FillFunctionNodeWithParameters(systemRow, functionRow, functionNode, isFirstSystem);
            }
        }
        static CountryConfig.FunctionRow GetFunctionRowByPolicyNameAndDisplayOrder(CountryConfigFacade countryConfigFacade,
                                                                                   string systemID, string policyName, string displayOrder)
        {
            try
            {
                CountryConfig.PolicyRow policyRow = countryConfigFacade.GetPolicyRowByFullName(systemID, policyName);
                int displayIndex = Convert.ToInt32(displayOrder) - 1;

                CountryConfig.FunctionRow func = null;
                if (policyRow != null && displayIndex >= 0)
                {
                    List <CountryConfig.FunctionRow> siblingFunctions = policyRow.GetFunctionRows().OrderBy(f => long.Parse(f.Order)).ToList();
                    if (displayIndex < siblingFunctions.Count)
                    {
                        func = siblingFunctions.ElementAt(displayIndex);
                    }
                }
                return(func);
            }
            catch { return(null); }
        }
Esempio n. 4
0
        private void EM2_FixUprating(CountryConfig.SystemRow sr1, Dictionary <string, string> upratingFactors, Dictionary <string, string> upratingFactors2, string countryShortName, double alpha, int uprateType, bool treatAsMarket)
        {
            // first get the ils_origy & ils_ben components
            CountryConfig.PolicyRow ilsdef = sr1.GetPolicyRows().FirstOrDefault(p => p.Name.ToLower() == ("ilsdef_" + countryShortName).ToLower());
            if (ilsdef == null)
            {
                ilsdef = sr1.GetPolicyRows().FirstOrDefault(p => p.Name.ToLower() == ("ildef_" + countryShortName).ToLower());
            }
            if (ilsdef == null)
            {
                return;
            }

            CountryConfig.FunctionRow[] il_funcs = ilsdef.GetFunctionRows();
            List <string> ils_origy       = ExpandIncomeList(DefVarName.ILSORIGY, il_funcs).Keys.ToList();
            List <string> ils_ben         = ExpandIncomeList(DefVarName.ILSBEN, il_funcs).Keys.ToList();
            List <string> overrideInclude = ExpandIncomeList("pet_override", il_funcs).Where(x => x.Value).Select(x => x.Key).ToList();
            List <string> overrideExclude = ExpandIncomeList("pet_override", il_funcs).Where(x => !x.Value).Select(x => x.Key).ToList();

            List <string> reservedWords = new List <string> {
                "dataset", "def_factor", "factor_name", "factor_value", "factor_condition", "aggvar_name", "aggvar_part", "aggvar_tolerance", "warnifnofactor", "run_cond"
            };

            // Then apply them to the appropriate variables of s1
            foreach (CountryConfig.FunctionRow fr in sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("Uprate_" + countryShortName).ToLower()).GetFunctionRows())
            {
                if (fr.Name.ToLower() == "uprate")
                {
                    foreach (CountryConfig.ParameterRow pr in fr.GetParameterRows())
                    {
                        string pn = pr.Name.ToLower();

                        if (!reservedWords.Contains(pn))
                        {
                            if (uprateType == 3)    // uprate all
                            {
                                double val;
                                if (upratingFactors.ContainsKey(pr.Value.ToLower()))
                                {
                                    pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors2[pr.Value.ToLower()]) * alpha).ToString());
                                }
                                else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val))
                                {
                                    pr.Value = FixDecSep((val * alpha).ToString());
                                }
                            }
                            else
                            {
                                bool marketIncome = overrideInclude.Contains(pn);   // if in the override include list
                                if (!overrideExclude.Contains(pn) && !marketIncome) // else if not in the override exlcude list
                                {
                                    VarConfig.VariableRow v = EM_AppContext.Instance.GetVarConfigFacade().GetVariableByName(pn);
                                    if (v == null || v.Monetary != "1")
                                    {
                                        marketIncome = false;
                                    }
                                    else
                                    {
                                        if (treatAsMarket)
                                        {
                                            marketIncome = !pn.EndsWith(DefGeneral.POSTFIX_SIMULATED);
                                        }
                                        else
                                        {
                                            marketIncome = !ils_ben.Contains(pn) && (pn[0] == 'y' || pn[0] == 'a' || pn[0] == 'x' || ils_origy.Contains(pn));
                                        }
                                    }
                                }

                                // if this is a market income
                                if (marketIncome)
                                {
                                    if (uprateType == 1)
                                    {
                                        double val;
                                        if (upratingFactors.ContainsKey(pr.Value.ToLower()))
                                        {
                                            pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors[pr.Value.ToLower()]) * alpha).ToString());
                                        }
                                        else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val))
                                        {
                                            pr.Value = FixDecSep((val * alpha).ToString());
                                        }
                                    }
                                    else if (uprateType == 2)
                                    {
                                        if (upratingFactors.ContainsKey(pr.Value.ToLower()))
                                        {
                                            pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors[pr.Value.ToLower()])).ToString());
                                        }
                                    }
                                }
                                else    // if it is non-market income
                                {
                                    if (uprateType == 2)
                                    {
                                        double val;
                                        if (upratingFactors2.ContainsKey(pr.Value.ToLower()))
                                        {
                                            pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors2[pr.Value.ToLower()]) / alpha).ToString());
                                        }
                                        else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val))
                                        {
                                            pr.Value = FixDecSep((val / alpha).ToString());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (uprateType > 1)
            {
                string[] monetaryTypes = new string[] { DefPeriod.M, DefPeriod.Y, DefPeriod.Q, DefPeriod.W,
                                                        DefPeriod.D, DefPeriod.L, DefPeriod.S, DefPeriod.C };
                foreach (CountryConfig.FunctionRow fr in sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("Uprate_" + countryShortName).ToLower()).GetFunctionRows())
                {
                    foreach (CountryConfig.ParameterRow pr in fr.GetParameterRows())
                    {
                        string val = pr.Value.ToLower().Trim();
                        if (val.Length < 3)
                        {
                            continue;
                        }
                        string valType = val.Substring(val.Length - 2);

                        if (monetaryTypes.Contains(valType))
                        {
                            val = val.Substring(0, val.Length - 2);
                            if (uprateType == 2)
                            {
                                pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(val) / alpha).ToString()) + valType;
                            }
                            else if (uprateType == 3)
                            {
                                pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(val) * alpha).ToString()) + valType;
                            }
                        }
                    }
                }
            }
            try
            {
                // Then, fix the output filenames
                sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_" + countryShortName).ToLower())
                .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput")
                .GetParameterRows().First(p => p.Name.ToLower() == "file")
                .Value = sr1.Name + "_std";
                sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_hh_" + countryShortName).ToLower())
                .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput")
                .GetParameterRows().First(p => p.Name.ToLower() == "file")
                .Value = sr1.Name + "_std_hh";
                // Finally, if required, do the scaling
                if (checkRadioMarket.Checked)
                {
                    CountryConfig.FunctionRow fr = sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_" + countryShortName).ToLower())
                                                   .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput");
                    CountryConfig.FunctionRow fr_hh = sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_hh_" + countryShortName).ToLower())
                                                      .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput");

                    if (fr.GetParameterRows().Count(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower()) == 0)
                    {
                        CountryConfig.ParameterRow fpr = fr.GetParameterRows().First(p => p.Name.ToLower() == "file");
                        CountryConfig.ParameterRow cpr = CountryConfigFacade.AddParameterRow(fpr, false,
                                                                                             DefPar.DefOutput.MultiplyMonetaryBy, DefinitionAdmin.GetParDefinition(DefFun.DefOutput, DefPar.DefOutput.MultiplyMonetaryBy));
                        cpr.Value = FixDecSep((1 / alpha).ToString());
                    }
                    else
                    {
                        CountryConfig.ParameterRow mpr = fr.GetParameterRows().First(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower());
                        double d;
                        if (!EM_Helpers.TryConvertToDouble(mpr.Value, out d))
                        {
                            d = 1;
                        }
                        mpr.Value = FixDecSep((d / alpha).ToString());
                    }

                    if (fr_hh.GetParameterRows().Count(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower()) == 0)
                    {
                        CountryConfig.ParameterRow fpr_hh = fr_hh.GetParameterRows().First(p => p.Name.ToLower() == "file");
                        CountryConfig.ParameterRow cpr    = CountryConfigFacade.AddParameterRow(fpr_hh, false,
                                                                                                DefPar.DefOutput.MultiplyMonetaryBy, DefinitionAdmin.GetParDefinition(DefFun.DefOutput, DefPar.DefOutput.MultiplyMonetaryBy));
                        cpr.Value = FixDecSep((1 / alpha).ToString());
                    }
                    else
                    {
                        CountryConfig.ParameterRow mpr_hh = fr_hh.GetParameterRows().First(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower());
                        double d;
                        if (!EM_Helpers.TryConvertToDouble(mpr_hh.Value, out d))
                        {
                            d = 1;
                        }
                        mpr_hh.Value = FixDecSep((d / alpha).ToString());
                    }
                }
            }
            catch
            {
                throw new Exception("Problem in default output functions.");
            }
        }