Пример #1
0
 def __init__(self, range, title=None, gradient=None, step=1,
              max_divisions=16, tz_offset=datetime.timedelta(0, 0)):
     def steps(step=None):
         steps = [1, 5, 15, 30, 60,
                  5 * 60, 15 * 60, 30 * 60,
                  3600, 3 * 3600, 6 * 3600, 12 * 3600]
         return itertools.imap(lambda s: datetime.timedelta(0, s),
                               itertools.dropwhile(lambda s: s < step,
                                                   steps))
     lower, upper = range
     if step:
         for step in steps(step):
             lower = util.datetime_floor(range[0], step)
             upper = util.datetime_floor(range[1], step)
             if upper < range[1]:
                 upper += step
             if (upper - lower).seconds / step.seconds < max_divisions:
                 range = (int(time.mktime(lower.timetuple())),
                          int(time.mktime(upper.timetuple())))
                 self.grid_step = '%.1f' % (100.0 * step.seconds
                                            / (upper - lower).seconds)
                 self.step = step
                 break
     Scale.__init__(self, range, title=title, gradient=gradient, step=None)
     self.labels, self.positions = [], []
     t = datetime.datetime(lower.year, lower.month, lower.day, lower.hour) \
         + self.step
     while t < upper:
         self.labels.append((t + tz_offset).strftime('%H:%M'))
         self.positions.append('%1.f' % (100.0 * (t - lower).seconds
                                         / (upper - lower).seconds))
         t += self.step
Пример #2
0
 def make_time_marks_folder(self, globals, step=datetime.timedelta(0, 300)):
     style_url = globals.stock.check_hide_children_style.url()
     folder = kml.Folder(name='Time marks',
                         styleUrl=style_url,
                         visibility=0)
     coord = self.track.coords[0]
     style_url = globals.stock.time_mark_styles[0].url()
     folder.add(self.make_time_mark(globals, coord, coord.dt, style_url))
     dt = util.datetime_floor(self.track.coords[0].dt, step)
     while dt <= self.track.coords[0].dt:
         dt += step
     while dt < self.track.coords[-1].dt:
         coord = self.track.coord_at(dt)
         if dt.minute == 0:
             style_index = 0
         elif dt.minute == 30:
             style_index = 1
         elif dt.minute == 15 or dt.minute == 45:
             style_index = 2
         else:
             style_index = 3
         style_url = globals.stock.time_mark_styles[style_index].url()
         folder.add(self.make_time_mark(globals, coord, dt, style_url))
         dt += step
     coord = self.track.coords[-1]
     style_url = globals.stock.time_mark_styles[0].url()
     folder.add(self.make_time_mark(globals, coord, coord.dt, style_url))
     return folder
Пример #3
0
 def make_time_marks_folder(self, globals, step=datetime.timedelta(0, 300)):
     style_url = globals.stock.check_hide_children_style.url()
     folder = kml.Folder(name='Time marks', styleUrl=style_url, visibility=0)
     coord = self.track.coords[0]
     style_url = globals.stock.time_mark_styles[0].url()
     folder.add(self.make_time_mark(globals, coord, coord.dt, style_url))
     dt = util.datetime_floor(self.track.coords[0].dt, step)
     while dt <= self.track.coords[0].dt:
         dt += step
     while dt < self.track.coords[-1].dt:
         coord = self.track.coord_at(dt)
         if dt.minute == 0:
             style_index = 0
         elif dt.minute == 30:
             style_index = 1
         elif dt.minute == 15 or dt.minute == 45:
             style_index = 2
         else:
             style_index = 3
         style_url = globals.stock.time_mark_styles[style_index].url()
         folder.add(self.make_time_mark(globals, coord, dt, style_url))
         dt += step
     coord = self.track.coords[-1]
     style_url = globals.stock.time_mark_styles[0].url()
     folder.add(self.make_time_mark(globals, coord, coord.dt, style_url))
     return folder
Пример #4
0
    def __init__(self,
                 range,
                 title=None,
                 gradient=None,
                 step=1,
                 max_divisions=16,
                 tz_offset=datetime.timedelta(0, 0)):
        def steps(step=None):
            steps = [
                1, 5, 15, 30, 60, 5 * 60, 15 * 60, 30 * 60, 3600, 3 * 3600,
                6 * 3600, 12 * 3600
            ]
            return itertools.imap(
                lambda s: datetime.timedelta(0, s),
                itertools.dropwhile(lambda s: s < step, steps))

        lower, upper = range
        if step:
            for step in steps(step):
                lower = util.datetime_floor(range[0], step)
                upper = util.datetime_floor(range[1], step)
                if upper < range[1]:
                    upper += step
                if (upper - lower).seconds / step.seconds < max_divisions:
                    range = (int(time.mktime(lower.timetuple())),
                             int(time.mktime(upper.timetuple())))
                    self.grid_step = '%.1f' % (100.0 * step.seconds /
                                               (upper - lower).seconds)
                    self.step = step
                    break
        Scale.__init__(self, range, title=title, gradient=gradient, step=None)
        self.labels, self.positions = [], []
        t = datetime.datetime(lower.year, lower.month, lower.day, lower.hour) \
            + self.step
        while t < upper:
            self.labels.append((t + tz_offset).strftime('%H:%M'))
            self.positions.append('%1.f' % (100.0 * (t - lower).seconds /
                                            (upper - lower).seconds))
            t += self.step