Esempio n. 1
0
        public static FactsPartsDictionary GetFactsOfParts(Taxonomy taxonomy)
        {
            var instance = new FactsPartsDictionary();

            instance.DeSerializeItems = (lines) => {
                var values = new IntervalList();
                foreach (var line in lines)
                {
                    values.AddInterval(Interval.GetInstanceFromString(line));
                }
                values.TrimExcess();

                return(values);
            };
            instance.SerializeItem = (itemcontainer) =>
            {
                var sb = new StringBuilder();
                foreach (var item in itemcontainer.Intervals)
                {
                    sb.AppendLine(item.Content());
                }
                return(sb);
            };
            instance.Folder            = () => taxonomy.TaxonomyFactsFolder;
            instance.FileSearchPattern = "FactsOfParts_*.dat";
            instance.GetKey            = (file) =>
            {
                return(Utilities.Converters.FastParse(Utilities.Strings.TextBetween(file, "FactsOfParts_", ".dat")));
            };

            return(instance);
        }
      // Destructively merge two IntervalLists.
      // Invariant: None of the Intervals in the two lists may overlap
      // intervals in this list.
      public static IntervalList Merge(IntervalList x, IntervalList y)
      {
        if(x == null) return y;
        if(y == null) return x;

        if(x.End > y.Start) return Merge(y, x);

        Debug.Assert(x.End != y.Start);

        // We now have x, y non-null and x.End < y.Start.

        if(y.Start == x.End + 1)
        {
          // The two intervals adjoin. Merge them into one and then
          // merge the tails.
          x.End = y.End;
          x.Next = Merge(x.Next, y.Next);
          return x;
        }

        // y belongs in the tail of x.

        x.Next = Merge(y, x.Next);
        return x;
      }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ucs"></param>
        /// <param name="table"></param>
        /// <param name="max"></param>
        /// <returns></returns>
        /// <remarks>
        /// Original comment:
        /// /* auxiliary function for binary search in interval table */
        /// </remarks>
        private static bool BinarySearch(char ucs, IntervalList table)
        {
            int min = 0;
            int max = table.Count - 1;
            int mid;

            if (ucs < table[0].first || ucs > table[max].last)
            {
                return(false);
            }

            while (max >= min)
            {
                mid = (min + max) / 2;
                if (ucs > table[mid].last)
                {
                    min = mid + 1;
                }
                else if (ucs < table[mid].first)
                {
                    max = mid - 1;
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
            // Destructively merge two IntervalLists.
            // Invariant: None of the Intervals in the two lists may overlap
            // intervals in this list.
            public static IntervalList Merge(IntervalList x, IntervalList y)
            {
                if (x == null)
                {
                    return(y);
                }
                if (y == null)
                {
                    return(x);
                }

                if (x.End > y.Start)
                {
                    return(Merge(y, x));
                }

                Debug.Assert(x.End != y.Start);

                // We now have x, y non-null and x.End < y.Start.

                if (y.Start == x.End + 1)
                {
                    // The two intervals adjoin. Merge them into one and then
                    // merge the tails.
                    x.End  = y.End;
                    x.Next = Merge(x.Next, y.Next);
                    return(x);
                }

                // y belongs in the tail of x.

                x.Next = Merge(y, x.Next);
                return(x);
            }
 private void CheckNonEmpty()
 {
     if (!IntervalList.Any())
     {
         throw new InvalidCastException($"cannot initialize a non-empty interval set with an empty interval set");
     }
 }
Esempio n. 6
0
        public IList <int> ToIntervalList(FactsPartsDictionary FactsOfParts, IList <int> facts, bool ensurepartnr = false)
        {
            //cover here
            var items = FactsOfParts.SearchFactsIndexByKey(DictFilterIndexes.ToArray(), facts);

            foreach (var negativeindex in NegativeDictFilterIndexes)
            {
                if (FactsOfParts.ContainsKey(negativeindex))
                {
                    items = Utilities.Objects.SortedExcept(items, FactsOfParts[negativeindex]);
                }
            }
            if (ChildQueries.Count > 0)
            {
                var result = new IntervalList();

                foreach (var childquery in ChildQueries)
                {
                    result.AddRange(childquery.ToIntervalList(FactsOfParts, items));
                }
                return(result);
            }

            return(items);
        }
Esempio n. 7
0
            public static IntervalList FromArray(int[] xs, int length)
            {
                Array.Sort(xs, 0, length);

                IntervalList result  = null;
                IntervalList current = null;

                int i = 0;

                while (i < length)
                {
                    int start = i;
                    while ((i < length - 1) && (xs[i + 1] == xs[i] + 1))
                    {
                        i++;
                    }

                    IntervalList interval = new IntervalList(xs[start], xs[i]);

                    if (result == null)
                    {
                        result  = interval;
                        current = interval;
                    }
                    else
                    {
                        current.Next = interval;
                        current      = interval;
                    }
                    i++;
                }
                return(result);
            }
        /**
         * Creates an IntAllocator allocating integer IDs within the inclusive range [start, end]
         */
        public IntAllocator(int start, int end)
        {
            if(start > end) throw new ArgumentException("illegal range [" + start  +", " + end + "]");

              // Fairly arbitrary heuristic for a good size for the unsorted set.
              unsorted = new int[Math.Max(32, (int)Math.Sqrt(end - start))];
              Base = new IntervalList(start, end);
        }
Esempio n. 9
0
 private void Flush()
 {
     if (_unsortedCount > 0)
     {
         _base          = IntervalList.Merge(_base, IntervalList.FromArray(_unsorted, _unsortedCount));
         _unsortedCount = 0;
     }
 }
Esempio n. 10
0
 private void Flush()
 {
     if (unsortedCount > 0)
     {
         Base          = IntervalList.Merge(Base, IntervalList.FromArray(unsorted, unsortedCount));
         unsortedCount = 0;
     }
 }
Esempio n. 11
0
        /**
         * Creates an IntAllocator allocating integer IDs within the inclusive range [start, end]
         */
        public IntAllocator(int start, int end)
        {
            if (start > end)
            {
                throw new ArgumentException("illegal range [" + start + ", " + end + "]");
            }

            // Fairly arbitrary heuristic for a good size for the unsorted set.
            unsorted = new int[Math.Max(32, (int)Math.Sqrt(end - start))];
            Base     = new IntervalList(start, end);
        }
        protected override void Initialize()
        {
            base.Initialize();

            TypeSelectorItems.Insert(0, new ProductType {
                Name = "Не обрано", Id = -1
            });

            IntervalList = AggregationInterval.GetList();

            SelectedInterval = IntervalList.FirstOrDefault();

            ProductType = TypeSelectorItems.FirstOrDefault();
        }
Esempio n. 13
0
 private void SetIntervalValue(Scheduler scheduler)
 {
     try
     {
         if (scheduler != null)
         {
             SelectedIntervsl = IntervalList.IndexOf(scheduler.interval.ToString()).ToString();
         }
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
     }
 }
Esempio n. 14
0
        public void ShouldWorkWithNullValues()
        {
            List <TodoItem> items = new List <TodoItem>();

            IntervalList il = new IntervalList(7, items);

            WeekList wl = new WeekList(il.List);

            Assert.True(wl.List.Count == 0);

            wl = new WeekList(null);

            Assert.True(il.List.Count == 0);
        }
Esempio n. 15
0
        public void AddTaxFacts(IList <int> list)
        {
            IntervalList intervals = list as IntervalList;

            if (intervals == null)
            {
                intervals = new IntervalList();
                foreach (var item in list)
                {
                    intervals.Add(item);
                }
            }
            //this.TaxFacts.Add(intervals);
            this.TaxFacts.Add((List <int>)list);
        }
        public void ShouldWorkWithNullValues()
        {
            List <TodoItem> items = new List <TodoItem>();

            IntervalList il = new IntervalList(7, items);

            Assert.True(il.List.Count == 0);

            il = new IntervalList(7, null);

            Assert.True(il.List.Count == 0);

            il = new IntervalList(-500, null);

            Assert.True(il.List.Count == 0);
        }
        public void ShouldWorkWithNullValues()
        {
            List <TodoItem> items = new List <TodoItem>();

            IntervalList          il   = new IntervalList(7, items);
            WeekList              wl   = new WeekList(il.List);
            AverageLineSeriesList alsl = new AverageLineSeriesList(5, wl.List);

            Assert.True(alsl.List.Count == 0);

            alsl = new AverageLineSeriesList(5, null);

            Assert.True(alsl.List.Count == 0);

            alsl = new AverageLineSeriesList(-500, null);

            Assert.True(alsl.List.Count == 0);
        }
Esempio n. 18
0
 public void Exclude1Test()
 {
     var intervalList = new IntervalList<int>
         {
             new Interval<int>(1, 10),
             new Interval<int>(1, 10),
             new Interval<int>(5, 7),
             new Interval<int>(4, 10),
             new Interval<int>(0, 12),
             new Interval<int>(15, 40),
             new Interval<int>(30, 42),
             new Interval<int>(1, 13),
             new Interval<int>(40, 45),
         };
     intervalList.Exclude(new Interval<int>(0, 40));
     Assert.AreEqual(1, intervalList.Count);
     Assert.IsTrue(intervalList[0].Equals(new Interval<int>(40, 45)));
 }
Esempio n. 19
0
        public bool Reserve(int id)
        {
            // We always flush before reserving because the only way to determine
            // if an ID is in the unsorted array is through a linear scan. This leads
            // us to the potentially expensive situation where there is a large unsorted
            // array and we reserve several IDs, incurring the cost of the scan each time.
            // Flushing makes sure the array is always empty and does no additional work if
            // reserve is called twice.
            Flush();

            IntervalList current = Base;

            while (current != null)
            {
                if (current.End < id)
                {
                    current = current.Next;
                    continue;
                }
                else if (current.Start > id)
                {
                    return(false);
                }
                else if (current.End == id)
                {
                    current.End--;
                }
                else if (current.Start == id)
                {
                    current.Start++;
                }
                else
                {
                    // The ID is in the middle of this interval.
                    // We need to split the interval into two.
                    IntervalList rest = new IntervalList(id + 1, current.End);
                    current.End  = id - 1;
                    rest.Next    = current.Next;
                    current.Next = rest;
                }
                return(true);
            }
            return(false);
        }
Esempio n. 20
0
 public void NormalizeTest()
 {
     var intervalList = new IntervalList<int>
         {
             new Interval<int>(1, 10),
             new Interval<int>(1, 10),
             new Interval<int>(5, 7),
             new Interval<int>(4, 10),
             new Interval<int>(0, 12),
             new Interval<int>(15, 40),
             new Interval<int>(30, 42),
             new Interval<int>(1, 13),
             new Interval<int>(40, 45),
         };
     intervalList.Normalize();
     Assert.AreEqual(2, intervalList.Count);
     Assert.IsTrue(intervalList[0].Equals(new Interval<int>(0, 13)));
     Assert.IsTrue(intervalList[1].Equals(new Interval<int>(15, 45)));
 }
Esempio n. 21
0
 /**
  * Allocate a fresh integer from the range, or return -1 if no more integers
  * are available. This operation is guaranteed to run in O(1)
  */
 public int Allocate()
 {
     if (unsortedCount > 0)
     {
         return(unsorted[--unsortedCount]);
     }
     else if (Base != null)
     {
         int result = Base.Start++;
         if (Base.Start == Base.End)
         {
             Base = Base.Next;
         }
         return(result);
     }
     else
     {
         return(-1);
     }
 }
Esempio n. 22
0
        /// <inheritdoc />
        public OpenPeriodSet(DateTime from, DateTime?to)
        {
            Start <DateTime> start = new Start <DateTime>(from, Inclusivity.Inclusive);

            if (to.HasValue)
            {
                if (to.Value == from)
                {
                    IntervalList.Add(new DegenerateOpenPeriod(new Degenerate <DateTime>(from)));
                }
                else
                {
                    IntervalList.Add(new StartEndingOpenPeriod(start, new End <DateTime>(to.Value, Inclusivity.Exclusive)));
                }
            }
            else
            {
                IntervalList.Add(new StartingOpenPeriod(start));
            }
        }
Esempio n. 23
0
        /// <inheritdoc />
        public BoundedPeriodSet(DateTime from, DateTime?to = null)
        {
            Start <DateTime> start = new Start <DateTime>(from, Inclusivity.Inclusive);

            if (to.HasValue)
            {
                if (to.Value == from)
                {
                    IntervalList.Add(new DefaultDegenerateInterval <DateTime>(new Degenerate <DateTime>(from)));
                }
                else
                {
                    IntervalList.Add(new DefaultStartEndingInterval <DateTime>(start, new End <DateTime>(to.Value, Inclusivity.Exclusive)));
                }
            }
            else
            {
                IntervalList.Add(new DefaultStartingInterval <DateTime>(start));
            }
        }
        public void Setup()
        {
            List <TodoItem> items = new List <TodoItem>(
                new TodoItem[] {
                new TodoItem(90, 4000, new DateTime(2019, 1, 1)),
                new TodoItem(91, 4000, new DateTime(2019, 1, 2)),
                // week
                new TodoItem(92, 4000, new DateTime(2019, 1, 8)),
                new TodoItem(93, 4000, new DateTime(2019, 1, 13)),
                // week
                new TodoItem(94, 4000, new DateTime(2019, 1, 15)),
                new TodoItem(95, 4000, new DateTime(2019, 1, 16)),
            });


            IntervalList IL = new IntervalList(7, items);

            WL    = new WeekList(IL.List);
            ALSL  = new AverageLineSeriesList(2, WL.List);
            ALSL1 = new AverageLineSeriesList(1, WL.List);
        }
        public void Setup()
        {
            List <TodoItem> items = new List <TodoItem>(
                new TodoItem[] {
                new TodoItem(90, 4000, new DateTime(2019, 1, 1)),
                new TodoItem(91, 4000, new DateTime(2019, 1, 2)),
                // week
                new TodoItem(92, 4000, new DateTime(2019, 1, 8)),
                new TodoItem(93, 4000, new DateTime(2019, 1, 13)),
                // week
                new TodoItem(94, 4000, new DateTime(2019, 1, 15)),
                new TodoItem(95, 4000, new DateTime(2019, 1, 16)),
            });

            IntervalList     IL  = new IntervalList(7, items);
            WeekList         WL  = new WeekList(IL.List);
            WeightChangeList WCL = new WeightChangeList(WL.List);

            w0 = WCL.List.ElementAt(0);
            w1 = WCL.List.ElementAt(1);
            w2 = WCL.List.ElementAt(2);
            w3 = WCL.List.ElementAt(3);
        }
Esempio n. 26
0
        /**
         * Allocate a fresh integer from the range, or return -1 if no more integers
         * are available. This operation is guaranteed to run in O(1)
         */

        public int Allocate()
        {
            if (_unsortedCount > 0)
            {
                return(_unsorted[--_unsortedCount]);
            }
            else if (_base != null)
            {
                int result = _base.Start;
                if (_base.Start == _base.End)
                {
                    _base = _base.Next;
                }
                else
                {
                    _base.Start++;
                }
                return(result);
            }
            else
            {
                return(-1);
            }
        }
Esempio n. 27
0
 public void Exclude2Test()
 {
     var intervalList = new IntervalList<int>
         {
             new Interval<int>(1, 10),
             new Interval<int>(1, 10),
             new Interval<int>(5, 7),
             new Interval<int>(4, 10),
             new Interval<int>(0, 12),
             new Interval<int>(15, 40),
             new Interval<int>(30, 42),
             new Interval<int>(1, 13),
             new Interval<int>(40, 45),
         };
     intervalList.Exclude(Enumerable.Empty<Interval<int>>());
     Assert.AreEqual(2, intervalList.Count);
     Assert.IsTrue(intervalList[0].Equals(new Interval<int>(0, 13)));
     Assert.IsTrue(intervalList[1].Equals(new Interval<int>(15, 45)));
 }
Esempio n. 28
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));
            }
        }
        public void ShouldWorkWithMissingDays()
        {
            List <TodoItem> items = new List <TodoItem>(
                new TodoItem[] {
                new TodoItem(90, 4000, new DateTime(2019, 1, 1)),
                new TodoItem(91, 4000, new DateTime(2019, 1, 2)),
                //new TodoItem(92, 4000, new DateTime(2019, 1, 3)),
                new TodoItem(93, 4000, new DateTime(2019, 1, 4)),
                new TodoItem(94, 4000, new DateTime(2019, 1, 5)),
                //new TodoItem(95, 4000, new DateTime(2019, 1, 6)),
                new TodoItem(96, 4000, new DateTime(2019, 1, 7)),
                // week
                new TodoItem(97, 4000, new DateTime(2019, 1, 8)),
                new TodoItem(98, 4000, new DateTime(2019, 1, 9)),
                //new TodoItem(99, 4000, new DateTime(2019, 1, 10)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 11)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 12)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 13)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 14)),
                // week
                new TodoItem(90, 4000, new DateTime(2019, 1, 15)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 16)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 17)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 18)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 19)),
                new TodoItem(90, 4000, new DateTime(2019, 1, 20)),
                //new TodoItem(90, 4000, new DateTime(2019, 1, 21)),
            });

            IntervalList IL = new IntervalList(7, items);

            LinkedList <IntervalGroupModel> intervals = new LinkedList <IntervalGroupModel>(
                new IntervalGroupModel[] {
                new IntervalGroupModel()
                {
                    Items = new List <TodoItem>(
                        new TodoItem[] {
                        new TodoItem(90, 4000, new DateTime(2019, 1, 1)),
                        new TodoItem(91, 4000, new DateTime(2019, 1, 2)),
                        //new TodoItem(92, 4000, new DateTime(2019, 1, 3)),
                        new TodoItem(93, 4000, new DateTime(2019, 1, 4)),
                        new TodoItem(94, 4000, new DateTime(2019, 1, 5)),
                        //new TodoItem(95, 4000, new DateTime(2019, 1, 6)),
                        new TodoItem(96, 4000, new DateTime(2019, 1, 7)),
                    }),

                    Start = new DateTime(2019, 1, 1)
                },

                new IntervalGroupModel()
                {
                    Items = new List <TodoItem>(
                        new TodoItem[] {
                        new TodoItem(97, 4000, new DateTime(2019, 1, 8)),
                        new TodoItem(98, 4000, new DateTime(2019, 1, 9)),
                        //new TodoItem(99, 4000, new DateTime(2019, 1, 10)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 11)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 12)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 13)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 14)),
                    }),

                    Start = new DateTime(2019, 1, 8)
                },

                new IntervalGroupModel()
                {
                    Items = new List <TodoItem>(
                        new TodoItem[] {
                        new TodoItem(90, 4000, new DateTime(2019, 1, 15)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 16)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 17)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 18)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 19)),
                        new TodoItem(90, 4000, new DateTime(2019, 1, 20)),
                        //new TodoItem(90, 4000, new DateTime(2019, 1, 21)),
                    }),

                    Start = new DateTime(2019, 1, 15)
                },
            });

            IL.List.Should().BeEquivalentTo(intervals);
        }
        public static void ExecuteExplicitFiltering(Taxonomy taxonomy, ValidationRule rule)
        {
            if (rule.ID.Contains("es_v308"))
            {
            }
            var          tables           = rule.Tables.Select(i => taxonomy.Tables.FirstOrDefault(t => t.ID == i)).ToList();
            IntervalList tableintevallist = null;

            foreach (var table in tables)
            {
                tableintevallist = tableintevallist == null ? new IntervalList() : tableintevallist;
                tableintevallist = Utilities.Objects.MergeSorted(tableintevallist, table.FactindexList, null);
                //tableintevallist.Clear();
            }
            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(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(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)
            {
                data = allfactsintevallist;
            }
            rule.TypedDimensions = rule.BaseQuery.DictFilterIndexes.Where(i => taxonomy.IsTyped(i)).ToList();
            rule.CoveredParts    = rule.BaseQuery.GetAspects(taxonomy);

            var singlefactparameters = rule.Parameters.Where(i => !i.IsGeneral && !i.BindAsSequence).ToList();
            var multifactparameters  = rule.Parameters.Where(i => !i.IsGeneral && i.BindAsSequence).ToList();

            //Utilities.Logger.WriteToFile(String.Format("EnumerateIntervals {0} on {1}", rule.BaseQuery, data));

            foreach (var group in rule.BaseQuery.EnumerateIntervals(taxonomy.FactsOfParts, 0, data, false))
            {
                //Utilities.Logger.WriteToFile("Joining rule with parameters...");
                foreach (var parameter in rule.Parameters)
                {
                    if (!parameter.IsGeneral)
                    {
                        IntervalList facts = (IntervalList)Utilities.Objects.IntersectSorted(parameter.Data, group, null);
                        //var facts = factsq.ToList();
                        if (facts.Count > 0)
                        {
                            hasfacts = true;
                        }
                        else
                        {
                        }
                        parameter.TaxFacts.Add(facts.ToList());
                    }
                }

                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));
            }
        }
 /// <inheritdoc />
 public override bool ContainsNegativeInfinity()
 {
     return(IntervalList.Any(p => p.ContainsNegativeInfinity()));
 }
 /// <inheritdoc />
 public override IEnumerable <TT> Select <TT>(Func <TInterval, TT> selector)
 {
     return(IntervalList.Select(selector));
 }
