def open_timeline(self, begin, end): """ open a new time line in the table """ self._timeline_days = list(date_range(begin, end, self._timestep)) days = list(date_range(begin, end, oneDay)) #days = [d for d in days if d.day_of_week-5 < 0] self._timeline_all_days = days self.view_begin = begin self.view_end = end
def activity_timeline(self, activities, resource): """write a day for a task""" task = activities[0][3] for day in date_range(self.view_begin, self.view_end): available = resource.is_available(day) bgcolor = self.set_bg_color(day, available) #draw backgrgound self._handler.draw_rect(self._x, self._y, self._daywidth, ROW_HEIGHT, fillcolor=bgcolor) for d in range(self.factor): day_ = day + oneHour * d * (HOURS_PER_DAY / self.factor) if day_.hour >= 12: day_ += oneHour for begin, end, _, _, usage, _ in activities: if begin <= day_ < end: if usage > 1: log.info(" usage", usage, "for", resource.id, "on", day) break self._activity_timeline(available, usage, day, d) self._activity_timeline(False, 0, day, d) self.draw_separator_resources() # update abscisse self._x += self._daywidth
def occupation_timeline(self, project, resource): """ write a timeline day for a resource occupation """ for day in date_range(self.view_begin, self.view_end): # draw background self._handler.draw_rect( self._x, self._y, self._daywidth, ROW_HEIGHT, fillcolor=self._colors['EVEN_SET']['RESOURCE_UNAVAILABLE']) for d in range(self.factor): day_ = day + oneHour * d * (HOURS_PER_DAY / self.factor) if day_.hour >= 12: day_ += oneHour act = project.activities.select('resource', resource.id) if act: act = act.select('begin', day_) usage = project.get_total_usage(resource.id, day_) available = resource.is_available(day_) and \ (day_ < self.view_end) and usage and act self._occupation_timeline(available, 1. / self.factor, day_, d) if usage > 1: log.info(" Warning! usage", usage, "for", resource.id, "on", day_) #draw separators self.draw_separator_resources() # update abscisse self._x += self._daywidth
def milestone_timeline(self, day, milestone, project): """ Iterate over each day to draw corresponding milestone """ self._ctask = milestone last_day = day + self._timestep begin, end = project.get_task_date_range(milestone) assert begin == end for day in date_range(day, last_day): draw = (day == begin) self._milestone_timeline(day, draw, project.factor)
def draw_timeline(self): """ Format time line according to time step """ for day in list(date_range(self.view_begin, self.view_end)): # timestep == week if self._timestep == 7 and day.day_of_week == 0: date = str(day.iso_week[1]) self._draw_text("s%s" % date) #timestep == month elif self._timestep == 13 and day.day == 1: date = str("%02d" % day.month) self._draw_text(date) # timestep == day elif self._timestep == 1: date = day.strftime('%m-%d') self._draw_text(date) if self._timestep == 30: step = float(day.days_in_month) else: step = float(self._timestep) self._x += self._timestepwidth / step
def _milestone_timeline(self, day, draw, factor): """ Effectively draw a milestone """ # background color if day.date == TODAY.date: bgcolor = self._color_set['TODAY'] elif day.day_of_week in (5, 6): bgcolor = self._color_set['WEEKEND'] else: bgcolor = self._color_set['WEEKDAY'] width = self._daywidth first_day = self._timeline_days[0] last_day = self._timeline_days[-1] + self._timestep rnge = list(date_range(first_day, last_day)) self._handler.draw_rect(self._x, self._y, max(width, 0), ROW_HEIGHT, fillcolor=bgcolor) self.draw_separator_gantt(self._x, self._y, self._y, rnge=[day]) # draw milestone as diamond if draw: x, y = self._x, self._y self._tasks_slots.setdefault(self._ctask, []).append((x, y)) self._handler.draw_poly( ( (x + (width - 1) / factor, y + ROW_HEIGHT / 2), # right (x + width / (2 * factor), y + ROW_HEIGHT * 3 / 4), # top (x + 1, y + ROW_HEIGHT / 2), # left (x + width / (2 * factor), y + ROW_HEIGHT / 4)), # bottom fillcolor=self._colors['CONSTRAINT']) # record position self._x += width