def _get_trunc_func( self, subject: str, period: str ) -> Tuple[Union[TruncHour, TruncDay, TruncWeek, TruncMonth], str]: if period == "Hour": fields = """ FLOOR(DATE_PART('day', first_date - %s) * 24 + DATE_PART('hour', first_date - %s)) AS first_date, FLOOR(DATE_PART('day', event_date - first_date) * 24 + DATE_PART('hour', event_date - first_date)) AS date, """ return TruncHour(subject), fields elif period == "Day": fields = """ FLOOR(DATE_PART('day', first_date - %s)) AS first_date, FLOOR(DATE_PART('day', event_date - first_date)) AS date, """ return TruncDay(subject), fields elif period == "Week": fields = """ FLOOR(DATE_PART('day', first_date - %s) / 7) AS first_date, FLOOR(DATE_PART('day', event_date - first_date) / 7) AS date, """ return TruncWeek(subject), fields elif period == "Month": fields = """ FLOOR((DATE_PART('year', first_date) - DATE_PART('year', %s)) * 12 + DATE_PART('month', first_date) - DATE_PART('month', %s)) AS first_date, FLOOR((DATE_PART('year', event_date) - DATE_PART('year', first_date)) * 12 + DATE_PART('month', event_date) - DATE_PART('month', first_date)) AS date, """ return TruncMonth(subject), fields else: raise ValidationError(f"Period {period} is unsupported.")
def _determineTrunc( subject: str, period: str ) -> Union[TruncHour, TruncDay, TruncWeek, TruncMonth]: if period == "Hour": return TruncHour(subject) elif period == "Day": return TruncDay(subject) elif period == "Week": return TruncWeek(subject) elif period == "Month": return TruncMonth(subject) else: raise ValueError(f"Period {period} is unsupported.")
def trunc_func( self, field_name: str ) -> Union[TruncHour, TruncDay, TruncWeek, TruncMonth]: if self.interval == "hour": return TruncHour(field_name) elif self.interval == "day": return TruncDay(field_name) elif self.interval == "week": return TruncWeek(field_name) elif self.interval == "month": return TruncMonth(field_name) else: raise ValidationError(f"{self.interval} not supported")