Esempio n. 33
0
        /// <summary>
        /// Удаление выбросов и вывод на экран диаграмм
        /// </summary>
        private void SearchEjectionWriteResult()
        {
            int lap = 1;

            double[] ND_copy = new double[ND.Length];
            Array.Copy(ND, ND_copy, ND.Length);

            bool flag = false;

            List <Interval> intervalRangeND;

            do
            {
                intervalRangeND = IntervalList.GetIntervalRange(ND_copy);
                ZDotChart dotChartControl   = CreateDotChart(ND_copy, lap);
                double    meanValue         = IntervalList.GetMeanValue(intervalRangeND, ND_copy.Length),
                          standartDeviation = IntervalList.GetStandardDeviation(intervalRangeND, ND_copy.Length),
                          dispersion        = IntervalList.GetDispersion(intervalRangeND, ND_copy.Length);
                string resTemp              = "Мат ожидание: " + Math.Round(meanValue, 3).ToString() + Environment.NewLine +
                                            "σ: " + Math.Round(standartDeviation, 3).ToString() + Environment.NewLine +
                                            "Дисперсия: " + Math.Round(dispersion, 3).ToString() + Environment.NewLine;

                double max   = ND_copy.Max();
                double Tmax  = (max - meanValue) / standartDeviation;
                double Ttabl = TableStudent.Instance[ND_copy.Length - 2];
                resTemp += "Tmax(n) = " + Math.Round(Tmax, 3).ToString() + ";  Tтабл = "
                           + Math.Round(Ttabl, 3).ToString() + " " + Environment.NewLine;
                if (Tmax >= TableStudent.Instance[ND_copy.Length - 2])
                {
                    resTemp += "Выброс Xmax = " + Math.Round(max, 3).ToString() + "." + Environment.NewLine;
                    var tempND = ND_copy.ToList();
                    tempND.Remove(max);
                    ND_copy = tempND.ToArray();
                    flag    = true;
                }
                else
                {
                    flag = false;
                }

                intervalRangeND   = IntervalList.GetIntervalRange(ND_copy);
                meanValue         = IntervalList.GetMeanValue(intervalRangeND, ND_copy.Length);
                standartDeviation = IntervalList.GetStandardDeviation(intervalRangeND, ND_copy.Length);
                dispersion        = IntervalList.GetDispersion(intervalRangeND, ND_copy.Length);
                resTemp          += Environment.NewLine +
                                    "----------------------" + Environment.NewLine + Environment.NewLine +
                                    "Мат ожидание: " + Math.Round(meanValue, 3).ToString() + Environment.NewLine +
                                    "σ: " + Math.Round(standartDeviation, 3).ToString() + Environment.NewLine +
                                    "Дисперсия: " + Math.Round(dispersion, 3).ToString() + Environment.NewLine;

                double min  = ND_copy.Min();
                double Tmin = (meanValue - min) / standartDeviation;
                Ttabl    = TableStudent.Instance[ND_copy.Length - 2];
                resTemp += "Tmin(n) = " + Math.Round(Tmin, 3) + "; Tтабл = " + Ttabl.ToString() + " " + Environment.NewLine;
                if (Tmin >= TableStudent.Instance[ND_copy.Length - 2])
                {
                    resTemp += "Выброс Xmin = " + Math.Round(min, 3).ToString() + "." + Environment.NewLine;
                    flag     = true;
                    var tempND = ND_copy.ToList();
                    tempND.Remove(min);
                    ND_copy = tempND.ToArray();
                }

                dotChartControl.TextRight = resTemp;
                //Построить график
                CollectionDotCharts.Add(dotChartControl);
                lap++;
            } while (flag);
        }
