def get_2months_chart(self, width, height): today = datetime.today().date() start_date = today - timedelta(days=today.weekday(), weeks=7) ideas = {} for item in self.get_ideas_count_day_by_day(start_date): week_number = item.date.isocalendar()[1] ideas.setdefault(week_number, 0) ideas[week_number] += item.count connections = {} for item in self.get_connection_count_day_by_day(start_date): week_number = item.date.isocalendar()[1] connections.setdefault(week_number, 0) connections[week_number] += item.count # last 2 months labels week_numbers = [(start_date + timedelta(weeks=n)).isocalendar()[1] for n in range(0, 8)] data = [(ideas.get(item, 0), connections.get(item, 0)) for item in week_numbers] labels = [u'%s %s' % (_(u'week'), n) for n in week_numbers] legend_labels = [_(u'Ideas count'), _(u'Connections count')] chart = DoubleHorizontalLineChart(labels, zip(*data), width=width, height=height, legend=True, legendlabels=legend_labels) return chart.get_png()
def get_2weeks_chart(self, width, height): start_date = datetime.today().date() - timedelta(days=14) ideas = {} for item in self.get_ideas_count_day_by_day(start_date): ideas[item.formatted_date] = item.count connections = {} for item in self.get_connection_count_day_by_day(start_date): connections[item.formatted_date] = item.count labels = [ format_date(start_date + timedelta(days=days), format="short") for days in range(0, 14) ] data = [(ideas.get(item, 0), connections.get(item, 0)) for item in labels] legend_labels = [_(u'Ideas count'), _(u'Connections count')] chart = DoubleHorizontalLineChart(labels, zip(*data), width=width, height=height, legend=True, legendlabels=legend_labels) return chart.get_png()
def get_2weeks_chart(self, width, height): start_date = datetime.today().date() - timedelta(days=14) ideas = {} for item in self.get_ideas_count_day_by_day(start_date): ideas[item.formatted_date] = item.count connections = {} for item in self.get_connection_count_day_by_day(start_date): connections[item.formatted_date] = item.count labels = [ format_date(start_date + timedelta(days=days), format="short") for days in range(0, 14)] data = [(ideas.get(item, 0), connections.get(item, 0)) for item in labels] legend_labels = [_(u'Ideas count'), _(u'Connections count')] chart = DoubleHorizontalLineChart(labels, zip(*data), width=width, height=height, legend=True, legendlabels=legend_labels) return chart.get_png()