Exemple #1
0
        public Period XFI_Period(ValidationParameter a)
        {
            var fact = a.CurrentFacts.FirstOrDefault();
            var ct   = Instance.Contexts.Items[fact.ContextID];

            return(Instance.Contexts.Periods[ct.PeriodID]);
            //return null;
        }
Exemple #2
0
        public void testparameter()
        {
            var p = new ValidationParameter("p", "12");

            p.Type = TypeEnum.String;
            var s  = Utilities.Converters.ToJson(p);
            var px = Utilities.Converters.JsonTo <ValidationParameter>(s);
        }
Exemple #3
0
        public Entity XFI_Entity(ValidationParameter a)
        {
            var fact = a.CurrentFacts.FirstOrDefault();
            var ct   = Instance.Contexts.Items[fact.ContextID];

            return(Instance.Contexts.Entitites[ct.EntityID]);
            //return fact.Entity;
            //return null;
        }
        public static int GetFactCount(ValidationParameter p)
        {
            var c = 0;

            foreach (var facts in p.TaxFacts)
            {
                c += facts.Count;
            }
            return(c);
        }
Exemple #5
0
        public nString XFI_Fact_Explicit_Dimension_Value(ValidationParameter a, string qname)
        {
            var result = "";
            var fact   = a.CurrentFacts.FirstOrDefault();
            var dim    = fact.Dimensions.FirstOrDefault(i => i.DimensionItem == qname);

            if (dim != null)
            {
                result = dim.DomainAndMember;
            }
            return(new nString(result));
        }