Esempio n. 34
0
 /**
  * Allocate a fresh integer from the range, or return -1 if no more integers
  * are available. This operation is guaranteed to run in O(1)
  */
 public int Allocate()
 {
     if(unsortedCount > 0){
     return unsorted[--unsortedCount];
       } else if (Base != null) {
     int result = Base.Start++;
     if(Base.Start == Base.End) Base = Base.Next;
     return result;
       } else {
     return -1;
       }
 }
Esempio n. 35
0
        public Message ProcessRequest(Message request)
        {
            var ajaxtag = "ajax";


            //Logger.WriteLine("ProcessRequest " + request.Url);
            Message result = new Message();

            result.Id          = request.Id;
            result.Url         = request.Url;
            result.Error       = "";
            result.ContentType = request.ContentType;
            result.Category    = request.Category;
            if (request.Category == "notification")
            {
                Utilities.Logger.WriteLine(request.Data);
                if (request.Data.ToLower().Contains("ui ready"))
                {
                    AppEngine.Features.OnUIReady();
                    //AppEngine.Features.LoadTaxonomyToUI();
                }
            }
            if (request.Category == ajaxtag)
            {
                if (Utilities.FS.FileExists(request.Url))
                {
                    result.Data = Utilities.FS.ReadAllText(request.Url);
                }
                else
                {
                    var filextension = "";
                    var extix        = request.Url.LastIndexOf(".");
                    if (extix > -1)
                    {
                        filextension = request.Url.Substring(extix + 1);
                    }
                    if (filextension.In("html"))
                    {
                        var table = Engine.CurrentTaxonomy.Tables.FirstOrDefault(i => i.HtmlPath == request.Url);
                        if (table != null)
                        {
                            result.Data = Utilities.FS.ReadAllText(table.FullHtmlPath);
                        }
                    }

                    if (filextension.In("xml", "xsd"))
                    {
                        var doc = Engine.CurrentTaxonomy.TaxonomyDocuments.FirstOrDefault(i => i.LocalRelPath == request.Url);
                        if (doc != null)
                        {
                            result.Data = Utilities.FS.ReadAllText(doc.LocalPath);
                        }
                    }
                    var urlparts = request.Url.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                    if (urlparts.Length == 2)
                    {
                        var part0 = urlparts[0].ToLower();
                        var part1 = urlparts[1].ToLower();
                        if (part0 == "settings")
                        {
                            var settings = Settings.Current;

                            if (part1 == "get")
                            {
                                result.Data = settings.GetJsonObj();
                            }
                            if (part1 == "save")
                            {
                                var keys = settings.Keys.ToList();

                                foreach (var key in keys)
                                {
                                    var value = request.GetParameter(key);
                                    settings.SetValue(key, value);
                                }
                                //settings.CheckValidationCells = request.GetParameter<bool>("CheckValidationCells");
                                //settings.ReDownloadFiles = request.GetParameter<bool>("ReDownloadFiles");
                                //settings.ReloadFullTaxonomy = request.GetParameter<bool>("ReloadFullTaxonomy");
                                //settings.ReloadFullTaxonomyButStructure = request.GetParameter<bool>("ReloadFullTaxonomyButStructure");
                                if (settings.ReloadFullTaxonomy)
                                {
                                    settings.ReloadFullTaxonomyButStructure = true;
                                }
                                //settings.ReloadTaxonomyOnInstanceLoaded = request.GetParameter<bool>("ReloadTaxonomyOnInstanceLoaded");
                                //settings.ValidateOnInstanceLoaded = request.GetParameter<bool>("ValidateOnInstanceLoaded");

                                this.AppEngine.Features.SaveSettings();
                            }
                        }
                        if (part0 == "instance")
                        {
                            if (Engine.CurrentInstance != null && Engine.CurrentTaxonomy != null)
                            {
                                if (part1 == "get")
                                {
                                    var json = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.CurrentInstancePath);
                                    json = json.Replace("\r\n", "");

                                    result.Data = json;
                                }
                                if (part1 == "save")
                                {
                                    var factsjson = request.GetParameter("facts");
                                    var facts     = Utilities.Converters.JsonTo <List <InstanceFact> >(factsjson);
                                    var json      = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.CurrentInstancePath);
                                    Engine.CurrentInstance.SaveFacts(facts);
                                    this.AppEngine.Features.SaveInstance("");
                                    //result.Data = "Ok";
                                }
                                if (part1 == "validation")
                                {
                                    var json = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.CurrentInstanceValidationResultPath);
                                    result.Data = json;
                                }
                                if (part1 == "factindexes")
                                {
                                    var indexes_str = request.GetParameter("indexes").ToLower();
                                    var indexes     = indexes_str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                    var items       = Engine.CurrentInstance.GetFactStringsByFactIdStrings(indexes);
                                    var json        = Utilities.Converters.ToJson(items);
                                    result.Data = json;
                                }
                                if (part1 == "validationresults")
                                {
                                    var page     = int.Parse(request.GetParameter("page"));
                                    var pagesize = int.Parse(request.GetParameter("pagesize"));
                                    var ruleid   = request.GetParameter("ruleid").ToLower();
                                    var full     = request.GetParameter("full").ToLower();

                                    var taxonomy = AppEngine.Features.Engine.CurrentTaxonomy;
                                    var instance = AppEngine.Features.Engine.CurrentInstance;

                                    var rs    = new DataResult <LogicalModel.Validation.ValidationRuleResult>();
                                    var query = Engine.CurrentInstance.ValidationRuleResults.AsQueryable();
                                    if (full == "1")
                                    {
                                        SimpleValidationRule rule = taxonomy.ValidationRules.FirstOrDefault(i => i.ID.Equals(ruleid, StringComparison.OrdinalIgnoreCase));
                                        if (rule == null)
                                        {
                                            rule = taxonomy.SimpleValidationRules.FirstOrDefault(i => i.ID.Equals(ruleid, StringComparison.OrdinalIgnoreCase));
                                        }
                                        if (rule != null)
                                        {
                                            query = rule.GetAllInstanceResults(instance).AsQueryable();
                                        }
                                        else
                                        {
                                            Utilities.Logger.WriteLine(String.Format("Rule {0} was not Found (DataService)", ruleid));
                                        }
                                    }
                                    query = query.Where(i => i.ID.Equals(ruleid, StringComparison.OrdinalIgnoreCase));
                                    //TODO

                                    var idlist = new List <int>();


                                    rs.Items = query.Skip(pagesize * page).Take(pagesize).ToList();
                                    foreach (var item in rs.Items)
                                    {
                                        foreach (var p in item.Parameters)
                                        {
                                            foreach (var fid in p.FactIDs)
                                            {
                                                var fact = instance.GetFactBaseByIndexString(fid);
                                                if (fact != null)
                                                {
                                                    //p.Facts.Add(fact.FactString);
                                                }
                                            }
                                        }
                                    }
                                    rs.Total = query.Count();
                                    var json = Utilities.Converters.ToJson(rs);
                                    foreach (var item in rs.Items)
                                    {
                                        foreach (var p in item.Parameters)
                                        {
                                            p.InstanceFacts.Clear();
                                        }
                                    }
                                    result.Data = json;
                                }
                            }
                        }
                        if (part0 == "layout")
                        {
                            var url     = request.Url.Replace("/", "\\");
                            var content = System.IO.File.ReadAllText(url);
                            result.Data = content;
                        }
                        if (part0 == "ui")
                        {
                            if (part1 == "menu")
                            {
                                var commandid = request.GetParameter("command").ToLower();
                                var p1        = request.GetParameter("p1").ToLower();
                                if (!string.IsNullOrEmpty(commandid))
                                {
                                    var command = this.AppEngine.Features.CommandContainer.Where(i => i.ID.ToLower() == commandid).FirstOrDefault();
                                    if (command != null)
                                    {
                                        var originalca = command.ContextAccessor;
                                        command.ContextAccessor = () => { return(new object[] { p1 }); };
                                        command.Execute();
                                        command.ContextAccessor = originalca;
                                    }
                                }
                                else
                                {
                                    var json = AppEngine.Features.GetJsonObj(AppEngine.Features.CommandContainer);
                                    result.Data = json;
                                }
                            }
                        }
                        if (part0 == "browse")
                        {
                            var json = "";
                            if (part1 == "file")
                            {
                                json = AppEngine.Features.UI.BrowseFile("", "");
                            }
                            if (part1 == "folder")
                            {
                                json = AppEngine.Features.UI.BrowseFolder("");
                            }
                            result.Data = json;
                        }
                        if (part0 == "app")
                        {
                            var json = "";
                            if (part1 == "info")
                            {
                                json = AppEngine.Features.GetAppInfo();
                            }
                            result.Data = json;
                        }
                        if (part0 == "taxonomy")
                        {
                            var json = "";
                            if (Engine.CurrentTaxonomy != null)
                            {
                                if (part1 == "get")
                                {
                                    json = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.TaxonomyModulePath);
                                }
                                if (part1 == "concepts")
                                {
                                    json = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.TaxonomyConceptPath);
                                }
                                if (part1 == "cellindexes")
                                {
                                    json = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.TaxonomyCellIndexPath);
                                }
                                if (part1 == "documents")
                                {
                                    json = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.TaxonomyStructurePath);
                                    if (Utilities.FS.FileExists(Engine.CurrentInstance.FullPath))
                                    {
                                        var td = new TaxonomyDocument();
                                        td.LocalRelPath = Engine.CurrentInstance.FullPath;
                                        td.FileName     = Utilities.Strings.GetFileName(td.LocalRelPath);
                                        var instjson = Utilities.Converters.ToJson(td);
                                        json = json.Insert(json.IndexOf("[") + 1, instjson + ", ");
                                    }
                                }
                                if (part1 == "validationrules")
                                {
                                    json = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.TaxonomySimpleValidationPath);
                                }
                                if (part1 == "validationrule")
                                {
                                    var id   = request.Parameters["id"];
                                    var rule = Engine.CurrentTaxonomy.ValidationRules.FirstOrDefault(i => i.ID == id);
                                    if (rule != null)
                                    {
                                        var results = Engine.CurrentInstance.Facts.Count > 0 ? rule.GetAllInstanceResults(Engine.CurrentInstance) : rule.GetAllResults();
                                        json = Utilities.Converters.ToJson(results);
                                    }
                                }
                                if (part1 == "hierarchies")
                                {
                                    json = Utilities.FS.ReadAllText(Engine.CurrentTaxonomy.TaxonomyHierarchyPath);
                                }
                                if (part1 == "labels")
                                {
                                    var page     = int.Parse(request.GetParameter("page"));
                                    var pagesize = int.Parse(request.GetParameter("pagesize"));
                                    var key      = request.GetParameter("key");
                                    var code     = request.GetParameter("code");
                                    var content  = request.GetParameter("content");
                                    var query    = AppEngine.Features.Engine.CurrentTaxonomy.TaxonomyLabels.AsQueryable();
                                    if (!String.IsNullOrEmpty(key))
                                    {
                                        query = query.Where(i => i.Key.IndexOf(key, StringComparison.InvariantCultureIgnoreCase) > -1);
                                    }
                                    if (!String.IsNullOrEmpty(code))
                                    {
                                        query = query.Where(i => i.Code.IndexOf(code, StringComparison.InvariantCultureIgnoreCase) > -1);
                                    }
                                    if (!String.IsNullOrEmpty(content))
                                    {
                                        query = query.Where(i => i.Content.IndexOf(content, StringComparison.InvariantCultureIgnoreCase) > -1);
                                    }
                                    var rs = new DataResult <Label>();
                                    rs.Items = query.Skip(pagesize * page).Take(pagesize).ToList();
                                    rs.Total = query.Count();
                                    json     = Utilities.Converters.ToJson(rs);
                                }
                                if (part1 == "facts")
                                {
                                    var page       = int.Parse(request.GetParameter("page"));
                                    var pagesize   = int.Parse(request.GetParameter("pagesize"));
                                    var factstring = request.GetParameter("factstring");
                                    var cellid     = request.GetParameter("cellid").ToLower();
                                    var rs         = new DataResult <KeyValue>();
                                    var taxonomy   = Engine.CurrentTaxonomy;
                                    var query      = taxonomy.FactIndexEnumerable();

                                    var qry = LogicalModel.Base.FactBaseQuery.GetQuery(factstring, Engine.CurrentTaxonomy.FactParts);
                                    if (qry != null)
                                    {
                                        var all    = new Interval(0, taxonomy.FactsManager.FactsOfPages.HashKeys.Count);
                                        var allist = new IntervalList();
                                        allist.AddInterval(all);
                                        var idlist2 = qry.EnumerateIntervals(taxonomy.FactsOfParts, 0, allist, false).SelectMany(i => i);

                                        var indexes  = idlist2.Select(i => i).Distinct().ToDictionary(k => k, v => true);
                                        var comparer = new Utilities.IntArrayEqualityComparer();
                                        query = query.Where(i => indexes.ContainsKey(i));
                                    }
                                    if (!String.IsNullOrEmpty(cellid))
                                    {
                                        //var cells = taxonomy.CellIndexDictionary.Where(i => i.Value.IndexOf(cellid, StringComparison.Ordinal)>-1).Select(i=>i.Key);
                                        //longcellid=cellid
                                        //query = query.Where(i => i.Value.Any(j => cells.Contains(j)));
                                        query = query.Where(i => taxonomy.FactsManager.GetFact(i).Value.Any(j => taxonomy.CellIndexDictionary[j].IndexOf(cellid, StringComparison.OrdinalIgnoreCase) > -1));
                                    }

                                    rs.Items = query.Skip(pagesize * page).Take(pagesize).Select(i =>
                                    {
                                        var keycell = taxonomy.FactsManager.GetFactKeywithCells(i);
                                        var keystr  = taxonomy.GetFactStringKey(keycell.FactKey);
                                        return(new KeyValue(keystr, keycell.CellIndexes));       //.Select(c => taxonomy.CellIndexDictionary[c]).ToList()
                                    }
                                                                                                 ).ToList();
                                    rs.Total = query.Count();
                                    json     = Utilities.Converters.ToJson(rs);
                                }
                                if (part1 == "table")
                                {
                                    if (request.Parameters.ContainsKey("cell"))
                                    {
                                        var cell      = request.Parameters["cell"];
                                        var report    = "";
                                        var extension = "";
                                        var row       = "";
                                        var column    = "";
                                        if (cell.IndexOf(">") > -1)
                                        {
                                            report = cell.Remove(cell.IndexOf("<"));
                                            var cellspecifiers = cell.TextBetween("<", ">").Split('|');
                                            var nr_params      = cellspecifiers.Length;
                                            extension = nr_params > 0 ? cellspecifiers[0] : "";
                                            row       = nr_params > 1 ? cellspecifiers[1] : "";
                                            column    = nr_params > 2 ? cellspecifiers[2] : "";
                                        }
                                        else
                                        {
                                            report = cell;
                                        }

                                        json = GetTableHtmlPath(report, extension, row, column);
                                    }
                                    if (request.Parameters.ContainsKey("item"))
                                    {
                                        var item = request.Parameters["item"];
                                        if (item == "factmap")
                                        {
                                            var reportid = request.Parameters["reportid"];
                                            var table    = this.Engine.CurrentTaxonomy.Tables.FirstOrDefault(i => i.ID == reportid);
                                            if (table != null)
                                            {
                                                json = Utilities.FS.ReadAllText(table.FactMapPath);
                                            }
                                        }
                                    }
                                }
                                if (part1 == "tables")
                                {
                                    var h           = new BaseModel.Hierarchy <TableInfo>();
                                    var tablegroups = Engine.CurrentTaxonomy.Module.TableGroups.Cast <TableInfo>(i =>
                                    {
                                        var ti    = new TableInfo();
                                        ti.ID     = i.ID;// String.IsNullOrEmpty(i.FilingIndicator) ? i.ID : i.FilingIndicator;
                                        ti.Tables = i.TableIDs;
                                        //var name = String.IsNullOrEmpty(i.LabelCode) ? i.LabelContent : i.LabelCode;
                                        var name       = String.IsNullOrEmpty(i.FilingIndicator) ? i.LabelContent : i.FilingIndicator;
                                        ti.Name        = Utilities.Strings.TrimTo(name, 40);
                                        ti.Description = i.LabelContent;
                                        ti.Type        = "tablegroup";
                                        return(ti);
                                    });

                                    var tgs            = tablegroups.All();
                                    var tablesingroups = tgs.SelectMany(i => i.Item.Tables).Distinct().ToList();
                                    var alltableids    = Engine.CurrentTaxonomy.Tables.Select(i => i.ID).ToList();
                                    var ungrouped      = alltableids.Except(tablesingroups).ToList();
                                    foreach (var tgcontainer in tgs)
                                    {
                                        var tg  = tgcontainer.Item;
                                        var htg = tgcontainer;// new BaseModel.Hierarchy<LogicalModel.TableInfo>(tg);

                                        //h.Children.Add(htg);
                                        //var tables = Engine.CurrentTaxonomy.Tables.Where(i => i.FilingIndicator == tg.ID);
                                        var tables = Engine.CurrentTaxonomy.Tables.Where(i => tg.Tables.Contains(i.ID)).ToList();
                                        if (tables.Count > 0)
                                        {
                                            //htg.Children.Clear();
                                        }
                                        foreach (var tbl in tables)
                                        {
                                            var tbinfo = new TableInfo();
                                            var ht     = htg.Children.FirstOrDefault(i => i.Item.ID == tbl.ID);
                                            if (ht == null)
                                            {
                                                ht = new BaseModel.Hierarchy <TableInfo>(tbinfo);
                                                htg.Children.Add(ht);
                                            }

                                            ht.Item.ID      = String.Format("{0}<>", tbl.ID);
                                            ht.Item.HasData = tbl.InstanceFactsCount;
                                            var name = tbl.Name;
                                            ht.Item.Name        = Utilities.Strings.TrimTo(name, 40);
                                            ht.Item.Description = string.IsNullOrEmpty(tbl.LabelContent) ? name : tbl.LabelContent;
                                            ht.Item.Type        = "table";
                                            //TODO EXT
                                            //var tbextensions = tbl.Extensions.Children;
                                            var tbextensions = Engine.CurrentInstance.GetTableExtensions(tbl);
                                            ht.Children.AddRange(tbextensions.Select(i => new BaseModel.Hierarchy <TableInfo>(i)));
                                        }
                                    }
                                    h = tablegroups;
                                    if (ungrouped.Count > 0)
                                    {
                                        var ungroupedti = new TableInfo();
                                        ungroupedti.Type = "tablegroup";
                                        ungroupedti.Name = "Ungrouped";
                                        var hungr = new Hierarchy <TableInfo>(ungroupedti);
                                        h.AddChild(hungr);
                                        foreach (var t in ungrouped)
                                        {
                                            var tbinfo = new TableInfo();
                                            var tbl    = Engine.CurrentTaxonomy.Tables.FirstOrDefault(i => i.ID == t);
                                            var ht     = new BaseModel.Hierarchy <TableInfo>(tbinfo);


                                            ht.Item.ID      = String.Format("{0}<>", tbl.ID);
                                            ht.Item.HasData = tbl.InstanceFactsCount;
                                            var name = tbl.Name;
                                            ht.Item.Name        = Utilities.Strings.TrimTo(name, 40);
                                            ht.Item.Description = string.IsNullOrEmpty(tbl.LabelContent) ? name : tbl.LabelContent;
                                            ht.Item.Type        = "table";
                                            hungr.AddChild(ht);
                                        }
                                    }
                                    var itemswithdata = h.Where(i => i.Item.HasData > 0).ToList();
                                    foreach (var itemwithdata in itemswithdata)
                                    {
                                        var current = itemwithdata;
                                        while (current.Parent != null)
                                        {
                                            current = current.Parent;
                                            current.Item.HasData = itemwithdata.Item.HasData;
                                        }
                                    }
                                    json = Utilities.Converters.ToJson(h);
                                }
                            }
                            result.Data = json;
                        }
                    }
                }
                //Logger.WriteLine("Finished " + request.Url);
            }
            return(result);
        }
