コード例 #1
0
        public static Tnum IntervalsSince(Tdate startDate, Tdate endDate, IntervalType interval, int? startAt)
        {
            // Handle unknowns
            Hstate top = PrecedingState(startDate.FirstValue, endDate.FirstValue);
            if (top != Hstate.Known) return new Tnum(new Hval(null,top));

            DateTime start = startDate.ToDateTime;
            DateTime end = endDate.ToDateTime;

            Tnum result = new Tnum();

            if (start != Time.DawnOf)
            {
                result.AddState(Time.DawnOf,0);
            }

            DateTime indexDate = start;
            int? indexNumber = startAt;

            while (indexDate < end)
            {
                result.AddState(indexDate,Convert.ToDecimal(indexNumber));
                indexNumber++;
                indexDate = indexDate.AddInterval(interval, 1);
            }

            if (end < Time.EndOf) result.AddState(end, 0);
            return result;
        }
コード例 #2
0
        public static Tnum IntervalsUntil(Tdate startDate, Tdate endDate, IntervalType interval, int startAt)
        {
            // Handle unknowns
            Hstate top = PrecedingState(startDate.FirstValue, endDate.FirstValue);

            if (top != Hstate.Known)
            {
                return(new Tnum(new Hval(null, top)));
            }

            DateTime start = startDate.ToDateTime;
            DateTime end   = endDate.ToDateTime;

            Tnum result = new Tnum();

            DateTime indexDate   = end;
            int      indexNumber = startAt - 1;

            while (indexDate > start)
            {
                if (indexNumber != startAt - 1)
                {
                    result.AddState(indexDate, Convert.ToString(indexNumber));
                }
                indexNumber++;
                indexDate = indexDate.SubtractInterval(interval);
            }

            result.AddState(Time.DawnOf, 0);
            result.AddState(start, Convert.ToString(indexNumber));
            result.AddState(end, 0);

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Determines whether this instance is ever true during a specified time period.
        /// </summary>
        public Tbool IsEverTrue(Tdate start, Tdate end)
        {
            Tbool equalsVal = this == true;

            Tbool isDuringInterval = Time.IsBetween(start, end);

            Tbool isOverlap = equalsVal & isDuringInterval;

            return(isOverlap.IsEverTrue());
        }
コード例 #4
0
        /// <summary>
        /// Determines whether this instance is always true during a specified interval.
        /// </summary>
        public Tbool IsAlwaysTrue(Tdate start, Tdate end)
        {
            Tbool equalsVal = this == true;

            Tbool isDuringInterval = Time.IsBetween(start, end);

            Tbool isOverlap = equalsVal & isDuringInterval;

            Tbool overlapAndIntervalAreCoterminous = isOverlap == isDuringInterval;

            return(!overlapAndIntervalAreCoterminous.IsEver(false));
        }
コード例 #5
0
        /// <summary>
        /// Returns a Tbool that's true up to a specified DateTime, and false
        /// at and after it.
        /// </summary>
        public static Tbool IsBefore(Tdate dt)
        {
            // Handle unknowns
            if (!dt.FirstValue.IsKnown)
            {
                return(new Tbool(dt.FirstValue));
            }

            // Create boolean
            Tbool result = new Tbool();

            if (dt == DawnOf)
            {
                result.AddState(DawnOf, false);
            }
            else
            {
                result.AddState(DawnOf, true);
                result.AddState(dt.ToDateTime, false);
            }
            return(result);
        }
コード例 #6
0
        //*********************************************************************
        // TEMPORAL "RECURRENCE" FUNCTIONS
        //*********************************************************************

        /// <summary>
        /// Loops (cycles) through numbers over time (e.g. 1 2 3 4 1 2 3 4 ...)
        /// </summary>
        public static Tnum Recurrence(Tdate startDate, Tdate endDate, IntervalType interval, int min, int max)
        {
            // Handle unknowns
            Hstate top = PrecedingState(startDate.FirstValue, endDate.FirstValue);

            if (top != Hstate.Known)
            {
                return(new Tnum(new Hval(null, top)));
            }

            DateTime start = startDate.ToDateTime;
            DateTime end   = endDate.ToDateTime;

            Tnum result = new Tnum();

            if (start != Time.DawnOf)
            {
                result.AddState(Time.DawnOf, 0);
            }

            DateTime indexDate   = start;
            int      indexNumber = min;

            while (indexDate < end)
            {
                result.AddState(indexDate, Convert.ToString(indexNumber));
                indexDate = indexDate.AddInterval(interval, 1);

                // Reset sequence
                indexNumber++;
                if (indexNumber > max)
                {
                    indexNumber = min;
                }
            }

            result.AddState(end, 0);
            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Returns the value of a Tvar at a specified point in time.
        /// </summary>
        /// <remarks>
        /// If the Tdate varies over time, only the first value is used.
        /// </remarks>
        public T AsOf <T>(Tdate date) where T : Tvar
        {
            Hval result;

            // If base Tvar has eternal, known value, return that.
            // (In these cases, the Tdate is irrelevant.)
            if (this.IsEternal && !this.IsEternallyUnknown)
            {
                result = this.FirstValue;
            }
            // If either the base Tvar or Tdate are unknown...
            else if (!date.FirstValue.IsKnown || this.IsEternallyUnknown)
            {
                Hstate top = PrecedingState(this.FirstValue, date.FirstValue);
                result = new Hval(null, top);
            }
            else
            {
                result = this.ObjectAsOf(date.ToDateTime);
            }

            return((T)Util.ReturnProperTvar <T>(result));
        }
コード例 #8
0
        public static Tnum IntervalsSince(Tdate startDate, Tdate endDate, IntervalType interval, int?startAt)
        {
            // Handle unknowns
            Hstate top = PrecedingState(startDate.FirstValue, endDate.FirstValue);

            if (top != Hstate.Known)
            {
                return(new Tnum(new Hval(null, top)));
            }

            DateTime start = startDate.ToDateTime;
            DateTime end   = endDate.ToDateTime;

            Tnum result = new Tnum();

            if (start != Time.DawnOf)
            {
                result.AddState(Time.DawnOf, 0);
            }

            DateTime indexDate   = start;
            int?     indexNumber = startAt;

            while (indexDate < end)
            {
                result.AddState(indexDate, Convert.ToDecimal(indexNumber));
                indexNumber++;
                indexDate = indexDate.AddInterval(interval, 1);
            }

            if (end < Time.EndOf)
            {
                result.AddState(end, 0);
            }
            return(result);
        }
コード例 #9
0
 //*********************************************************************
 // TEMPORAL "STEP" FUNCTIONS
 //*********************************************************************
 /// <summary>
 /// Returns the number of intervals since a given date (step up function)
 /// (e.g. 1 2 3 4 5 6 7 8 9 ...)
 /// </summary>
 public static Tnum IntervalsSince(Tdate start, Tdate end, IntervalType interval)
 {
     return IntervalsSince(start, end, interval, 0);
 }
コード例 #10
0
        //*********************************************************************
        // TEMPORAL "RECURRENCE" FUNCTIONS
        //*********************************************************************
        /// <summary>
        /// Loops (cycles) through numbers over time (e.g. 1 2 3 4 1 2 3 4 ...)
        /// </summary>
        public static Tnum Recurrence(Tdate startDate, Tdate endDate, IntervalType interval, int min, int max)
        {
            // Handle unknowns
            Hstate top = PrecedingState(startDate.FirstValue, endDate.FirstValue);
            if (top != Hstate.Known) return new Tnum(new Hval(null,top));

            DateTime start = startDate.ToDateTime;
            DateTime end = endDate.ToDateTime;

            Tnum result = new Tnum();

            if (start != Time.DawnOf)
            {
                result.AddState(Time.DawnOf, 0);
            }

            DateTime indexDate = start;
            int indexNumber = min;

            while (indexDate < end)
            {
                result.AddState(indexDate,Convert.ToString(indexNumber));
                indexDate = indexDate.AddInterval(interval, 1);

                // Reset sequence
                indexNumber++;
                if (indexNumber > max)
                {
                    indexNumber = min;
                }
            }

            result.AddState(end, 0);
            return result;
        }
コード例 #11
0
ファイル: Tbool.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the value of a Tbool at a specified point in time. 
 /// </summary>
 public Tbool AsOf(Tdate dt)
 {
     return this.AsOf<Tbool>(dt);
 }
コード例 #12
0
ファイル: Tbool.cs プロジェクト: mpoulshock/hammurabi
        /// <summary>
        /// Determines whether this instance is always true during a specified interval.
        /// </summary>
        public Tbool IsAlwaysTrue(Tdate start, Tdate end)
        {
            Tbool equalsVal = this == true; 

            Tbool isDuringInterval = Time.IsBetween(start, end);
            
            Tbool isOverlap = equalsVal & isDuringInterval;

            Tbool overlapAndIntervalAreCoterminous = isOverlap == isDuringInterval;

            return !overlapAndIntervalAreCoterminous.IsEver(false);
        }
コード例 #13
0
ファイル: Misc.cs プロジェクト: mkpace/hammurabi
 /// <summary>
 /// Returns the number of weeks (accurate to three decimal places) between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum WeekDiff(Tdate td1, Tdate td2)
 {
     return(Tdate.WeekDifference(td1, td2));
 }
コード例 #14
0
ファイル: Service.svc.cs プロジェクト: mpoulshock/hammurabi
        /// <summary>
        /// Asserts a given fact (of the proper Tvar type)
        /// </summary>
        private static void AssertFact(Factoid f)
        {
            // Instantiate relevant Things
            Thing t1 = f.Arg1.ToString() != "" ? Facts.AddThing(f.Arg1.ToString()) : null;
            Thing t2 = f.Arg2.ToString() != "" ? Facts.AddThing(f.Arg2.ToString()) : null;
            Thing t3 = f.Arg3.ToString() != "" ? Facts.AddThing(f.Arg3.ToString()) : null;

            // Sometimes I have my doubts about static typing...
            if (f.FactType == "Tbool")
            {
                Tbool val = new Tbool();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tnum")
            {
                Tnum val = new Tnum();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tstr")
            {
                Tstr val = new Tstr();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tdate")
            {
                Tdate val = new Tdate();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
            else if (f.FactType == "Tset")
            {
                Tset val = new Tset();
                foreach (TemporalValue v in f.Timeline)
                {
                    val.AddState(v.Date, new Hval(v.Value));
                }
                Facts.Assert(t1, f.Relationship, t2, t3, val);
            }
        }
コード例 #15
0
ファイル: Tdate.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the value of the Tdate at a specified point in time.
 /// </summary>
 public Tdate AsOf(Tdate dt)
 {
     return this.AsOf<Tdate>(dt);
 }
コード例 #16
0
 /// <summary>
 /// Returns the value of the Tnum at a specified point in time.
 /// </summary>
 public Tnum AsOf(Tdate dt)
 {
     return(this.AsOf <Tnum>(dt));
 }
コード例 #17
0
ファイル: Tstr.cs プロジェクト: mkpace/hammurabi
 /// <summary>
 /// Returns the value of a Tstr at a specified point in time.
 /// </summary>
 public Tstr AsOf(Tdate dt)
 {
     return(this.AsOf <Tstr>(dt));
 }
コード例 #18
0
ファイル: Tdate.cs プロジェクト: mkpace/hammurabi
        // TODO: Add MonthDiff and QuarterDiff functions

        /// <summary>
        /// Returns the number of years between the DateTimes in two Tdates.
        /// </summary>
        public static Tnum YearDifference(Tdate td1, Tdate td2)
        {
            return(ApplyFcnToTimeline <Tnum>(x => YearDiffRec(x), td1, td2));;
        }
コード例 #19
0
ファイル: Tdate.cs プロジェクト: mkpace/hammurabi
 /// <summary>
 /// Returns the number of weeks between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum WeekDifference(Tdate td1, Tdate td2)
 {
     return((DayDifference(td1, td2) / 7).RoundToNearest(0.001));
 }
コード例 #20
0
ファイル: Tdate.cs プロジェクト: mkpace/hammurabi
        // ********************************************************************
        // TimeDiff
        // ********************************************************************

        /// <summary>
        /// Returns the number of days between the DateTimes in two Tdates.
        /// </summary>
        public static Tnum DayDifference(Tdate td1, Tdate td2)
        {
            return(ApplyFcnToTimeline <Tnum>(x => CoreDayDiff(x), td1, td2));
        }
コード例 #21
0
ファイル: Tdate.cs プロジェクト: mkpace/hammurabi
 /// <summary>
 /// Returns the value of the Tdate at a specified point in time.
 /// </summary>
 public Tdate AsOf(Tdate dt)
 {
     return(this.AsOf <Tdate>(dt));
 }
コード例 #22
0
ファイル: Misc.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the number of weeks (accurate to three decimal places) between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum WeekDiff(Tdate td1, Tdate td2)
 {
     return Tdate.WeekDifference(td1,td2);
 }
コード例 #23
0
ファイル: Misc.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the number of days between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum DayDiff(Tdate td1, Tdate td2)
 {
     return Tdate.DayDifference(td1,td2);
 }
コード例 #24
0
ファイル: Tdate.cs プロジェクト: mpoulshock/hammurabi
 // ********************************************************************
 // TimeDiff
 // ********************************************************************
 
 /// <summary>
 /// Returns the number of days between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum DayDifference(Tdate td1, Tdate td2)
 {
     return ApplyFcnToTimeline<Tnum>(x => CoreDayDiff(x), td1, td2);
 }    
コード例 #25
0
        //*********************************************************************
        // TEMPORAL "STEP" FUNCTIONS
        //*********************************************************************

        /// <summary>
        /// Returns the number of intervals since a given date (step up function)
        /// (e.g. 1 2 3 4 5 6 7 8 9 ...)
        /// </summary>
        public static Tnum IntervalsSince(Tdate start, Tdate end, IntervalType interval)
        {
            return(IntervalsSince(start, end, interval, 0));
        }
コード例 #26
0
ファイル: Tdate.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the number of weeks between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum WeekDifference(Tdate td1, Tdate td2)
 {
     return (DayDifference(td1, td2) / 7).RoundToNearest(0.001);
 }
コード例 #27
0
ファイル: Misc.cs プロジェクト: mkpace/hammurabi
 /// <summary>
 /// Returns the number of days between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum DayDiff(Tdate td1, Tdate td2)
 {
     return(Tdate.DayDifference(td1, td2));
 }
コード例 #28
0
ファイル: Tdate.cs プロジェクト: mpoulshock/hammurabi
 // TODO: Add MonthDiff and QuarterDiff functions
 
 /// <summary>
 /// Returns the number of years between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum YearDifference(Tdate td1, Tdate td2)
 {
     return ApplyFcnToTimeline<Tnum>(x => YearDiffRec(x), td1, td2);;
 }
コード例 #29
0
ファイル: Misc.cs プロジェクト: mkpace/hammurabi
 /// <summary>
 /// Returns the number of years (accurate to three decimal places) between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum YearDiff(Tdate td1, Tdate td2)
 {
     return(Tdate.YearDifference(td1, td2));
 }
コード例 #30
0
ファイル: Tset.cs プロジェクト: mkpace/hammurabi
 /// <summary>
 /// Returns the members of the set at a specified point in time.
 /// </summary>
 public Tset AsOf(Tdate dt)
 {
     return(this.AsOf <Tset>(dt));
 }
コード例 #31
0
ファイル: Tbool.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Determines whether this instance is ever true during a specified time period.
 /// </summary>
 public Tbool IsEverTrue(Tdate start, Tdate end)
 {
     Tbool equalsVal = this == true; 
     
     Tbool isDuringInterval = Time.IsBetween(start, end);
     
     Tbool isOverlap = equalsVal & isDuringInterval;
     
     return isOverlap.IsEverTrue();
 }
コード例 #32
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));
        }
コード例 #33
0
        public static Tnum IntervalsUntil(Tdate startDate, Tdate endDate, IntervalType interval, int startAt)
        {
            // Handle unknowns
            Hstate top = PrecedingState(startDate.FirstValue, endDate.FirstValue);
            if (top != Hstate.Known) return new Tnum(new Hval(null,top));

            DateTime start = startDate.ToDateTime;
            DateTime end = endDate.ToDateTime;

            Tnum result = new Tnum();

            DateTime indexDate = end;
            int indexNumber = startAt-1;

            while (indexDate > start)
            {
                if (indexNumber != startAt-1)
                {
                    result.AddState(indexDate,Convert.ToString(indexNumber));
                }
                indexNumber++;
                indexDate = indexDate.SubtractInterval(interval);
            }

            result.AddState(Time.DawnOf, 0);
            result.AddState(start,Convert.ToString(indexNumber));
            result.AddState(end, 0);

            return result;
        }
コード例 #34
0
ファイル: Tstr.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the value of a Tstr at a specified point in time. 
 /// </summary>
 public Tstr AsOf(Tdate dt)
 {
     return this.AsOf<Tstr>(dt);
 }
コード例 #35
0
 /// <summary>
 /// Maps a function to a timeline, starting on a given date.
 /// </summary>
 //  TODO: Get rid of Time.IntervalType
 public static Tnum TemporalMap(Func<Tnum,Tnum> fcn, Tdate startDate, Tnum intervalCount, Time.IntervalType intervalType)
 {
     return fcn(Time.IntervalsSince(startDate, startDate.AddYears(intervalCount), intervalType));
 }
コード例 #36
0
ファイル: Tset.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the members of the set at a specified point in time. 
 /// </summary>
 public Tset AsOf(Tdate dt)
 {
     return this.AsOf<Tset>(dt);
 }
コード例 #37
0
 /// <summary>
 /// Returns a Tbool that's true during a specified time interval (including
 /// at the "start"), and otherwise false (including at the moment represented
 /// by the "end").
 /// </summary>
 public static Tbool IsBetween(Tdate start, Tdate end)
 {
     return(IsAtOrAfter(start) && IsBefore(end));
 }
コード例 #38
0
ファイル: Absolute time.cs プロジェクト: mpoulshock/hammurabi
        /// <summary>
        /// Returns a Tbool that's true up to a specified DateTime, and false
        /// at and after it.
        /// </summary>
        public static Tbool IsBefore(Tdate dt)
        {
            // Handle unknowns
            if (!dt.FirstValue.IsKnown)
            {
                return new Tbool(dt.FirstValue);
            }

            // Create boolean
            Tbool result = new Tbool();

            if (dt == DawnOf)
            {
                result.AddState(DawnOf, false);
            }
            else
            {
                result.AddState(DawnOf, true);
                result.AddState(dt.ToDateTime, false);
            }
            return result;
        }
コード例 #39
0
ファイル: Misc.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the number of years (accurate to three decimal places) between the DateTimes in two Tdates.
 /// </summary>
 public static Tnum YearDiff(Tdate td1, Tdate td2)
 {
     return Tdate.YearDifference(td1,td2);
 }
コード例 #40
0
ファイル: Elapsed time.cs プロジェクト: mpoulshock/hammurabi
        /// <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);
        }
コード例 #41
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);
        }
