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_month(self): vc = QueryContext("user_table", group_by=['month']) vc.append_column(MonthColumn('date', alias='month')) result = vc.resolve(self.session.connection()) self.assertEquals(result, { 1.0: { 'month': 1.0 }, 2.0: { 'month': 2.0 }, 3.0: { 'month': 3.0 } })
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)