def make_query(code_gen, identifier, accuracy_name, stats_name):
def template(dp, GROUP_NAMES, stats_context, EXPR_NAME):
groups = GROUP_NAMES
QUERY_NAME = (
stats_context.query().group_by(groups).agg(dp.len(), EXPR_NAME).WITH_KEYS
if groups
else stats_context.query().select(EXPR_NAME)
)
STATS_NAME = QUERY_NAME.release().collect()
STATS_NAME # type: ignore
return (
DefaultsTemplate(template)
.fill_values(
GROUP_NAMES=list(code_gen.analysis_plan.groups.keys()),
)
We know whether GROUP_NAMES is going to be empty or not, so we can get rid of the conditional logic inside the template. I generally want to to move conditional logic outside the template, unless it serves a pedagogical purpose, and doesn't make things much more cluttered. I think this fails on both counts.
We know whether
GROUP_NAMESis going to be empty or not, so we can get rid of the conditional logic inside the template. I generally want to to move conditional logic outside the template, unless it serves a pedagogical purpose, and doesn't make things much more cluttered. I think this fails on both counts.