def columns(self): cols = super(TR, self).columns if self.grouping == 'month': cols[0] = AggregateColumn( "Month", combine_month_year, [YearColumn('date', alias='year'), MonthColumn('date', alias='month')], format_fn=format_date) elif self.grouping == 'quarter': cols[0] = AggregateColumn( "Quarter", combine_quarter_year, [YearColumn('date', alias='year'), YearQuarterColumn('date', alias='quarter')], format_fn=format_date) else: cols[0] = DatabaseColumn("Year", YearColumn('date', alias='year'), format_fn=format_year) return cols
def date_column(self): if self.grouping == 'month': return AggregateColumn( "Month", combine_month_year, [ YearColumn('date_reported', alias='year'), MonthColumn('date_reported', alias='month') ], format_fn=format_date) elif self.grouping == 'quarter': return AggregateColumn( "Quarter", combine_quarter_year, [ YearColumn('date_reported', alias='year'), YearQuarterColumn('date_reported', alias='quarter') ], format_fn=format_date) else: return DatabaseColumn("Year", YearColumn('date_reported', alias='year'), format_fn=format_year)
def get_column_config(self, data_source_config, lang): return ColumnConfig(columns=[ AggregateColumn( header=self.get_header(lang), aggregate_fn=lambda year, month: {'year': year, 'month': month}, format_fn=self.get_format_fn(), columns=[ YearColumn(self.field, alias=self._year_column_alias()), MonthColumn(self.field, alias=self._month_column_alias()), ], slug=self.column_id, data_slug=self.column_id, )], )
def test_distinct_on(self): vc = QueryContext( "user_table", distinct_on=['user', 'year'], order_by=[OrderBy('user'), OrderBy('year'), OrderBy('date', is_ascending=False)], group_by=['user', 'date'] ) vc.append_column(SimpleColumn('user')) vc.append_column(YearColumn('date', alias='year')) vc.append_column(SimpleColumn('indicator_a')) result = vc.resolve(self.session.connection()) self.assertEquals(result, { ('user1', datetime.date(2013, 2, 1)): {'user': '******', 'year': 2013.0, 'indicator_a': 3, 'date': datetime.date(2013, 2, 1)}, ('user2', datetime.date(2013, 3, 1)): {'user': '******', 'year': 2013.0, 'indicator_a': 2, 'date': datetime.date(2013, 3, 1)} })
def test_year(self): vc = QueryContext("user_table", group_by=['year']) vc.append_column(YearColumn('date', alias='year')) result = vc.resolve(self.session.connection()) self.assertEquals(result, {2013.0: {'year': 2013.0}})