#coding:utf-8 import os import time import datetime import sys import django from django.core.cache import cache from django.db import connection sys.path.append('/mnt/wzbapi/src') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' django.setup() import common.models as cm def update_records(): """ """ prset = cm.PlayerRecord.objects.filter(stock_date="2022-05-09") for index,pr in enumerate(prset): player_id = pr.player_id match_id = pr.match_id match_group = pr.match_group yesterday = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id,match_group=match_group,stock_date="2022-05-06").first() if yesterday: pr.yesterday_fund = yesterday.today_fund pr.yesterday_stock = yesterday.today_stock pr.yesterday_stock_img = yesterday.today_stock_img # init_fund = pr.init_fund today_fund = pr.today_fund yesterday_fund = pr.yesterday_fund today_income = (today_fund - yesterday_fund)/float(yesterday_fund) total_income = (today_fund - init_fund)/float(init_fund) pr.today_income = round(today_income,4) pr.total_income = round(total_income,4) pr.save() if __name__ == "__main__": print "start update group rank..." st = time.time() update_records() print "time cost:",time.time()-st