def get_time_series_by_subgroup(stat: CountStat, table: Type[BaseCount], key_id: int, end_times: List[datetime], subgroup_to_label: Dict[(Optional[str], str)], include_empty_subgroups: bool) -> Dict[(str, List[int])]:
    queryset = table_filtered_to_id(table, key_id).filter(property=stat.property).values_list('subgroup', 'end_time', 'value')
    value_dicts: Dict[(Optional[str], Dict[(datetime, int)])] = defaultdict((lambda : defaultdict(int)))
    for (subgroup, end_time, value) in queryset:
        value_dicts[subgroup][end_time] = value
    value_arrays = {}
    for (subgroup, label) in subgroup_to_label.items():
        if ((subgroup in value_dicts) or include_empty_subgroups):
            value_arrays[label] = [value_dicts[subgroup][end_time] for end_time in end_times]
    if (stat == COUNT_STATS['messages_sent:client:day']):
        return rewrite_client_arrays(value_arrays)
    return value_arrays
def get_time_series_by_subgroup(stat: CountStat, table: Type[BaseCount], key_id: int, end_times: List[datetime], subgroup_to_label: Dict[(Optional[str], str)], include_empty_subgroups: bool) -> Dict[(str, List[int])]:
    queryset = table_filtered_to_id(table, key_id).filter(property=stat.property).values_list('subgroup', 'end_time', 'value')
    value_dicts: Dict[(Optional[str], Dict[(datetime, int)])] = defaultdict((lambda : defaultdict(int)))
    for (subgroup, end_time, value) in queryset:
        value_dicts[subgroup][end_time] = value
    value_arrays = {}
    for (subgroup, label) in subgroup_to_label.items():
        if ((subgroup in value_dicts) or include_empty_subgroups):
            value_arrays[label] = [value_dicts[subgroup][end_time] for end_time in end_times]
    if (stat == COUNT_STATS['messages_sent:client:day']):
        return rewrite_client_arrays(value_arrays)
    return value_arrays