本文整理汇总了Python中db.Database.update_scores方法的典型用法代码示例。如果您正苦于以下问题:Python Database.update_scores方法的具体用法?Python Database.update_scores怎么用?Python Database.update_scores使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.update_scores方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_past_votes
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import update_scores [as 别名]
def process_past_votes():
print 'Processing past votes'
Database.db.scores.ensure_index([('image_id', pymongo.ASCENDING)])
Database.db.country_scores.ensure_index([('image_id', pymongo.ASCENDING)])
# votes = Database.db.votes.find({'ip': {'$exists': True}})
votes = Database.db.votes.find()
print votes.count(), 'un-calculated votes found in the DB'
total_vote_count = 0
start_time = time()
gifs_dict = dict([(gif['file_id'], str(gif['_id'])) for gif in Database.db.gifs.find()])
for vote in votes:
total_vote_count += 1
if total_vote_count % 1000 == 0:
print "Processed %s votes in %s" % (total_vote_count, time() - start_time)
start_time = time()
try:
metric = vote['metric']
country = vote.get('country', None)
if vote['choice'] in ['left', 'equal']:
winner_file_id = vote['left']
loser_file_id = vote['right']
else:
winner_file_id = vote['right']
loser_file_id = vote['left']
winner_image_id = gifs_dict[winner_file_id]
loser_image_id = gifs_dict[loser_file_id]
isDraw = vote['choice'] == 'both' or vote['choice'] == 'neither'
update_scores_start = time()
vote_id = vote['_id']
Database.update_scores(metric, winner_image_id, loser_image_id, isDraw, country)
except Exception as e:
print "Error", e
print 'Done processing votes!'