def _get_old_unhelpful():
 old_formatted = {}
 cursor = connection.cursor()
 cursor.execute('SELECT doc_id, yes, no\n        FROM\n            (SELECT wiki_revision.document_id as doc_id,\n                SUM(limitedvotes.helpful) as yes,\n                SUM(NOT(limitedvotes.helpful)) as no\n            FROM\n                (SELECT * FROM wiki_helpfulvote\n                    WHERE created <= DATE_SUB(CURDATE(), INTERVAL 1 WEEK)\n                    AND created >= DATE_SUB(DATE_SUB(CURDATE(),\n                        INTERVAL 1 WEEK), INTERVAL 1 WEEK)\n                ) as limitedvotes\n            INNER JOIN wiki_revision ON\n                limitedvotes.revision_id=wiki_revision.id\n            INNER JOIN wiki_document ON\n                wiki_document.id=wiki_revision.document_id\n            WHERE wiki_document.locale="en-US"\n            GROUP BY doc_id\n            HAVING no > yes\n            ) as calculated')
 old_data = cursor.fetchall()
 for data in old_data:
  doc_id = data[0]
  yes = float(data[1])
  no = float(data[2])
  total = (yes + no)
  if (total == 0):
   continue
  old_formatted[doc_id] = {'total': total, 'percentage': (yes / total)}
 return old_formatted

def _get_old_unhelpful ( ) : old_formatted = { } cursor = connection . cursor ( ) cursor . execute ( 'SELECT doc_id, yes, no\n        FROM\n            (SELECT wiki_revision.document_id as doc_id,\n                SUM(limitedvotes.helpful) as yes,\n                SUM(NOT(limitedvotes.helpful)) as no\n            FROM\n                (SELECT * FROM wiki_helpfulvote\n                    WHERE created <= DATE_SUB(CURDATE(), INTERVAL 1 WEEK)\n                    AND created >= DATE_SUB(DATE_SUB(CURDATE(),\n                        INTERVAL 1 WEEK), INTERVAL 1 WEEK)\n                ) as limitedvotes\n            INNER JOIN wiki_revision ON\n                limitedvotes.revision_id=wiki_revision.id\n            INNER JOIN wiki_document ON\n                wiki_document.id=wiki_revision.document_id\n            WHERE wiki_document.locale="en-US"\n            GROUP BY doc_id\n            HAVING no > yes\n            ) as calculated' ) old_data = cursor . fetchall ( ) for data in old_data : doc_id = data [ 0 ] yes = float ( data [ 1 ] ) no = float ( data [ 2 ] ) total = ( yes + no ) if ( total == 0 ) : continue old_formatted [ doc_id ] = { 'total' : total , 'percentage' : ( yes / total ) } return old_formatted
gets the data from 2 weeks ago and formats it as output so that we can get a percent change .