def _get_current_unhelpful(old_formatted):
 final = {}
 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                ) 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')
 current_data = cursor.fetchall()
 for data in current_data:
  doc_id = data[0]
  yes = float(data[1])
  no = float(data[2])
  total = (yes + no)
  if (total == 0):
   continue
  percentage = (yes / total)
  if (doc_id in old_formatted):
   final[doc_id] = {'total': total, 'currperc': percentage, 'diffperc': (percentage - old_formatted[doc_id]['percentage'])}
  else:
   final[doc_id] = {'total': total, 'currperc': percentage, 'diffperc': 0.0}
 return final

def _get_current_unhelpful ( old_formatted ) : final = { } 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                ) 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' ) current_data = cursor . fetchall ( ) for data in current_data : doc_id = data [ 0 ] yes = float ( data [ 1 ] ) no = float ( data [ 2 ] ) total = ( yes + no ) if ( total == 0 ) : continue percentage = ( yes / total ) if ( doc_id in old_formatted ) : final [ doc_id ] = { 'total' : total , 'currperc' : percentage , 'diffperc' : ( percentage - old_formatted [ doc_id ] [ 'percentage' ] ) } else : final [ doc_id ] = { 'total' : total , 'currperc' : percentage , 'diffperc' : 0.0 } return final
gets the data for the past week and formats it as return value .