update_records.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #coding:utf-8
  2. import os
  3. import time
  4. import datetime
  5. import sys
  6. import django
  7. from django.core.cache import cache
  8. from django.db import connection
  9. sys.path.append('/mnt/wzbapi/src')
  10. os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
  11. django.setup()
  12. import common.models as cm
  13. def update_records():
  14. """
  15. """
  16. prset = cm.PlayerRecord.objects.filter(stock_date="2022-05-09")
  17. for index,pr in enumerate(prset):
  18. player_id = pr.player_id
  19. match_id = pr.match_id
  20. match_group = pr.match_group
  21. yesterday = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id,match_group=match_group,stock_date="2022-05-06").first()
  22. if yesterday:
  23. pr.yesterday_fund = yesterday.today_fund
  24. pr.yesterday_stock = yesterday.today_stock
  25. pr.yesterday_stock_img = yesterday.today_stock_img
  26. #
  27. init_fund = pr.init_fund
  28. today_fund = pr.today_fund
  29. yesterday_fund = pr.yesterday_fund
  30. today_income = (today_fund - yesterday_fund)/float(yesterday_fund)
  31. total_income = (today_fund - init_fund)/float(init_fund)
  32. pr.today_income = round(today_income,4)
  33. pr.total_income = round(total_income,4)
  34. pr.save()
  35. if __name__ == "__main__":
  36. print "start update group rank..."
  37. st = time.time()
  38. update_records()
  39. print "time cost:",time.time()-st