def process_table_result( self, resultset: Dict[Tuple[int, int], Dict[str, Any]], filter: RetentionFilter, ): result = [ { "values": [ resultset.get((first_day, day), {"count": 0, "people": []}) for day in range(filter.total_intervals - first_day) ], "label": "{} {}".format(filter.period, first_day), "date": (filter.date_from + RetentionFilter.determine_time_delta(first_day, filter.period)[0]), } for first_day in range(filter.total_intervals) ] return result
def process_table_result( self, resultset: Dict[CohortKey, Dict[str, Any]], filter: RetentionFilter, ): """ Constructs a response for the rest api when there is no breakdown specified We process the non-breakdown case separately from the breakdown case so we can easily maintain compatability from when we didn't have breakdowns. The key difference is that we "zero fill" the cohorts as we want to have a result for each cohort between the specified date range. """ def construct_url(first_day): params = RetentionFilter({ **filter._data, "display": "ActionsTable", "breakdown_values": [first_day] }).to_params() return "/api/person/retention/?" f"{urlencode(params)}" result = [{ "values": [ resultset.get(CohortKey((first_day, ), day), { "count": 0, "people": [] }) for day in range(filter.total_intervals - first_day) ], "label": "{} {}".format(filter.period, first_day), "date": (filter.date_from + RetentionFilter.determine_time_delta( first_day, filter.period)[0]), "people_url": construct_url(first_day), } for first_day in range(filter.total_intervals)] return result