Пример #1
0
        /// <summary>
        /// Finds the Tset associated with a given Tnum value on a given date.
        /// </summary>
        private static Hval AssociatedTset(List <Tuple <Tset, Tnum> > setFcnVals, Tnum val, DateTime asOfDate)
        {
            foreach (Tuple <Tset, Tnum> t in setFcnVals)
            {
                // Handle uncertainty
                Hval s = t.Item2.AsOf(asOfDate).FirstValue;
                Hval v = val.AsOf(asOfDate).FirstValue;
                if (s.IsUncertain && v.IsUncertain)
                {
                    return(new Hval(null));                                     // Not hitting this for some reason...
                }
                if (s.IsUnstated && v.IsUnstated)
                {
                    return(new Hval(null, Hstate.Unstated));
                }
                if (s.IsStub && v.IsStub)
                {
                    return(new Hval(null, Hstate.Stub));
                }

                // Compare numeric values
                if (t.Item2.AsOf(asOfDate) == val.AsOf(asOfDate))
                {
                    // Tsets created in Combos() are eternal, so FirstValue is ok here
                    return(t.Item1.FirstValue);
                }
            }
            return(new Hval(null, Hstate.Stub));
        }
Пример #2
0
        /// <summary>
        /// Finds the Tset associated with a given Tnum value on a given date.
        /// </summary>
        private static Hval AssociatedTset(List<Tuple<Tset,Tnum>> setFcnVals, Tnum val, DateTime asOfDate)
        {
            foreach(Tuple<Tset,Tnum> t in setFcnVals)
            {
                // Handle uncertainty
                Hval s = t.Item2.AsOf(asOfDate).FirstValue;
                Hval v = val.AsOf(asOfDate).FirstValue;
                if (s.IsUncertain && v.IsUncertain)     return new Hval(null);  // Not hitting this for some reason...
                if (s.IsUnstated && v.IsUnstated)       return new Hval(null, Hstate.Unstated);
                if (s.IsStub && v.IsStub)               return new Hval(null, Hstate.Stub);

                // Compare numeric values
                if (t.Item2.AsOf(asOfDate) == val.AsOf(asOfDate))
                {
                    // Tsets created in Combos() are eternal, so FirstValue is ok here
                    return t.Item1.FirstValue;
                }
            }
            return new Hval(null, Hstate.Stub);
        }
Пример #3
0
        /// <summary>
        /// Returns a running count (over time) of the number of subintervals
        /// within each interval in which the Tvar (this) is true.
        /// </summary>
        /// <remarks>
        /// This function should be used as an extension method to EverPer()
        /// or AlwaysPer().
        /// Example: Count the number of weeks each year during which
        /// a person was employed.  The first week of employment would be
        /// numbered 0, the second 1, etc.
        /// </remarks>
        // TODO: Fix broken test case for this function.
        public Tnum RunningCountPer(Tnum intervals)
        {
            // TODO: Implement unknowns

            Tnum result = new Tnum();

            result.AddState(Time.DawnOf, 0);

            int     count   = 0;
            decimal?prevBig = 0;
            SortedList <DateTime, Hval> sub = this.IntervalValues;

            // Iterate through the sub-intervals
            for (int i = 0; i < sub.Count - 1; i++)
            {
                DateTime dt = sub.Keys[i];

                // Reset count for each new (big, not sub-) interval
                decimal?big = intervals.AsOf(dt).ToDecimal;
                if (big != prevBig)
                {
                    count = 0;
                }
                prevBig = big;

                // If the Tbool is true during the subinterval, increment
                // the subsequent subinterval
                if (this.AsOf(dt).ToBool == true)
                {
                    count++;
                }

                result.AddState(sub.Keys[i + 1], count);
            }

            return(result.Lean);
        }
Пример #4
0
        /// <summary>
        /// Returns the total number of elapsed intervals between two dates.
        /// </summary>
        public Tnum TotalElapsedIntervals(Tnum interval, Tdate start, Tdate end)
        {
            Tnum rei = RunningElapsedIntervals(interval);

            return(rei.AsOf(end) - rei.AsOf(start));
        }
Пример #5
0
        /// <summary>
        /// Finds the total of a Tnum, summed over the given intervals between two
        /// dates (start and end).
        /// </summary>
        /// <example>
        ///   AnnualIncome2014 = MonthlyIncome.TotalSummedIntervals(TheMonth, 2014-01-01, 2014-12-31)
        /// </example>
        public Tnum TotalSummedIntervals(Tnum interval, Tdate start, Tdate end)
        {
            Tnum rsi = RunningSummedIntervals(interval);

            return(rsi.AsOf(end) - rsi.AsOf(start));
        }