def process(self, chart): self.min_date = datetime.date.max self.max_date = datetime.date.min self.tasks_by_owners = {} self.owners_by_pools = {} self.left_offset = 0 for task in chart.tasks: LOGGER.debug("Processing %s" % task) # Min & Max dates if task.from_date < self.min_date: self.min_date = task.from_date if task.till_date > self.max_date: self.max_date = task.till_date # Users & users' tasks owner = task.owner if owner not in self.tasks_by_owners: self.tasks_by_owners[owner] = {} if task.from_date not in self.tasks_by_owners[owner]: self.tasks_by_owners[owner][task.from_date] = [] self.tasks_by_owners[owner][task.from_date].append(task) # Pools if task.pool not in self.owners_by_pools: self.owners_by_pools[task.pool] = [] if owner not in self.owners_by_pools[task.pool]: self.owners_by_pools[task.pool].append(owner) o = self.font.getsize(owner)[0] if o > self.left_offset: self.left_offset = o # Getting chart height self.height = chart.get_height(self) self._init_image(Image.new("RGBA", (self.width, self.height), "#FFFFFF")) self.active_width = self.width - self.left_offset - 30 self.box(20 + self.left_offset, 18, self.active_width, self.height - 90, "#808080") days = [] d = self.min_date while d <= self.max_date: if d.weekday() not in [5, 6]: days.append(d) d += datetime.timedelta(days=1) self.coords = {} self.day_length = self.active_width / float(len(days)) for i in range(0, len(days)): self.coords[days[i]] = int(i * self.day_length) visible = 1 while visible * self.day_length < 20: visible += 1 for i in range(0, int(math.ceil(len(days) / float(visible)))): self.milestone(days[i * visible], "#808080" if not i else "#F0F0F0", "#808080") today = self.de_weekend(datetime.date.today()) self.milestone(today, "#FF0000", "#FF0000") chart.draw(self) output = StringIO.StringIO() self.image.save(output, "PNG") data = output.getvalue() output.close() return data
def init_chart(): dom.create('canvas', 'my-chart', '#ui') dom.attr('#my-chart', 'width', 500) dom.attr('#my-chart', 'height', 300) return chart.draw('#my-chart', option)
def process(self, chart): self.min_date = datetime.date.max self.max_date = datetime.date.min self.tasks_by_owners = {} self.owners_by_pools = {} self.left_offset = 0 for task in chart.tasks: LOGGER.debug("Processing %s" % task) # Min & Max dates if task.from_date < self.min_date: self.min_date = task.from_date if task.till_date > self.max_date: self.max_date = task.till_date # Users & users' tasks owner = task.owner if owner not in self.tasks_by_owners: self.tasks_by_owners[owner] = {} if task.from_date not in self.tasks_by_owners[owner]: self.tasks_by_owners[owner][task.from_date] = [] self.tasks_by_owners[owner][task.from_date].append(task) # Pools if task.pool not in self.owners_by_pools: self.owners_by_pools[task.pool] = [] if owner not in self.owners_by_pools[task.pool]: self.owners_by_pools[task.pool].append(owner) o = self.font.getsize(owner)[0] if o > self.left_offset: self.left_offset = o # Getting chart height self.height = chart.get_height(self) self._init_image( Image.new("RGBA", (self.width, self.height), "#FFFFFF")) self.active_width = self.width - self.left_offset - 30 self.box(20 + self.left_offset, 18, self.active_width, self.height - 90, "#808080") days = [] d = self.min_date while d <= self.max_date: if d.weekday() not in [5, 6]: days.append(d) d += datetime.timedelta(days=1) self.coords = {} self.day_length = self.active_width / float(len(days)) for i in range(0, len(days)): self.coords[days[i]] = int(i * self.day_length) visible = 1 while visible * self.day_length < 20: visible += 1 for i in range(0, int(math.ceil(len(days) / float(visible)))): self.milestone(days[i * visible], "#808080" if not i else "#F0F0F0", "#808080") today = self.de_weekend(datetime.date.today()) self.milestone(today, "#FF0000", "#FF0000") chart.draw(self) output = StringIO.StringIO() self.image.save(output, "PNG") data = output.getvalue() output.close() return data
if __name__ == "__main__": # Benötigte Variablen definieren # 1. f = Funktion # 2. i = Interval [a, b] # n = Anzahl der betrachteten Trapeze # e = Epsilon f = lambda x: math.e**(-(x - 2)**2 / 0.05) + math.e**(-( x - 5)**2 / 0.1) + 0.1 * x - math.e**(-(x - 3.5)**2 / 0.1) i = (1, 7) n = 10 e = 0.001 # 3. Funktion darstellen, wird unter "graphics/function.svg" gespeichert # Die Anzahl der verwendeten Datenpunkte wird auf 1000 gesetzt, damit eine # ausreichend genaue Funktion entsteht chart.draw(f, i[0], i[1], 1000) chart.save("Graph", "graphics/graph.svg") chart.reset() # 5. Das Integral der Funktion f im Interval [a, b] mit n = 10 gleichgroßen # Teilintervallen berechnen trapez_int = integrate.trapezoidal(f, i[0], i[1], 10) print("Integral Trapezregel (optimiert):", round(trapez_int, 5)) # Funktion darstellen, wird unter "graphics/trapezoidal.svg" gespeichert chart.draw(f, i[0], i[1], 10, dots=True, graph_name="Trapezregel",
import chart if __name__ == "__main__": # this is executed when invoked as a script print("hello John, welcome to the matrix") chart.draw()