Exemple #6
0
 public static bool In(this ValidationParameter obj, params String[] values)
 {
     foreach (var stringval in obj.StringValues)
     {
         var subresult = false;
         for (int i = 0; i < values.Length; i++)
         {
             if (String.Equals(stringval, values[i]))
             {
                 subresult = true;
                 break;
             }
         }
         if (!subresult)
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #7
0
 public decimal floor(ValidationParameter a)
 {
     return(Math.Floor(a.DecimalValue));
 }
Exemple #8
0
 public string Substring(ValidationParameter s, decimal startix, decimal count)
 {
     return(s.StringValue.Substring((int)startix, (int)count));
 }
Exemple #9
0
 public int StringLength(ValidationParameter s)
 {
     return(s.StringValue.Length);
 }
Exemple #10
0
 public int Month(ValidationParameter dt)
 {
     return(dt.DateValue.Month);
 }
Exemple #11
0
 public int Year(ValidationParameter dt)
 {
     return(dt.DateValue.Year);
 }
Exemple #12
0
 public ValueWithTreshold IAF_N_Divide(ValidationParameter a, ValidationParameter b)
 {
     return(IAF_N_Divide(a.ValueWithTreshold, b.ValueWithTreshold));;
 }
Exemple #13
0
 public int Day(ValidationParameter dt)
 {
     return(dt.DateValue.Day);
 }
Exemple #14
0
 public decimal abs(ValidationParameter a)
 {
     return(abs(a.DecimalValue));
 }
Exemple #15
0
 private decimal Invert(ValidationParameter a)
 {
     return(Invert(a.DecimalValue));
 }
Exemple #16
0
 public bool N_Less(ValidationParameter a, ValidationParameter b)
 {
     return(N_Less(a.DecimalValue, b.DecimalValue));
 }
Exemple #17
0
        public void SetFacts(LogicalModel.Validation.ValidationRule rule)
        {
            if (rule.ID.Contains("0147"))
            {
            }
            var         tables           = rule.Tables.Select(i => Taxonomy.Tables.FirstOrDefault(t => t.ID == i)).ToList();
            IList <int> tableintevallist = null;

            foreach (var table in tables)
            {
                tableintevallist = tableintevallist == null ? new IntervalList() : tableintevallist;
                tableintevallist = Utilities.Objects.MergeSorted(tableintevallist, table.FactindexList, null);
            }
            var         hastableinfo        = tableintevallist != null ? tableintevallist.Count > 0 : false;
            IList <int> allfactsintevallist = new IntervalList(0, Taxonomy.FactsManager.FactsOfPages.Count);

            if (hastableinfo)
            {
                allfactsintevallist = tableintevallist;
            }
            var ruletypeddimension = rule.BaseQuery.DictFilterIndexes.Where(i => Taxonomy.IsTyped(i));

            foreach (var parameter in rule.Parameters)
            {
                parameter.TaxFacts.Clear();
                IList <int> sdata = tableintevallist;
                if (!parameter.IsGeneral)
                {
                    if (parameter.BaseQuery.DictFilterIndexes.Count == 0)
                    {
                        sdata = allfactsintevallist;
                    }
                    parameter.Data            = parameter.BaseQuery.ToIntervalList(this.Taxonomy.FactsOfParts, sdata);
                    parameter.TypedDimensions = parameter.BaseQuery.DictFilterIndexes.Where(i => Taxonomy.IsTyped(i)).ToList();
                    parameter.TypedDimensions = parameter.TypedDimensions.Concat(ruletypeddimension).Distinct().ToList();
                    parameter.CoveredParts    = parameter.BaseQuery.GetAspects(this.Taxonomy);
                    if (parameter.FallBackValue == "()"
                        /*&& parameter.TypedDimensions.Count>0 */
                        && !parameter.BindAsSequence)
                    {
                        parameter.BindAsSequence = true;
                    }
                }
            }
            bool        hasfacts = false;
            var         ix       = 0;
            IList <int> data     = tableintevallist;

            if (rule.BaseQuery.DictFilterIndexes.Count == 0)
            {
                // && rule.BaseQuery.Pools.Count == 0
                //var interval = allfactsinteval;
                //var intervallist = new IntervalList();
                //intervallist.AddInterval(interval);
                data = allfactsintevallist;
            }
            rule.TypedDimensions = rule.BaseQuery.DictFilterIndexes.Where(i => Taxonomy.IsTyped(i)).ToList();
            rule.CoveredParts    = rule.BaseQuery.GetAspects(this.Taxonomy);
            var singlefactparameters = rule.Parameters.Where(i => !i.IsGeneral && !i.BindAsSequence).ToList();
            var multifactparameters  = rule.Parameters.Where(i => !i.IsGeneral && i.BindAsSequence).ToList();
            var mffnspissue          = false;

            LogicalModel.Validation.ValidationParameter p_mffnspissue = null;
            //Utilities.Logger.WriteToFile(String.Format("EnumerateIntervals {0} on {1}", rule.BaseQuery, data));

            foreach (var group in rule.BaseQuery.EnumerateIntervals(this.Taxonomy.FactsOfParts, 0, data, false))
            {
                //Utilities.Logger.WriteToFile("Joining rule with parameters...");

                foreach (var parameter in rule.Parameters)
                {
                    if (!parameter.IsGeneral)
                    {
                        var factsq = Utilities.Objects.IntersectSorted(parameter.Data, group, null);

                        //var facts = factsq.ToList();
                        var facts = factsq;

                        if (!parameter.BindAsSequence && facts.Count > 1)
                        {
                            mffnspissue   = true;
                            p_mffnspissue = parameter;
                        }
                        if (facts.Count > 0)
                        {
                            hasfacts = true;
                        }
                        parameter.AddTaxFacts(facts);
                    }
                }
                if (mffnspissue)
                {
                    var factcounts         = singlefactparameters.Select(i => new Utilities.KeyValue <int, LogicalModel.Validation.ValidationParameter>(i.TaxFacts.LastOrDefault().Count, i)).OrderByDescending(i => i.Key).ToList();
                    var distinctfactcounts = factcounts.Distinct().ToList();
                    if (singlefactparameters.Count == 1)
                    {
                        mffnspissue = false;
                        var p           = singlefactparameters.FirstOrDefault();
                        var lasttaxfact = p.TaxFacts.LastOrDefault();
                        p.TaxFacts.Remove(lasttaxfact);
                        foreach (var fact in lasttaxfact.AsEnumerable())
                        {
                            p.AddTaxFacts(new List <int>()
                            {
                                fact
                            });
                        }
                    }
                    if ((distinctfactcounts.Count == 2 && distinctfactcounts[1].Key == 1))
                    {
                        mffnspissue = false;
                        var theparameter         = factcounts[0].Value;
                        var parameterstocomplete = factcounts.Where(i => i.Key < factcounts[0].Key).Select(i => i.Value);

                        var facts = theparameter.TaxFacts.LastOrDefault();
                        theparameter.TaxFacts.Clear();
                        var run = 0;
                        foreach (var fact in facts.AsEnumerable())
                        {
                            theparameter.AddTaxFacts(new List <int>()
                            {
                                fact
                            });

                            foreach (var p in parameterstocomplete)
                            {
                                var firsttaxfact = p.TaxFacts.FirstOrDefault();
                                if (run > 0)
                                {
                                    p.TaxFacts.Add(firsttaxfact);
                                }
                            }
                            run++;
                        }
                    }
                    if (distinctfactcounts.Count == 1 /*&& multifactparameters.Count==0*/)
                    {
                        mffnspissue = false;
                        foreach (var p in singlefactparameters)
                        {
                            var lasttaxfact = p.TaxFacts.LastOrDefault();
                            p.TaxFacts.Remove(lasttaxfact);
                            foreach (var fact in lasttaxfact.AsEnumerable())
                            {
                                p.AddTaxFacts(new List <int>()
                                {
                                    fact
                                });
                            }
                        }
                    }
                }
                if (mffnspissue)
                {
                    Utilities.Logger.WriteLine(String.Format("{0}: Multiple facts found for Non Sequenced parameter {1}", rule.ID, p_mffnspissue.Name));
                }
                ix++;
                //Utilities.Logger.WriteToFile("End joining rule with parameters");
            }
            ValidationRuleHelper.SetParamerterTypes(Taxonomy, rule);
            if (!hasfacts)
            {
                Utilities.Logger.WriteLine(String.Format("{0}: Rule has no facts!", rule.ID));
            }
            var parameterswithissues = singlefactparameters.Where(i => i.TaxFacts.Any(f => f.Count > 1)).ToList();

            if (parameterswithissues.Count > 0)
            {
                Utilities.Logger.WriteLine(String.Format("{0}: Rule single factrule has multiple facts!", rule.ID));
            }
        }
Exemple #18
0
 public ValueWithTreshold IAF_abs(ValidationParameter a)
 {
     return(IAF_abs(a.ValueWithTreshold));
 }
Exemple #19
0
 public IValueWithTreshold IAF_N_Unary_Plus(ValidationParameter a)
 {
     return(IAF_N_Unary_Plus(a.ValueWithTreshold));
 }
Exemple #20
0
 public IValueWithTreshold IAF_N_Multiply(ValidationParameter a, ValidationParameter b)
 {
     return(IAF_N_Multiply(a.ValueWithTreshold, b.ValueWithTreshold));
 }
Exemple #21
0
 public bool IAF_N_GreaterEqual(ValidationParameter a, ValidationParameter b)
 {
     return(IAF_N_GreaterEqual(a.ValueWithTreshold, b.ValueWithTreshold));
 }
Exemple #22
0
 public bool empty(ValidationParameter a)
 {
     return(a.CurrentFacts.Count == 0);
 }
Exemple #23
0
        public LogicalModel.Validation.ValidationRule GetLogicalRule(Hierarchy <XbrlIdentifiable> hrule, XbrlTaxonomyDocument document)
        {
            this.Document = document;

            var tmp_rule = hrule.Copy();
            //FixRule(tmp_rule);
            var logicalrule    = new LogicalModel.Validation.ValidationRule();
            var valueassertion = tmp_rule.Item as ValueAssertion;

            logicalrule.ID = valueassertion.ID;
            //Utilities.Logger.WriteLine("Getting rule for " + logicalrule.ID);
            logicalrule.LabelID            = valueassertion.LabelID;
            logicalrule.OriginalExpression = valueassertion.Test.Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ");
            logicalrule.SetTaxonomy(this.Taxonomy);

            var sb = new StringBuilder();

            sb.AppendLine(logicalrule.DisplayText);
            sb.AppendLine(valueassertion.Test);
            var rawval = document.FileName + "\r\n" + document.LocalPath + "\r\n" + logicalrule.DisplayText + "\r\n" + logicalrule.OriginalExpression + "\r\n" + hrule.ToHierarchyString(i => i.ToString()) + "\r\n";

            logicalrule.RawInfo = rawval;
            Utilities.FS.AppendAllText(Taxonomy.TaxonomyValidationFolder + "Validations_XML.txt", rawval);

            if (logicalrule.ID.Contains("1058"))/*,"es_v354"*/
            {
            }

            var factvariables = tmp_rule.Where(i => i.Item is FactVariable);

            foreach (var fv in factvariables)
            {
                tmp_rule.Remove(fv);
            }


            logicalrule.BaseQuery = GetQuery(tmp_rule);

            logicalrule.BaseQuery.GetString(Taxonomy);

            foreach (var fv in factvariables)
            {
                var factvariable = fv.Item as FactVariable;
                var name         = factvariable.Name;
                var parameter    = new LogicalModel.Validation.ValidationParameter(name, logicalrule.ID);
                logicalrule.Parameters.Add(parameter);
                parameter.BindAsSequence = factvariable.BindAsSequence;
                parameter.FallBackValue  = factvariable.FallbackValue;


                parameter.BaseQuery = GetQuery(fv);
                parameter.Concept   = parameter.BaseQuery.GetConcept();
                if (String.IsNullOrEmpty(parameter.Concept))
                {
                    parameter.Concept = logicalrule.BaseQuery.GetConcept();
                }
                if (parameter.BaseQuery.HasDictFilter("find:filingIndicator"))
                {
                    parameter.IsGeneral   = true;
                    parameter.StringValue = "filingindicators";
                }
                ValidationRuleHelper.SetParamerterTypes(Taxonomy, logicalrule);
            }
            var factparameterqueries  = logicalrule.Parameters.Where(i => !i.IsGeneral).Select(i => i.BaseQuery).ToArray();
            var commconparameterquery = FactBaseQuery.GetCommonQuery(factparameterqueries);

            if (commconparameterquery != null && commconparameterquery.HasFilters())
            {
                FactBaseQuery.MergeQueries(logicalrule.BaseQuery, commconparameterquery);
                foreach (var pquery in factparameterqueries)
                {
                    FactBaseQuery.RemoveQuery(pquery, commconparameterquery);
                }
            }
            var sbquery = new StringBuilder();

            if (1 == 1)
            {
                sbquery.AppendLine("RuleQuery: ");
                sbquery.AppendLine(logicalrule.BaseQuery != null? logicalrule.BaseQuery.ToString():"");
                sbquery.AppendLine();
                foreach (var p in logicalrule.Parameters)
                {
                    sbquery.AppendLine(p + " Query: ");
                    if (p.BaseQuery != null)
                    {
                        sbquery.AppendLine(p.BaseQuery != null ? p.BaseQuery.ToString() : "");
                    }
                }
            }
            foreach (var gp in Taxonomy.ValidationParameters)
            {
                if (valueassertion.Test.Contains(gp.Value.XPathName))
                {
                    if (gp.Key == "ReportingLevel")
                    {
                        var p_rl1 = new LogicalModel.Validation.ValidationParameter("ReportingLevel", logicalrule.ID);
                        p_rl1.StringValue = this.Taxonomy.EntryDocument.FileName.Contains("_con") ? "con" : "ind";
                        p_rl1.Type        = LogicalModel.TypeEnum.String;
                        p_rl1.IsGeneral   = true;
                        logicalrule.Parameters.Add(p_rl1);
                        continue;
                    }
                    if (gp.Key == "AccountingStandard")
                    {
                        var p_rl2 = new LogicalModel.Validation.ValidationParameter("AccountingStandard", logicalrule.ID);
                        p_rl2.StringValue = this.Taxonomy.EntryDocument.FileName.Contains("GAAP") ? "GAAP" : "IFRS";
                        p_rl2.Type        = LogicalModel.TypeEnum.String;
                        p_rl2.IsGeneral   = true;
                        logicalrule.Parameters.Add(p_rl2);
                        continue;
                    }
                    var p_rl = new LogicalModel.Validation.ValidationParameter(gp.Key, logicalrule.ID);
                    p_rl.StringValue = "Unresolved";
                    p_rl.Type        = LogicalModel.TypeEnum.String;
                    p_rl.IsGeneral   = true;
                    logicalrule.Parameters.Add(p_rl);
                }
            }

            /*
             * if (valueassertion.Test.Contains("$ReportingLevel"))
             * {
             *  var p_rl1 = new LogicalModel.Validation.ValidationParameter("ReportingLevel", logicalrule.ID);
             *  p_rl1.StringValue = this.Taxonomy.EntryDocument.FileName.Contains("_con") ? "con" : "ind";
             *  p_rl1.Type = LogicalModel.TypeEnum.String;
             *  p_rl1.IsGeneral = true;
             *  logicalrule.Parameters.Add(p_rl1);
             * }
             * if (valueassertion.Test.Contains("$AccountingStandard"))
             * {
             *  var p_rl2 = new LogicalModel.Validation.ValidationParameter("AccountingStandard", logicalrule.ID);
             *  p_rl2.StringValue = this.Taxonomy.EntryDocument.FileName.Contains("GAAP") ? "GAAP" : "IFRS";
             *  p_rl2.Type = LogicalModel.TypeEnum.String;
             *  p_rl2.IsGeneral = true;
             *  logicalrule.Parameters.Add(p_rl2);
             * }
             */
            logicalrule.SetTaxonomy(this.Taxonomy);
            ValidationRuleHelper.ExecuteExplicitFiltering(this.Taxonomy, logicalrule);
            ValidationRuleHelper.ExecuteImplicitFiltering(this.Taxonomy, logicalrule);
            ValidationRuleHelper.ExecuteMatching(this.Taxonomy, logicalrule);
            ValidationRuleHelper.CheckConsistency(this.Taxonomy, logicalrule);

            //SetFacts(logicalrule);

            return(logicalrule);
        }
Exemple #24
0
 public ValueWithTreshold IAF_N_Subtract(ValidationParameter a, ValidationParameter b)
 {
     return(IAF_N_Subtract(a.ValueWithTreshold, b.ValueWithTreshold));;
 }
Exemple #25
0
        public string CheckCells(LogicalModel.Validation.ValidationParameter parameter)
        {
            var cellfound = false;
            var sb        = new StringBuilder();
            var sequence  = parameter.BindAsSequence ? "Sequence" : "";

            sb.AppendLine("parameter: " + parameter.Name + " " + sequence);
            var c_sb = new StringBuilder();
            var log  = false;

            foreach (var factgroup in parameter.TaxFacts)
            {
                foreach (var factid in factgroup.AsEnumerable())
                {
                    var cellslist = new List <List <String> >();
                    var factkey   = Taxonomy.FactsManager.GetFactKey(factid);
                    var fact      = FactBase.GetFactFrom(Taxonomy.GetFactStringKey(factkey));
                    if (Taxonomy.HasFact(factkey))
                    {
                        var cells = Taxonomy.GetCellsOfFact(factkey);
                        if (parameter.RuleID.Contains("0602"))
                        {
                            cellslist.Add(cells.Select(i => i + " {" + factkey + "} ").ToList());
                        }
                        else
                        {
                            cellslist.Add(cells);
                        }
                        if (cells.Count == 0)
                        {
                            if (log)
                            {
                                c_sb.AppendLine(parameter.RuleID + " fact found but no cells! " + factkey);
                            }
                        }
                    }
                    else
                    {
                        var s_facts = Taxonomy.FactKeysAsEnumerable().Select(i => i).AsEnumerable();
                        if (fact.Concept != null)
                        {
                            //s_facts = s_facts.Where(i => i.StartsWith(fact.Concept.Content));
                            //if (Taxonomy.FactsOfDimensions.ContainsKey(fact.Concept.Content))
                            var ix = Taxonomy.FactParts[fact.Concept.Content];
                            if (Taxonomy.FactsOfParts.ContainsKey(ix))
                            {
                                s_facts = Taxonomy.FactsOfParts[ix].Select(
                                    i => Taxonomy.FactsManager.GetFactKey(i));
                            }
                            else
                            {
                                s_facts = new List <int[]>();
                            }
                        }
                        foreach (var dimension in fact.Dimensions)
                        {
                            s_facts = s_facts.Where(i => Taxonomy.GetFactStringKey(i).Contains(dimension.DomainMemberFullName));
                        }
                        // var s_factlist = s_facts.ToList();
                        var hasanyfact = false;

                        foreach (var s_fact in s_facts)
                        {
                            hasanyfact = true;
                            var cells = Taxonomy.GetCellsOfFact(s_fact);
                            if (cells.Count == 0)
                            {
                                if (log)
                                {
                                    c_sb.AppendLine(parameter.RuleID + " for parameter " + parameter.Name + " no cells were found! " + s_fact);
                                }
                            }
                            if (parameter.RuleID.Contains("0602"))
                            {
                                cellslist.Add(cells.Select(i => i + " {" + factkey + "} ").ToList());
                            }
                            else
                            {
                                cellslist.Add(cells);
                            }
                        }

                        if (!hasanyfact)
                        {
                            if (log)
                            {
                                c_sb.AppendLine(parameter.RuleID + " fact for parameter " + parameter.Name + " not found! " + factkey);
                            }
                        }
                    }
                    if (cellslist.Count == 0)
                    {
                    }
                    else
                    {
                        cellfound = true;
                    }
                    //sb.AppendLine(fact.GetFactKey());
                    foreach (var cells in cellslist)
                    {
                        foreach (var cell in cells)
                        {
                            sb.Append(cell + ", ");
                        }
                        sb.AppendLine();
                    }
                }
            }
            if (!cellfound)
            {
                if (log)
                {
                    c_sb.AppendLine("None of the Fact Groups can be found for " + parameter.RuleID + " - " + parameter.Name);
                }
            }
            if (c_sb.Length > 0)
            {
                Logger.WriteLine(c_sb.ToString());
            }
            return(sb.ToString());
        }
Exemple #26
0
 public bool IAF_N_Less(ValidationParameter a, ValidationParameter b)
 {
     return(IAF_N_Less(a.ValueWithTreshold, b.ValueWithTreshold));
 }
Exemple #27
0
 public int Count(ValidationParameter a)
 {
     return(a.CurrentFacts.Count);
 }
Exemple #28
0
 public string String(ValidationParameter a)
 {
     return(a.StringValue);
 }
Exemple #29
0
 public DateTime XS_Date(ValidationParameter a)
 {
     return(a.DateValue);
 }
Exemple #30
0
 public bool not(ValidationParameter a)
 {
     return(not(a.BooleanValue));
 }