+ def field_counts(self, answers):
+ for field_desc in self.field_descriptions:
+ field_name, params = field_desc
+ if params['type'] == 'options':
+ field_count = FieldOption.objects.filter(
+ answer__in=list(answers), set__name=params['option_set']).count()
+ else: # text, link
+ field_count = sum(1 for answer in answers if answer.field_values.get(field_name))
+ yield field_name, field_count
+
+ def expert_counts(self):
+ for expert in self.experts.all():
+ assigned_count = self.answer_set.filter(experts=expert).count()
+ marked_count = self.available_answers(expert, marked=True).count()
+ if assigned_count != 0 or marked_count != 0:
+ yield expert, marked_count, assigned_count
+
+ def complete_answers(self):
+ return self.answer_set.filter(complete=True)
+
+ def needing_arbiter(self):
+ return self.answer_set.filter(need_arbiter=True)
+