Exemplo n.º 1
0
 public Filter(bool exclude, FieldIndex fieldIndex, TimeLength value, FilterTest test)
 {
     Exclude_ = exclude;
     FieldIndex_ = fieldIndex;
     Value_ = value.TotalMinutes;
     Test_ = test;
 }
Exemplo n.º 2
0
        public int DurationInSeconds()
        {
            var minSecs = TimeLength.Split(':');

            return(int.Parse(minSecs[0]) * 60 + int.Parse(minSecs[1]));
        }
Exemplo n.º 3
0
 internal FixedDurationStationHandler(TimeLength ts, bool turnAround)
 {
     duration        = ts;
     this.turnAround = turnAround;
 }
Exemplo n.º 4
0
            public void ClearComputation()
            {
                // classes indexed by day
                ClassesByDay_ = new OrderedList<Session>[7];
                for (int i = 0; i < 7; i++)
                    ClassesByDay_[i] = new OrderedList<Session>();

                TimeAtUni_ = new TimeLength(0, 0);
                TimeInClasses_ = new TimeLength(0, 0);
                TimeInBreaks_ = new TimeLength(0, 0);
                Days_ = 0;

                MinDayLength_ = new TimeLength(24, 0);
                MaxDayLength_ = new TimeLength(0, 0);
                AverageDayLength_ = new TimeLength(0, 0);

                ShortBreak_ = new TimeLength(24, 0);
                LongBreak_ = new TimeLength(0, 0);
                AverageBreak_ = new TimeLength(0, 0);
                NumberBreaks_ = 0;

                ShortBlock_ = new TimeLength(24, 0);
                LongBlock_ = new TimeLength(0, 0);
                AverageBlock_ = new TimeLength(0, 0);
                NumberBlocks_ = 0;

                EarlyStart_ = TimeOfDay.Maximum;
                LateStart_ = TimeOfDay.Minimum;
                AverageStart_ = TimeOfDay.Minimum;

                EarlyEnd_ = TimeOfDay.Maximum;
                LateEnd_ = TimeOfDay.Minimum;
                AverageEnd_ = TimeOfDay.Minimum;

                TotalStart_ = new TimeLength(0);
                TotalEnd_ = new TimeLength(0);
            }
Exemplo n.º 5
0
 private void registerClock()
 {
     World.world.clock.registerOneShot(
         new ClockHandler(clockHandler),
         TimeLength.random(TimeLength.fromDays(14), TimeLength.fromDays(28)));
 }
