Permalink
Browse files

Count CAPTCHA success/fail rates in stats.

  • Loading branch information...
chromakode committed Nov 23, 2011
1 parent 6945598 commit 164fe494479ff3b4803ef253498c5ba70c3e2ed5
Showing with 17 additions and 1 deletion.
  1. +3 −1 r2/r2/controllers/validator/validator.py
  2. +14 −0 r2/r2/lib/stats.py
@@ -564,8 +564,10 @@ class VCaptcha(Validator):
def run(self, iden, solution):
if (not c.user_is_loggedin or c.user.needs_captcha()):
- if not captcha.valid_solution(iden, solution):
+ valid_captcha = captcha.valid_solution(iden, solution)
+ if not valid_captcha:
self.set_error(errors.BAD_CAPTCHA)
+ g.stats.action_event_count("captcha", valid_captcha)
class VUser(Validator):
def run(self, password = None):
View
@@ -41,6 +41,20 @@ def get_counter(self, name):
else:
return None
+ def action_count(self, counter_name, name, delta=1):
+ counter = self.get_counter(counter_name)
+ if counter:
+ from pylons import request
+ counter.increment('%s.%s' % (request.environ["pylons.routes_dict"]["action"], name), delta=delta)
+
+ def action_event_count(self, event_name, state=None, delta=1, true_name="success", false_name="fail"):
+ counter_name = 'event.%s' % event_name
+ if state == True:
+ self.action_count(counter_name, true_name, delta=delta)
+ elif state == False:
+ self.action_count(counter_name, false_name, delta=delta)
+ self.action_count(counter_name, 'total', delta=delta)
+
def cache_count(self, name, delta=1):
counter = self.get_counter('cache')
if counter and random.random() < self.CACHE_SAMPLE_RATE:

0 comments on commit 164fe49

Please sign in to comment.