Task #3118
Updated by Yingdi Yu over 8 years ago
This is a draft abstraction for schedule. It consists of two classes. Schedule -------- **Schedule** consists of a set of **RepetitiveIntervals**. Schedule implements WireEncodable and WireDecodable concept to facilitate storage. A schedule contains two sets of RepetitiveIntervals: a white list and a black list. The accessible time intervals of a schedule are those covered by one RepetitiveInterval in the white list but not by any RepetitiveInterval in the black list. Schedule implements WireEncodable and WireDecodable concept to facilitate storage. ### RepetitiveInterval The element object in Schedule. A RepetitiveInterval is a time interval with the repeated pattern. RepetitiveInterval has six properties: startDate, endDate, intervalStartTime, intervalEndTime, repeatUnit, and nRepeats. *startDate* and *endDate* are expressed as date, e.g., "20150822T000000"; *intervalStartTime* and *intervalEndTime* are expressed as a particular hour in a day, i.e., an interval from 0 to 23; *repeatUnit* is either day, month, or year; *nRepeat* x *repeatUnit* is the interval between two repetitions. One can interpret a RepetitiveInterval as: "starting from *startDate*, repeat an interval from *intervalStartTime* to *intervalEndTime* for every (*nRepeat* x *repeatUnit*) until *endDate*. Note that: + *nRepeat* = 0 means no repetition + *endDate* could be infinite + *repeatUnit* = day and *nRepeat* = 7 is equivalent to repetition per week. An example of RepetitiveInterval would look like: + startDate: 20150822T000000 + endDate: 20160822T000000 + intervalStartTime: 16 + intervalEndTime: 18 + repeatUnit: day + nRepeat: 7 RepetitiveInterval also implements WireEncodable and WireDecodable concept to facilitate storage. Interval -------- A simple class which contains a start time and an end time. It is used to as the return value of some member methods of Schedule. Class Interface --------------- class Schedule { public: ///@brief Construct an schedule Schedule(); Schedule(Block& block); public: template<encoding::Tag TAG> size_t wireEncode(EncodingImpl<TAG>& encoder) const; Block wireEncode(); void wireDecode(); ///@brief Add an RepetitiveInterval @p repetitiveInterval into white list Schedule& addWhiteInterval(RepetitiveInterval repetitiveInterval); ///@brief Add the RepetitiveInterval into black list Schedule& addBlackInterval(RepetitiveInterval repetitiveInterval); ///@brief Get the Interval that covers the @p ts Interval getCoveringInterval(const TimePoint& ts); private: std::set<RepetitiveInterval> m_whiteIntervalList; std::set<RepetitiveInterval> m_blackIntervalList; Block m_wire; }; class RepetitiveInterval { public: enum class RepeatUnit{ NONE = 0, DAY = 1, MONTH = 2, YEAR = 3 }; public: RepetitiveInterval(); RepetitiveInterval(Block& block); RepetitiveInterval(TimePoint startDate, TimePoint endDate, Hour intervalStartTime, Hour intervalEndTime, size_t nRepeats = 0, RepeatUnit unit = RepetitiveInterval::NONE); template<encoding::Tag TAG> size_t wireEncode(EncodingImpl<TAG>& encoder) const; Block wireEncode(); void wireDecode(); ///@brief Check if the time point @p ts is covered by the RepetitiveInterval bool covers(TimePoint tp); ///@brief Get the covering interval for time point @p ts Interval getCoveringInterval(TimePoint tp); ///@brief To store in std::set bool operator<(RepetitiveInterval interval) const; private: TimePoint m_startDate; TimePoint m_endDate; Hour m_intervalStartTime; Hour m_intervalEndTime; size_t m_nRepeats = 0; RepeatUnit m_unit; Block m_wire; }; class Interval { public: Interval(TimePoint startTime, TimePoint endTime); bool covers(TimePoint tp); Interval operator&&(Interval interval); private: TimePoint m_startTime; TimePoint m_endTime; };