def choose_strip(self, metrics, config): """ Return a tuple (major_strip, minor_strip) for current time period and window size. """ day_period = TimePeriod(self, timeline.BosparanianTime(0, 0), timeline.BosparanianTime(1, 0)) one_day_width = metrics.calc_exact_width(day_period) self.major_strip_is_decade = False if one_day_width > 20000: return (StripHour(), StripMinute()) elif one_day_width > 600: return (StripDay(), StripHour()) elif one_day_width > 60: return (StripMonth(), StripWeekday()) elif one_day_width > 25: return (StripMonth(), StripDay()) elif one_day_width > 10: return (StripMonth(), StripWeek(config)) elif one_day_width > 1.75: return (StripYear(), StripMonth()) elif one_day_width > 0.5: return (StripYear(), StripQuarter()) elif one_day_width > 0.12: self.major_strip_is_decade = True return (StripDecade(), StripYear()) elif one_day_width > 0.012: return (StripCentury(), StripDecade()) else: return (StripCentury(), StripCentury())
def move_period_num_months(period, num): try: delta = num years = abs(delta) / 13 bosparanian_start = BosparanianUtils.from_time(period.start_time) bosparanian_end = BosparanianUtils.from_time(period.end_time) if num < 0: years = -years delta = delta - 13 * years if delta < 0: start_month = bosparanian_start.month + 13 + delta end_month = bosparanian_end.month + 13 + delta if start_month > 13: start_month -= 13 end_month -= 13 if start_month > bosparanian_start.month: years -= 1 else: start_month = bosparanian_start.month + delta end_month = bosparanian_start.month + delta if start_month > 13: start_month -= 13 end_month -= 13 years += 1 start_year = bosparanian_start.year + years end_year = bosparanian_start.year + years start_time = bosparanian_start.replace(year=start_year, month=start_month) end_time = bosparanian_end.replace(year=end_year, month=end_month) return TimePeriod(period.time_type, start_time.to_time(), end_time.to_time()) except ValueError: return None
def _parse_displayed_period(self, text, tmp_dict): start = self._parse_time(tmp_dict.pop("tmp_start")) end = self._parse_time(tmp_dict.pop("tmp_end")) try: self.db.set_displayed_period( TimePeriod(self.db.get_time_type(), start, end)) except PeriodTooLongError: self.db.set_displayed_period( self.db.get_time_type().get_default_time_period())
def _validate_period_length(self): try: start = self.view.GetStart() end = self.view.GetEnd() TimePeriod(self.time_type, start, end) except PeriodTooLongError: msg = _("Entered period is too long.") self.view.DisplayInvalidPeriod(msg) raise ValueError(msg)
def choose_strip(self, metrics, config): start_time = 1 end_time = 2 limit = 30 period = TimePeriod(self, start_time, end_time) period_width = metrics.calc_exact_width(period) while period_width == 0: start_time *= 10 end_time *= 10 limit /= 10 period = TimePeriod(self, start_time, end_time) period_width = metrics.calc_exact_width(period) nbr_of_units = metrics.width / period_width size = 1 while nbr_of_units > limit: size *= 10 nbr_of_units /= 10 return (NumStrip(size * 10), NumStrip(size))
def _get_period(self, t1, t2): if t1 > t2: start = t2 end = t1 else: start = t1 end = t2 return TimePeriod( self.controller.get_timeline().get_time_type(), self.controller.get_drawer().snap(start), self.controller.get_drawer().snap(end))
def __init__(self): self.db = MemoryDB() from timelinelib.time.gregoriantime import GregorianTimeType self.db.time_type = GregorianTimeType() now = GregorianUtils.from_time(self.db.time_type.now()) self.start = self.get_time(now.year, now.month, 1) self.end = self.start + self.get_days_delta(30) self.db.set_displayed_period(TimePeriod(self.db.get_time_type(), self.start, self.end)) self.last_cat = None self.next_cid = 1
def move_period_num_years(period, num): try: delta = num start_year = BosparanianUtils.from_time(period.start_time).year end_year = BosparanianUtils.from_time(period.end_time).year start_time = BosparanianUtils.from_time( period.start_time).replace(year=start_year + delta) end_time = BosparanianUtils.from_time( period.end_time).replace(year=end_year + delta) return TimePeriod(period.time_type, start_time.to_time(), end_time.to_time()) except ValueError: return None
def get_export_periods(self, first_time, last_time): periods = [] current_period = None if self.main_frame.timeline: time_type = self.main_frame.timeline.get_time_type() current_period = self.get_view_properties().displayed_period period_delta = current_period.end_time - current_period.start_time periods.append(current_period) start_time = current_period.start_time period = current_period while first_time < start_time: start_time = period.start_time - period_delta end_time = period.start_time period = TimePeriod(time_type, start_time, end_time) periods.insert(0, period) end_time = current_period.end_time period = current_period while last_time > end_time: start_time = period.end_time end_time = period.end_time + period_delta period = TimePeriod(time_type, start_time, end_time) periods.append(period) return periods, current_period
def fill(strip_list, strip): """Fill the given list with the given strip.""" try: current_start = strip.start( self._view_properties.displayed_period.start_time) while current_start < self._view_properties.displayed_period.end_time: next_start = strip.increment(current_start) strip_list.append( TimePeriod(self._db.get_time_type(), current_start, next_start)) current_start = next_start except: # Exception occurs when major=century and when we are at the end of the calendar pass
def move_period_num_weeks(period, num): delta = delta_from_days(7) * num start_time = period.start_time + delta end_time = period.end_time + delta return TimePeriod(period.time_type, start_time, end_time)
def move_period(period, delta): start_time = period.start_time + delta end_time = period.end_time + delta return TimePeriod(period.time_type, start_time, end_time)