コード例 #42
0
ファイル: Tnum.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns the value of the Tnum at a specified point in time.
 /// </summary>
 public Tnum AsOf(Tdate dt)
 {
     return this.AsOf<Tnum>(dt);
 }
コード例 #43
0
 /// <summary>
 /// Maps a function to a timeline, starting on a given date.
 /// </summary>
 //  TODO: Get rid of Time.IntervalType
 public static Tnum TemporalMap(Func <Tnum, Tnum> fcn, Tdate startDate, Tnum intervalCount, Time.IntervalType intervalType)
 {
     return(fcn(Time.IntervalsSince(startDate, startDate.AddYears(intervalCount), intervalType)));
 }
コード例 #44
0
ファイル: Absolute time.cs プロジェクト: mpoulshock/hammurabi
 /// <summary>
 /// Returns a Tbool that's true during a specified time interval (including
 /// at the "start"), and otherwise false (including at the moment represented 
 /// by the "end").
 /// </summary>
 public static Tbool IsBetween(Tdate start, Tdate end)
 {
     return IsAtOrAfter(start) && IsBefore(end);
 }
コード例 #45
0
 /// <summary>
 /// Returns the value of a Tbool at a specified point in time.
 /// </summary>
 public Tbool AsOf(Tdate dt)
 {
     return(this.AsOf <Tbool>(dt));
 }
コード例 #46
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));
        }