Exemplo n.º 6
0
 private void registerTimer(TimeLength time)
 {
     WorldDefinition.World.Clock.registerOneShot(new ClockHandler(clockHandler), time);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Schedule a new game in the future.
 /// </summary>
 private void scheduleNewGame(TimeLength timeToGame)
 {
     futureGames.Add(new Game(this, timeToGame));
 }
Exemplo n.º 8
0
 public DebtEx(long corpus, double interest, TimeLength unitPeriod, Time due, AccountGenre genre) :
     base(corpus, interest, unitPeriod, due, genre)
 {
     initialze();
 }
Exemplo n.º 9
0
 private Rectangle TimeLengthRectangle(TimeLength t)
 {
     return(new Rectangle(0, 0, CellSize.Width, (int)(t.TotalMinutes / 60.0f * CellSize.Height)));
 }
Exemplo n.º 10
0
 protected void initialize()
 {
     minInterestRate = bank.GetDepositInterest(TimeLength.fromMinutes(Time.YEAR));
     manager.spend(_corpus, genre);
 }
Exemplo n.º 11
0
 public FixedDeposit(long corpus, double interest, TimeLength unitPeriod, Time due, AccountGenre genre) :
     base(corpus, interest, unitPeriod, due, genre)
 {
     initialize();
 }
Exemplo n.º 12
0
 public Game(StadiumStructure _stadium, TimeLength _time)
     : this(_stadium, OpponentTeam.drawRandom(), _time)
 {
 }
Exemplo n.º 13
0
            public bool AddStream(Stream stream)
            {
                // if the stream clashes with another stream
                if (!Fits(stream))
                    return false;

                // add to list of streams
                Combination_.Add(stream);

                // run through list of classes
                foreach (Session session in stream.Classes)
                {
                    // increase total time spent in classes
                    TimeInClasses_ += session.Length;

                    // if we're adding the class to an empty day
                    if (ClassesByDay_[session.Day].Count == 0)
                    {
                        // increment day count
                        Days_++;
                        // add start and ending times to totals
                        TotalStart_ += new TimeLength(session.StartTime.DayMinutes);
                        TotalEnd_ += new TimeLength(session.EndTime.DayMinutes);

                        // add length to total time at uni
                        TimeAtUni_ += session.Length;
                    }
                    else
                    {
                        // if it's earlier than the earliest class of that day
                        if (session.StartTime < ClassesByDay_[session.Day][0].StartTime)
                        {
                            TimeLength difference = ClassesByDay_[session.Day][0].StartTime - session.StartTime;
                            // remove the difference for total start
                            TotalStart_ -= difference;
                            // add the difference for total time at uni
                            TimeAtUni_ += difference;
                        }
                        // if it's later than the latest class
                        if (session.EndTime > ClassesByDay_[session.Day][ClassesByDay_[session.Day].Count - 1].EndTime)
                        {
                            TimeLength difference = session.EndTime - ClassesByDay_[session.Day][ClassesByDay_[session.Day].Count - 1].EndTime;
                            // add the difference for total end
                            TotalEnd_ += difference;
                            // add the difference for total time at uni
                            TimeAtUni_ += difference;
                        }
                    }
                    // update average day length
                    AverageDayLength_ = TimeAtUni_ / Days_;

                    // add new classes to day-indexed list
                    ClassesByDay_[session.Day].Add(session);
                    //ClassesByDay_[session.Day].Sort();

                    // check class start/end times against maxima/minima
                    if (session.StartTime < EarlyStart_)
                        EarlyStart_ = session.StartTime;
                    if (session.StartTime > LateStart_)
                        LateStart_ = session.StartTime;
                    if (session.EndTime < EarlyEnd_)
                        EarlyEnd_ = session.EndTime;
                    if (session.EndTime > LateEnd_)
                        LateEnd_ = session.EndTime;

                    // check day length
                    TimeLength dayLength = ClassesByDay_[session.Day][ClassesByDay_[session.Day].Count - 1].EndTime -
                        ClassesByDay_[session.Day][0].StartTime;
                    if (dayLength < MinDayLength_)
                        MinDayLength_ = dayLength;
                    if (dayLength > MaxDayLength_)
                        MaxDayLength_ = dayLength;
                }

                // clear break data
                NumberBreaks_ = 0;
                AverageBreak_ = new TimeLength(0, 0);
                ShortBreak_ = new TimeLength(24, 0);
                LongBreak_ = new TimeLength(0, 0);
                TimeInBreaks_ = new TimeLength(0, 0);
                // clear block data
                NumberBlocks_ = 0;
                AverageBlock_ = new TimeLength(0, 0);
                ShortBlock_ = new TimeLength(24, 0);
                LongBlock_ = new TimeLength(0, 0);
                // TODO: rewrite to avoid full sweep?
                // do a fresh sweep of all days to rebuild break/block data
                foreach (List<Session> daySessions in ClassesByDay_)
                {
                    // empty day - skip
                    if (daySessions.Count == 0)
                        continue;

                    // set up data for the start of the block
                    TimeOfDay blockStart = daySessions[0].StartTime;
                    TimeLength blockLength, breakLength;

                    // compare adjacent classes
                    int i;
                    for (i = 1; i < daySessions.Count; i++)
                    {
                        breakLength = daySessions[i].StartTime - daySessions[i - 1].EndTime;

                        // if there is at least ~15 minutes between the classes, call it a break, otherwise skip
                        if (breakLength.TotalMinutes < MinBreak)
                            continue;

                        // find block length
                        blockLength = daySessions[i - 1].EndTime - blockStart;

                        // increment number of blocks
                        NumberBlocks_++;
                        // add block length to cumulative sum
                        AverageBlock_ += blockLength;
                        // set start of next block
                        blockStart = daySessions[i].StartTime;

                        // compare block against maxima/minima
                        if (blockLength < ShortBlock_)
                            ShortBlock_ = blockLength;
                        if (blockLength > LongBlock_)
                            LongBlock_ = blockLength;

                        // increment number of breaks
                        NumberBreaks_++;
                        // add break to cumulative sum
                        TimeInBreaks_ += breakLength;

                        // compare break length against maxima/minima
                        if (breakLength < ShortBreak_)
                            ShortBreak_ = breakLength;
                        // check if it's the longest break so far
                        if (breakLength > LongBreak_)
                            LongBreak_ = breakLength;
                    }

                    // also create a block at the end
                    // find block length
                    blockLength = daySessions[i - 1].EndTime - blockStart;
                    // compare block against maxima/minima
                    if (blockLength < ShortBlock_)
                        ShortBlock_ = blockLength;
                    if (blockLength > LongBlock_)
                        LongBlock_ = blockLength;
                    // increment number of blocks
                    NumberBlocks_++;
                    // add block length to cumulative sum
                    AverageBlock_ += blockLength;
                }

                if (NumberBreaks_ > 0)
                {
                    // divide the sum of breaks to find the mean
                    AverageBreak_ = TimeInBreaks_ / NumberBreaks_;
                }

                // divide the sum of blocks to find the mean
                AverageBlock_ /= NumberBlocks_;

                AverageStart_ = new TimeOfDay(TotalStart_.TotalMinutes / Days_);
                AverageEnd_ = new TimeOfDay(TotalEnd_.TotalMinutes / Days_);

                return true;
            }
Exemplo n.º 14
0
            public bool ReCompute()
            {
                ClearComputation();

                // check if each stream fits with the other streams
                /*for (int i = 0; i < Combination_.Count; i++)
                {
                    for (int j = i + 1; j < Combination_.Count; j++)
                    {
                        if (Timetable_.LookupClashTable(Combination_[i], Combination_[j]))
                            return false;
                    }
                }*/

                // for each stream
                foreach (Stream stream in Combination_)
                {
                    // for each session in each stream
                    foreach (Session session in stream.Classes)
                    {
                        // build day-indexed list of classes
                        ClassesByDay_[session.Day].Add(session);
                        // calculate total time spent in classes
                        TimeInClasses_ += session.Length;
                    }
                }

                // for each day of classes
                foreach (List<Session> daySessions in ClassesByDay_)
                {
                    // empty day - skip
                    if (daySessions.Count == 0)
                        continue;
                    // otherwise increment day count
                    Days_++;

                    #region Breaks and blocks

                    // set up data for the start of the block
                    TimeOfDay blockStart = daySessions[0].StartTime;
                    TimeLength blockLength, breakLength;

                    // compare adjacent classes
                    int i;
                    for (i = 1; i < daySessions.Count; i++)
                    {
                        breakLength = daySessions[i].StartTime - daySessions[i - 1].EndTime;

                        // if there is at least ~15 minutes between the classes, call it a break, otherwise skip
                        if (breakLength.TotalMinutes < MinBreak)
                            continue;

                        // find block length
                        blockLength = daySessions[i - 1].EndTime - blockStart;

                        // increment number of blocks
                        NumberBlocks_++;
                        // add block length to cumulative sum
                        AverageBlock_ += blockLength;
                        // set start of next block
                        blockStart = daySessions[i].StartTime;

                        // compare block against maxima/minima
                        if (blockLength < ShortBlock_)
                            ShortBlock_ = blockLength;
                        if (blockLength > LongBlock_)
                            LongBlock_ = blockLength;

                        // increment number of breaks
                        NumberBreaks_++;
                        // add break to cumulative sum
                        TimeInBreaks_ += breakLength;

                        // compare break length against maxima/minima
                        if (breakLength < ShortBreak_)
                            ShortBreak_ = breakLength;
                        // check if it's the longest break so far
                        if (breakLength > LongBreak_)
                            LongBreak_ = breakLength;
                    }

                    // also create a block at the end
                    // find block length
                    blockLength = daySessions[i - 1].EndTime - blockStart;
                    // compare block against maxima/minima
                    if (blockLength < ShortBlock_)
                        ShortBlock_ = blockLength;
                    if (blockLength > LongBlock_)
                        LongBlock_ = blockLength;
                    // increment number of blocks
                    NumberBlocks_++;
                    // add block length to cumulative sum
                    AverageBlock_ += blockLength;

                    #endregion

                    TimeOfDay dayStart = daySessions[0].StartTime;
                    TimeOfDay dayEnd = daySessions[i - 1].EndTime;

                    TimeLength dayLength = dayEnd - dayStart;
                    // add to total time at uni
                    TimeAtUni_ += dayLength;
                    // check max/min
                    if (dayLength > MaxDayLength_)
                        MaxDayLength_ = dayLength;
                    if (dayLength < MinDayLength_)
                        MinDayLength_ = dayLength;

                    // add to total time for start and end
                    TotalStart_.TotalMinutes += dayStart.DayMinutes;
                    TotalEnd_.TotalMinutes += dayEnd.DayMinutes;

                    // check start/end min/max
                    if (dayStart < EarlyStart_)
                        EarlyStart_ = dayStart;
                    if (dayStart > LateStart_)
                        LateStart_ = dayStart;
                    if (dayEnd < EarlyEnd_)
                        EarlyEnd_ = dayEnd;
                    if (dayEnd > LateEnd_)
                        LateEnd_ = dayEnd;
                }

                // calculate averages using totals and counts
                if (NumberBreaks_ > 0)
                    AverageBreak_ = TimeInBreaks_ / NumberBreaks_;
                AverageBlock_ /= NumberBlocks_;
                AverageStart_ = new TimeOfDay(TotalStart_.TotalMinutes / Days_);
                AverageEnd_ = new TimeOfDay(TotalEnd_.TotalMinutes / Days_);
                AverageDayLength_ = TimeAtUni_ / Days_;



                /*
                // process all the streams
                foreach (Stream stream in Combination_)
                {
                    // run through list of classes
                    foreach (Session session in stream.Classes)
                    {
                        // increase total time spent in classes
                        TimeInClasses_ += session.Length;

                        // if we're adding the class to an empty day
                        if (ClassesByDay_[session.Day].Count == 0)
                        {
                            // increment day count
                            Days_++;
                            // add start and ending times to totals
                            TotalStart_ += new TimeLength(session.Start.TotalMinutes);
                            TotalEnd_ += new TimeLength(session.End.TotalMinutes);

                            // add length to total time at uni
                            TimeAtUni_ += session.Length;
                        }
                        else
                        {
                            // if it's earlier than the earliest class of that day
                            if (session.Start < ClassesByDay_[session.Day][0].Start)
                            {
                                TimeLength difference = ClassesByDay_[session.Day][0].Start - session.Start;
                                // remove the difference for total start
                                TotalStart_ -= difference;
                                // add the difference for total time at uni
                                TimeAtUni_ += difference;
                            }
                            // if it's later than the latest class
                            if (session.End > ClassesByDay_[session.Day][ClassesByDay_[session.Day].Count - 1].End)
                            {
                                TimeLength difference = session.End - ClassesByDay_[session.Day][ClassesByDay_[session.Day].Count - 1].End;
                                // add the difference for total end
                                TotalStart_ += difference;
                                // add the difference for total time at uni
                                TimeAtUni_ += difference;
                            }
                        }
                        // update average day length
                        AverageDayLength_ = TimeAtUni_ / Days_;

                        // add new classes to day-indexed list
                        ClassesByDay_[session.Day].Add(session);
                        ClassesByDay_[session.Day].Sort();

                        // check class start/end times against maxima/minima
                        if (session.Start < EarlyStart_)
                            EarlyStart_ = session.Start;
                        if (session.Start > LateStart_)
                            LateStart_ = session.Start;
                        if (session.End < EarlyEnd_)
                            EarlyEnd_ = session.End;
                        if (session.End > LateEnd_)
                            LateEnd_ = session.End;

                        // check day length
                        TimeLength dayLength = ClassesByDay_[session.Day][ClassesByDay_[session.Day].Count - 1].End -
                            ClassesByDay_[session.Day][0].Start;
                        if (dayLength < MinDayLength_)
                            MinDayLength_ = dayLength;
                        if (dayLength > MaxDayLength_)
                            MaxDayLength_ = dayLength;
                    }
                }

                // clear break data
                NumberBreaks_ = 0;
                AverageBreak_ = new TimeLength(0, 0);
                ShortBreak_ = new TimeLength(24, 0);
                LongBreak_ = new TimeLength(0, 0);
                TimeInBreaks_ = new TimeLength(0, 0);
                // clear block data
                NumberBlocks_ = 0;
                AverageBlock_ = new TimeLength(0, 0);
                ShortBlock_ = new TimeLength(24, 0);
                LongBlock_ = new TimeLength(0, 0);
                // TODO: rewrite to avoid full sweep?
                // do a fresh sweep of all days to rebuild break/block data
                foreach (List<Session> daySessions in ClassesByDay_)
                {
                    // set up data for the start of the block
                    TimeOfDay blockStart;
                    if (daySessions.Count > 0)
                        blockStart = daySessions[0].Start;
                    else
                        blockStart = new TimeOfDay();

                    // compare adjacent classes
                    for (int i = 1; i < daySessions.Count; i++)
                    {
                        TimeLength breakLength = daySessions[i].Start - daySessions[i - 1].End;

                        // if there's a break between classes, make a block
                        if (breakLength.TotalMinutes >= MinBreak)
                        {
                            // find block length
                            TimeLength blockLength = daySessions[i - 1].End - blockStart;
                            // compare block against maxima/minima
                            if (blockLength < ShortBlock_)
                                ShortBlock_ = blockLength;
                            if (blockLength > LongBlock_)
                                LongBlock_ = blockLength;

                            // increment number of blocks
                            NumberBlocks_++;
                            // add block length to cumulative sum
                            AverageBlock_ += blockLength;
                            // set start of next block
                            blockStart = daySessions[i].Start;
                        }
                        // also create a block at the end
                        if (i == daySessions.Count - 1)
                        {
                            // find block length
                            TimeLength blockLength = daySessions[i].End - blockStart;
                            // compare block against maxima/minima
                            if (blockLength < ShortBlock_)
                                ShortBlock_ = blockLength;
                            if (blockLength > LongBlock_)
                                LongBlock_ = blockLength;

                            // increment number of blocks
                            NumberBlocks_++;
                            // add block length to cumulative sum
                            AverageBlock_ += blockLength;
                        }

                        // if there is at least ~15 minutes between the classes, call it a break, otherwise skip
                        if (breakLength.TotalMinutes < MinBreak)
                            continue;

                        // increment number of breaks
                        NumberBreaks_++;
                        // add break to cumulative sum
                        TimeInBreaks_ += breakLength;

                        // compare break length against maxima/minima
                        if (breakLength < ShortBreak_)
                            ShortBreak_ = breakLength;
                        // check if it's the longest break so far
                        if (breakLength > LongBreak_)
                            LongBreak_ = breakLength;
                    }
                }
                // divide the sum of breaks to find the mean
                AverageBreak_ = TimeInBreaks_ / NumberBreaks_;
                // divide the sum of blocks to find the mean
                AverageBlock_ /= NumberBlocks_;*/

                return true;
            }
Exemplo n.º 15
0
        /// <summary>
        /// Creates a new station object with its left-top corner at
        /// the specified location.
        /// </summary>
        /// <param name="_type">
        /// Type of the station to be built.
        /// </param>
        /// <param name="wloc"></param>
        public Station(StationContribution _type, WorldLocator wloc)
            : base(_type, wloc)
        {
            this.type  = _type;
            this._name = string.Format("ST{0,2:d}", iota++);
            if (wloc.world == WorldDefinition.World)
            {
                WorldDefinition.World.Stations.add(this);
                WorldDefinition.World.Clock.registerRepeated(new ClockHandler(clockHandlerHour), TimeLength.fromHours(1));
                WorldDefinition.World.Clock.registerRepeated(new ClockHandler(clockHandlerDay), TimeLength.fromHours(24));
            }
            Distance r = new Distance(REACH_RANGE, REACH_RANGE, REACH_RANGE);

            // advertise listeners in the neighborhood that a new station is available
            foreach (IEntity e in Cube.CreateInclusive(baseLocation - r, baseLocation + r).GetEntities())
            {
                IStationListener l = (IStationListener)e.QueryInterface(typeof(IStationListener));
                if (l != null)
                {
                    l.advertiseStation(this);
                }
            }
        }
Exemplo n.º 16
0
        protected override void OnDragOver(DragEventArgs drgevent)
        {
            var time = FindClickTime(PointToClient(new Point(drgevent.X, drgevent.Y)));

            // outside of table bounds?
            if (ReferenceEquals(time, null))
            {
                // clear current preview (at edge of timetable)
                EndPreviewStream();
                // cannot drag outside of the actual table
                drgevent.Effect = DragDropEffects.None;
                return;
            }

            // dragging a class
            if (drgevent.Data.GetDataPresent(typeof(Session)) || drgevent.Data.GetDataPresent(typeof(Type)))
            {
                drgevent.Effect = DragDropEffects.Move;
                Type dragType;
                if (drgevent.Data.GetDataPresent(typeof(Session)))
                {
                    dragType = ((Session)drgevent.Data.GetData(typeof(Session))).Stream.Type;
                }
                else
                {
                    dragType = (Type)drgevent.Data.GetData(typeof(Type));
                }

                var session = Timetable.From(dragType).FindClassAt(time, false);
                if (session == null)
                {
                    EndPreviewStream();
                }
                else
                {
                    PreviewEquiv(session.Stream);
                }
            }
            // dragging an unavailability
            else if (drgevent.Data.GetDataPresent(typeof(Unavailability)))
            {
                var dragUnavail = (Unavailability)drgevent.Data.GetData(typeof(Unavailability));
                var offset      = new TimeLength(dragUnavail.StartMinute);
                var start       = time - dragUnavail.Length / 2;
                start -= offset;
                start.RoundToNearestHour();
                start += offset;

                _hoverUnavail = new Timeslot(start.Day, start, (start as TimeOfDay) + dragUnavail.Length);
                if (_hoverUnavail.StartTime < new TimeOfDay(_hourStart, 0) ||
                    _hoverUnavail.EndTime > new TimeOfDay(_hourEnd, 0))
                {
                    drgevent.Effect = DragDropEffects.None;
                    _hoverUnavail   = null;
                }
                else
                {
                    drgevent.Effect = DragDropEffects.Move;
                }
                Invalidate();
            }
            else
            {
                base.OnDragOver(drgevent);
            }
        }
Exemplo n.º 17
0
            public bool AddStream(Stream stream)
            {
                // if the stream clashes with another stream
                if (!Fits(stream))
                {
                    return(false);
                }

                // add to list of streams
                Streams.Add(stream);

                // run through list of classes
                foreach (Session session in stream.Classes)
                {
                    // increase total time spent in classes
                    TimeInClasses += session.Length;

                    // if we're adding the class to an empty day
                    if (_classesByDay[session.Day].Count == 0)
                    {
                        // increment day count
                        Days++;
                        // add start and ending times to totals
                        _totalStart += new TimeLength(session.StartTime.DayMinutes);
                        _totalEnd   += new TimeLength(session.EndTime.DayMinutes);

                        // add length to total time at uni
                        TimeAtUni += session.Length;
                    }
                    else
                    {
                        // if it's earlier than the earliest class of that day
                        if (session.StartTime < _classesByDay[session.Day][0].StartTime)
                        {
                            TimeLength difference = _classesByDay[session.Day][0].StartTime - session.StartTime;
                            // remove the difference for total start
                            _totalStart -= difference;
                            // add the difference for total time at uni
                            TimeAtUni += difference;
                        }
                        // if it's later than the latest class
                        if (session.EndTime > _classesByDay[session.Day][_classesByDay[session.Day].Count - 1].EndTime)
                        {
                            TimeLength difference = session.EndTime -
                                                    _classesByDay[session.Day][_classesByDay[session.Day].Count - 1]
                                                    .EndTime;
                            // add the difference for total end
                            _totalEnd += difference;
                            // add the difference for total time at uni
                            TimeAtUni += difference;
                        }
                    }
                    // update average day length
                    AverageDayLength = TimeAtUni / Days;

                    // add new classes to day-indexed list
                    _classesByDay[session.Day].Add(session);
                    //ClassesByDay_[session.Day].Sort();

                    // check class start/end times against maxima/minima
                    if (session.StartTime < EarlyStart)
                    {
                        EarlyStart = session.StartTime;
                    }
                    if (session.StartTime > LateStart)
                    {
                        LateStart = session.StartTime;
                    }
                    if (session.EndTime < EarlyEnd)
                    {
                        EarlyEnd = session.EndTime;
                    }
                    if (session.EndTime > LateEnd)
                    {
                        LateEnd = session.EndTime;
                    }

                    // check day length
                    TimeLength dayLength = _classesByDay[session.Day][_classesByDay[session.Day].Count - 1].EndTime -
                                           _classesByDay[session.Day][0].StartTime;
                    if (dayLength < MinDayLength)
                    {
                        MinDayLength = dayLength;
                    }
                    if (dayLength > MaxDayLength)
                    {
                        MaxDayLength = dayLength;
                    }
                }

                // clear break data
                NumberBreaks = 0;
                AverageBreak = new TimeLength(0, 0);
                ShortBreak   = new TimeLength(24, 0);
                LongBreak    = new TimeLength(0, 0);
                TimeInBreaks = new TimeLength(0, 0);
                // clear block data
                NumberBlocks = 0;
                AverageBlock = new TimeLength(0, 0);
                ShortBlock   = new TimeLength(24, 0);
                LongBlock    = new TimeLength(0, 0);
                // TODO: rewrite to avoid full sweep?
                // do a fresh sweep of all days to rebuild break/block data
                foreach (List <Session> daySessions in _classesByDay)
                {
                    // empty day - skip
                    if (daySessions.Count == 0)
                    {
                        continue;
                    }

                    int i;
                    CompareAdjacent(daySessions, out i);
                }

                if (NumberBreaks > 0)
                {
                    // divide the sum of breaks to find the mean
                    AverageBreak = TimeInBreaks / NumberBreaks;
                }

                // divide the sum of blocks to find the mean
                AverageBlock /= NumberBlocks;

                AverageStart = new TimeOfDay(_totalStart.TotalMinutes / Days);
                AverageEnd   = new TimeOfDay(_totalEnd.TotalMinutes / Days);

                return(true);
            }
Exemplo n.º 18
0
 private void registerTimer(TimeLength time)
 {
     World.world.clock.registerOneShot(new ClockHandler(clockHandler), time);
 }
Exemplo n.º 19
0
 protected void initialze()
 {
     manager.earn(_corpus, genre);
     clock.registerOneShot(new ClockHandler(warningBeforeDue), due - clock + TimeLength.fromDays(-30));
 }
Exemplo n.º 20
0
 public Rectangle TimeLengthRectangle(TimeLength t)
 {
     return new Rectangle(0, 0, Cell_.Width, (int)(t.TotalMinutes / 60.0f * Cell_.Height));
 }
Exemplo n.º 21
0
 private void registerTimer()
 {
     registerTimer(TimeLength.fromMinutes(type.MinutesPerVoxel));
 }
Exemplo n.º 22
0
        protected override void OnDragOver(DragEventArgs drgevent)
        {
            TimeOfWeek time = FindClickTime(PointToClient(new Point(drgevent.X, drgevent.Y)));
            // outside of table bounds?
            if (TimeOfWeek.ReferenceEquals(time, null))
            {
                // clear current preview (at edge of timetable)
                EndPreviewStream();
                // cannot drag outside of the actual table
                drgevent.Effect = DragDropEffects.None;
                return;
            }

            // dragging a class
            if (drgevent.Data.GetDataPresent(typeof(Session)) || drgevent.Data.GetDataPresent(typeof(Type)))
            {
                drgevent.Effect = DragDropEffects.Move;
                Type dragType;
                if (drgevent.Data.GetDataPresent(typeof(Session)))
                    dragType = ((Session)drgevent.Data.GetData(typeof(Session))).Stream.Type;
                else
                    dragType = (Type)drgevent.Data.GetData(typeof(Type));

                Session session = Timetable.From(dragType).FindClassAt(time, false);
                if (session == null)
                {
                    EndPreviewStream();
                }
                else
                {
                    PreviewEquiv(session.Stream);
                }
            }
            // dragging an unavailability
            else if (drgevent.Data.GetDataPresent(typeof(Unavailability)))
            {
                Unavailability dragUnavail = (Unavailability)drgevent.Data.GetData(typeof(Unavailability));
                TimeLength offset = new TimeLength(dragUnavail.StartMinute);
                TimeOfWeek start = time - dragUnavail.Length / 2;
                start -= offset;
                start.RoundToNearestHour();
                start += offset;

                HoverUnavail_ = new Timeslot(start.Day, (TimeOfDay)start, (TimeOfDay)start + dragUnavail.Length);
                if (HoverUnavail_.StartTime < new TimeOfDay(HourStart_, 0) || HoverUnavail_.EndTime > new TimeOfDay(HourEnd_, 0))
                {
                    drgevent.Effect = DragDropEffects.None;
                    HoverUnavail_ = null;
                }
                else
                {
                    drgevent.Effect = DragDropEffects.Move;
                }
                Invalidate();
            }
            else
            {
                base.OnDragOver(drgevent);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Clock event handler.
        /// </summary>
        public void clockHandler()
        {
            Debug.Assert(isPlaced);     // we should have unregistered the handler when the train was removed.

            CarState.Inside ins = head.State.asInside();
            if (ins != null)
            { // this car might need to stop
                TimeLength time = ins.voxel.railRoad.getStopTimeSpan(this, stopCallCount);
                if (time.totalMinutes > 0)
                {
                    stopCallCount++;
                    // a car needs to stop here
                    registerTimer(time);        // resume after the specified time

                    // TODO: see where this train is being stopped. do something if necessary
                    State = TrainStates.StoppingAtStation;
                    return;
                }


                if (time.totalMinutes < 0)
                {
                    reverse();  // turn around
                }
            }

            // this car can now move
            stopCallCount = 0;
            TrainStates s = TrainStates.Moving;

            // determine the next head car state
            CarState next = calcNextTrainCarState[head.State];

            if (next != null)
            {   // if it can move forward
                if (!isBlocked[next])
                {
                    move(next);
                }
                else
                {
                    // otherwise we can't move. emergency stop.
                    s = TrainStates.EmergencyStopping;
                }
            }
            else
            {
                // we can't go forward. turn around
                reverse();
                next = calcNextTrainCarState[head.State];

                if (next != null && !isBlocked[next])
                {
                    move(next);
                }
                else
                {
                    s = TrainStates.EmergencyStopping;
                }
            }
            State = s;  // update the state
            registerTimer();
        }
Exemplo n.º 24
0
 public Cursor DragCursor(TimeLength length, Color color)
 {
     // draw cursor bitmap
     Rectangle r = TimeLengthRectangle(length);
     Bitmap b = new Bitmap(r.Width + 1, r.Height + 1);
     Graphics g = Graphics.FromImage(b);
     g.FillRectangle(
         new SolidBrush(Color.FromArgb(200, color)),
         new Rectangle(0, 0, r.Width, r.Height));
     return new Cursor(b.GetHicon());
 }
Exemplo n.º 25
0
        // Returns interest for deposit (in percent).
        public double GetDepositInterest(TimeLength period)
        {
            long n = period.totalMinutes / Time.YEAR;

            return((double)n / 400);
        }
Exemplo n.º 26
0
            public Solution(Solution other)
            {
                this.Combination_ = new List<Stream>(other.Combination_);
                this.ClassesByDay_ = new OrderedList<Session>[7];
                for (int i = 0; i < 7; i++)
                {
                    ClassesByDay_[i] = new OrderedList<Session>(other.ClassesByDay_[i]);
                    //ClassesByDay_[i] = other.ClassesByDay_[i].Clone();
                }

                this.TimeAtUni_ = other.TimeAtUni_;
                this.TimeInClasses_ = other.TimeInClasses_;
                this.TimeInBreaks_ = other.TimeInBreaks_;
                this.Days_ = other.Days_;

                this.MinDayLength_ = other.MinDayLength_;
                this.MaxDayLength_ = other.MaxDayLength_;
                this.AverageDayLength_ = other.AverageDayLength_;

                this.ShortBreak_ = other.ShortBreak_;
                this.LongBreak_ = other.LongBreak_;
                this.AverageBreak_ = other.AverageBreak_;
                this.NumberBreaks_ = other.NumberBreaks_;

                this.ShortBlock_ = other.ShortBlock_;
                this.LongBlock_ = other.LongBlock_;
                this.AverageBlock_ = other.AverageBlock_;
                this.NumberBlocks_ = other.NumberBlocks_;

                this.EarlyStart_ = other.EarlyStart_;
                this.LateStart_ = other.LateStart_;
                this.AverageStart_ = other.AverageStart_;

                this.EarlyEnd_ = other.EarlyEnd_;
                this.LateEnd_ = other.EarlyEnd_;
                this.AverageEnd_ = other.AverageEnd_;

                this.TotalStart_ = other.TotalStart_;
                this.TotalEnd_ = other.TotalEnd_;
            }