Esempio n. 36
0
 private void Flush()
 {
     if(unsortedCount > 0)
     {
     Base = IntervalList.Merge(Base, IntervalList.FromArray(unsorted, unsortedCount));
     unsortedCount = 0;
     }
 }
Esempio n. 37
0
        public bool Reserve(int id)
        {
            // We always flush before reserving because the only way to determine
              // if an ID is in the unsorted array is through a linear scan. This leads
              // us to the potentially expensive situation where there is a large unsorted
              // array and we reserve several IDs, incurring the cost of the scan each time.
              // Flushing makes sure the array is always empty and does no additional work if
              // reserve is called twice.
              Flush();

              IntervalList current = Base;

              while(current != null)
              {
            if(current.End < id)
            {
              current = current.Next;
              continue;
            }
            else if(current.Start > id)
            {
              return false;
            }
            else if(current.End == id)
            {
              current.End--;
            }
            else if(current.Start == id)
            {
              current.Start++;
            }
            else
            {
              // The ID is in the middle of this interval.
              // We need to split the interval into two.
              IntervalList rest = new IntervalList(id + 1, current.End);
              current.End = id - 1;
              rest.Next = current.Next;
              current.Next = rest;
            }
            return true;
              }
              return false;
        }
Esempio n. 38
0
 public IEnumerable<Interval<DateTime>> NextAll(DateTime from, DateTime to)
 {
     var allowIntervals = new IntervalList<DateTime>(_allow.SelectMany(x => x.Next(from, to))).Normalize();
     var denyIntervals = new IntervalList<DateTime>(_deny.SelectMany(x => x.Next(from, to))).Normalize();
     allowIntervals.Exclude(denyIntervals);
     return allowIntervals.OrderBy(x => x.Min);
 }
Esempio n. 39
0
            public static IntervalList FromArray(int[] xs, int length)
            {
                Array.Sort(xs, 0, length);

                IntervalList result = null;
                IntervalList current = null;

                int i = 0;
                while(i < length){
                  int start = i;
                  while((i < length - 1) && (xs[i + 1] == xs[i] + 1))
                i++;

                  IntervalList interval = new IntervalList(xs[start], xs[i]);

                  if(result == null)
                  {
                result = interval;
                current = interval;
                  }
                  else
                  {
                current.Next = interval;
                current = interval;
                  }
                  i++;
                }
                return result;
            }