Newer
Older
elif strategy == grade_aggregation_strategy.avg_grade:
return sum(self.valid_percentages)/len(self.valid_percentages)
elif strategy == grade_aggregation_strategy.use_earliest:
return self.valid_percentages[0]
elif strategy == grade_aggregation_strategy.use_latest:
return self.valid_percentages[-1]
else:
raise ValueError(_("invalid grade aggregation strategy '%s'") % strategy)
def stringify_state(self):
if self.state is None:
elif self.state == grade_state_change_types.exempt:
elif self.state == grade_state_change_types.graded:
if self.valid_percentages:
result = "%.1f%%" % self.percentage()
if len(self.valid_percentages) > 1:
result += " (/%d)" % len(self.valid_percentages)
return result
else:
def stringify_machine_readable_state(self):
if self.state is None:
return u"NONE"
elif self.state == grade_state_change_types.exempt:
return "EXEMPT"
elif self.state == grade_state_change_types.graded:
if self.valid_percentages:
return "%.3f" % self.percentage()
else:
return u"NONE"
else:
return u"OTHER_STATE"
def stringify_percentage(self):
if self.state == grade_state_change_types.graded:
if self.valid_percentages:
return "%.1f" % self.percentage()
else:
return u""
else:
return ""
# }}}
# {{{ flow <-> grading integration
def get_flow_grading_opportunity(course, flow_id, flow_desc, grading_rule):
from course.utils import FlowSessionGradingRule
assert isinstance(grading_rule, FlowSessionGradingRule)
gopp, created = GradingOpportunity.objects.get_or_create(
course=course,
identifier=grading_rule.grade_identifier,
defaults=dict(
name="Flow: %s" % flow_desc.title,
aggregation_strategy=grading_rule.grade_aggregation_strategy,
# {{{ XMPP log
class InstantMessage(models.Model):
participation = models.ForeignKey(Participation)
text = models.CharField(max_length=200)
time = models.DateTimeField(default=now)
class Meta:
verbose_name = _("instant message")
verbose_name_plural = _("instant messages")
ordering = ("participation__course", "time")
def __unicode__(self):
return "%s: %s" % (self.participation, self.text)
# }}}
# vim: foldmethod=marker