Skip to content

Commit

Permalink
feat: Refactor CongoSameDiff class to ensure consistent number of var…
Browse files Browse the repository at this point in the history
…iants in each group
  • Loading branch information
drikusroor committed Apr 11, 2024
1 parent 6f3d8a2 commit 1ac94f5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backend/experiment/rules/congosamediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ def validate(self, experiment: Experiment):
# Every non-practice group should have the same number of variants
# that should be labeled with a single uppercase letter
groups = sections.values('group').distinct()
variants_count = sections.exclude(tag__contains='practice').values('tag').distinct().count()
variants = sections.exclude(tag__contains='practice').values('tag')
unique_variants = set([variant['tag'] for variant in variants])
variants_count = len(unique_variants)
for group in groups:
group_variants = sections.filter(group=group['group']).exclude(tag__contains='practice').values('tag').distinct()

Expand All @@ -273,7 +275,9 @@ def validate(self, experiment: Experiment):
errors.append(f'Group {group["group"]} should have variants with a single uppercase letter (A-Z), but has {variant["tag"]}')

if group_variants.count() != variants_count:
errors.append(f'Group {group["group"]} should have the same number of variants as the total amount of variants ({variants_count}) but has {group_variants.count()}')
group_variants_stringified = ', '.join([variant['tag'] for variant in group_variants])
total_variants_stringified = ', '.join(unique_variants)
errors.append(f'Group {group["group"]} should have the same number of variants as the total amount of variants ({variants_count}; {total_variants_stringified}) but has {group_variants.count()} ({group_variants_stringified})')

if errors:
raise ValueError('The experiment playlist is not valid: \n- ' + '\n- '.join(errors))
Expand Down

0 comments on commit 1ac94f5

Please sign in to comment.