Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/reports/utils.py

Issue 8625042: Reports - user usefullness (Closed)
Patch Set: Reports - user usefulness Created Oct. 19, 2012, 12:54 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/reports/utils.py
===================================================================
--- a/sitescripts/reports/utils.py
+++ b/sitescripts/reports/utils.py
@@ -5,7 +5,7 @@
# http://mozilla.org/MPL/2.0/.
import hashlib, hmac, base64, MySQLdb, os, re, marshal, subprocess
-from sitescripts.utils import get_config, cached, get_template, sendMail
+from sitescripts.utils import get_config, memoize, cached, get_template, sendMail
def getReportSubscriptions(guid):
cursor = get_db().cursor(MySQLdb.cursors.DictCursor)
@@ -59,7 +59,7 @@
reportData['hasscreenshot'] = 0
del reportData['screenshot']
knownIssues = len(reportData.get('knownIssues', []))
- contact = getUserId(reportData.get('email', None)) if reportData.get('email', None) else None
+ contact = getUserId(reportData.get('email', None)) if 'email' in reportData else None
Wladimir Palant 2012/10/22 13:32:52 If 'email' in reportData is True then it means tha
Andrey Novikov 2012/10/23 14:15:29 Done.
dumpstr = marshal.dumps(reportData)
if contact != None and isNew:
@@ -111,6 +111,47 @@
if os.path.isfile(file):
os.remove(file)
+@memoize
+def getUserUsefulnessScore(contact):
+ if contact == None:
+ return 0
+
+ cursor = get_db().cursor()
+ executeQuery(cursor,
+ '''SELECT ((positive + 1.9208) / (positive + negative)
+ - 1.96 * SQRT((positive * negative) / (positive + negative) + 0.9604) / (positive + negative))
+ / (1 + 3.8416 / (positive + negative)) AS score FROM #PFX#users WHERE id = %s''',
+ (contact))
Wladimir Palant 2012/10/22 13:32:52 Please add a link to the source of this formula.
Andrey Novikov 2012/10/23 14:15:29 Done.
+ user = cursor.fetchone()
Wladimir Palant 2012/10/22 13:32:52 You are selecting the score, not the user - please
Andrey Novikov 2012/10/23 14:15:29 Done.
+ if user == None:
+ return 0
+
+ if user[0] == None: # no score yet
+ return 0.3
+ else:
+ return user[0]
Wladimir Palant 2012/10/22 13:32:52 How about returning |4 * user[0]| here? We want th
Andrey Novikov 2012/10/23 14:15:29 Done.
+
+def updateUserUsefulness(contact, newusefulness, oldusefulness):
+ new = int(newusefulness)
+ old = int(oldusefulness)
+ if new == old:
+ return
+ positive = 0
+ negative = 0
+ if old > 0:
+ positive -= 1
+ elif old < 0:
+ negative -= 1
+ if new > 0:
+ positive += 1
+ elif new < 0:
+ negative += 1
+ cursor = get_db().cursor()
+ executeQuery(cursor,
+ '''UPDATE #PFX#users SET negative = negative + %s, positive = positive + %s WHERE id = %s''',
+ (negative, positive, contact))
+ get_db().commit()
+
def saveScreenshot(guid, screenshot):
prefix = 'data:image/png;base64,'
if not screenshot.startswith(prefix):

Powered by Google App Engine
This is Rietveld