Commits

Owen Nelson  committed 2e235be

adding a util method to get the % of targets that viewed the image or followed the link on a given campaign

  • Participants
  • Parent commits a2026c0

Comments (0)

Files changed (1)

File src/trawler/models.py

                                [recipient])
         msg.send()
 
+    def get_percents(self):
+        """
+        Primitive % calculator for pass/fail.
+        """
+        total = self.targets.count()
+        return dict(link=(float(self.targets.filter(link_followed=True
+                                                    ).count()) / total) * 100,
+                    img=(float(self.targets.filter(image_viewed=True
+                                                     ).count()) / total) * 100)
+
+
     @models.permalink
     def get_absolute_url(self):
         return ('campaign_detail', (), {'pk': self.pk})