|
|
@@ -23,11 +23,64 @@ from utils.qrcodetool import gen_general_qrcode
|
|
|
from django.db.models import Q,Sum,Count
|
|
|
from PIL import Image
|
|
|
from PIL import Image,ImageDraw,ImageFont
|
|
|
+from django.db import transaction
|
|
|
+from threading import Thread
|
|
|
+#from django.core.cache import cache
|
|
|
+from django.db import connection
|
|
|
|
|
|
import xlrd
|
|
|
import xlwt
|
|
|
from xlutils.copy import copy
|
|
|
from xltpl.writer import BookWriter
|
|
|
+from django_redis import get_redis_connection
|
|
|
+from constants import *
|
|
|
+
|
|
|
+def async(f):
|
|
|
+ def wrapper(*args, **kwargs):
|
|
|
+ thr = Thread(target=f, args=args, kwargs=kwargs)
|
|
|
+ thr.start()
|
|
|
+ return wrapper
|
|
|
+
|
|
|
+
|
|
|
+def get_today_date():
|
|
|
+ if datetime.datetime.now().strftime("%H:%M") < "15:00":
|
|
|
+ if datetime.datetime.now().weekday() in [5,6] or datetime.datetime.now().strftime("%Y-%m-%d") in MISS_DATES:
|
|
|
+ today = cm.PlayerRecord.objects.all().order_by("-stock_date").first().stock_date
|
|
|
+ else:
|
|
|
+ if datetime.datetime.now().weekday()==0:
|
|
|
+ today = (datetime.datetime.now()-datetime.timedelta(days=3)).strftime("%Y-%m-%d")
|
|
|
+ else:
|
|
|
+ today = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
+ else:
|
|
|
+ if datetime.datetime.now().weekday() in [5,6] or datetime.datetime.now().strftime("%Y-%m-%d") in MISS_DATES:
|
|
|
+ today = cm.PlayerRecord.objects.all().order_by("-stock_date").first().stock_date
|
|
|
+ else:
|
|
|
+ today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ return today
|
|
|
+ #return '2021-11-05'
|
|
|
+
|
|
|
+#@async
|
|
|
+def update_group_rank(match_id,match_group,stock_date):
|
|
|
+ #return
|
|
|
+ prset = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,stock_date=stock_date).order_by("-total_income")
|
|
|
+ records = prset.values()
|
|
|
+ case_id = " case id "
|
|
|
+ cases = []
|
|
|
+ where = []
|
|
|
+ for index,pr in enumerate(prset):
|
|
|
+ key = "%s_%s_%s_%s" % (pr.player_id,match_id,match_group,stock_date)
|
|
|
+ record = records[index]
|
|
|
+ record.update({"group_rank":index+1})
|
|
|
+ ccc.cache.delete(key)
|
|
|
+ ccc.pl.set(key,json.dumps(record,cls=ccc.CusJSONEncoder))
|
|
|
+ ccc.pl.execute()
|
|
|
+
|
|
|
+#@ccc.cache_data()
|
|
|
+def get_notices():
|
|
|
+ """
|
|
|
+ """
|
|
|
+ notices = list(cm.Article.objects.filter(status=2).values())
|
|
|
+ return notices
|
|
|
|
|
|
def get_index_data(request):
|
|
|
"""首页数据
|
|
|
@@ -37,20 +90,28 @@ def get_index_data(request):
|
|
|
raise ce.TipException(u"该账号未参加任何赛事!")
|
|
|
player_id = player.id
|
|
|
match_id = player.match_id
|
|
|
- match_name = cm.Match.objects.filter(id=match_id).first().name
|
|
|
- records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
|
|
|
+ match_group = player.match_group
|
|
|
+
|
|
|
+ #if datetime.datetime.now().hour < 15:
|
|
|
+ # today = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
+ #else:
|
|
|
+ # today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ today = get_today_date()
|
|
|
+
|
|
|
+ match_name = get_match_info(match_id).get("name")
|
|
|
+
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id)
|
|
|
if records_set:
|
|
|
- today_record = records_set.first()
|
|
|
- cur_rank = records_set.first().rank
|
|
|
- group_income = get_group_income(today_record.match_id,today_record.match_group)
|
|
|
- if today_record.total_income in group_income:
|
|
|
- cur_rank = group_income.index(today_record.total_income)+1
|
|
|
- else:
|
|
|
- cur_rank = 1
|
|
|
- records = list(records_set.values())[:10]
|
|
|
+ try:
|
|
|
+ cur_rank = get_today_record(player_id,match_id,match_group,today).get("group_rank","")
|
|
|
+ records = list(records_set.order_by("-stock_date").values())
|
|
|
+ except:
|
|
|
+ cur_rank = 0
|
|
|
+ records = []
|
|
|
else:
|
|
|
cur_rank = 0
|
|
|
records = []
|
|
|
+
|
|
|
for item in records:
|
|
|
today_stock = json.loads(item["today_stock"]) if item["today_stock"] else []
|
|
|
today_stock = filter(lambda x:x["name"],today_stock)
|
|
|
@@ -62,7 +123,9 @@ def get_index_data(request):
|
|
|
item["yesterday_stock_img"] = json.loads(item["yesterday_stock_img"]) if item["yesterday_stock_img"] else []
|
|
|
item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
- ret = {"match_name":match_name,"cur_rank":cur_rank,"records":records}
|
|
|
+ #通知
|
|
|
+ notices = get_notices()
|
|
|
+ ret = {"match_name":match_name,"cur_rank":cur_rank,"records":records,"notices":notices}
|
|
|
|
|
|
return ret
|
|
|
|
|
|
@@ -80,11 +143,13 @@ def get_group_income(match_id,match_group):
|
|
|
"""
|
|
|
"""
|
|
|
data = []
|
|
|
- player_ids = list(cm.Player.objects.filter(match_group=match_group).values_list("id",flat=True))
|
|
|
+ today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ player_ids = list(cm.Player.objects.filter(match_id=match_id,match_group=match_group).values_list("id",flat=True))
|
|
|
for player_id in player_ids:
|
|
|
- today_record = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,player_id=player_id).order_by("-stock_date").first()
|
|
|
+ today_record = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,player_id=player_id,stock_date=today).first()
|
|
|
if today_record:
|
|
|
data.append(today_record.total_income)
|
|
|
+ data = list(set(data))
|
|
|
data = sorted(data,key=lambda x:x,reverse=True)
|
|
|
return data
|
|
|
|
|
|
@@ -94,11 +159,13 @@ def get_player_match_detail(request):
|
|
|
"""
|
|
|
qdata = request.json
|
|
|
player_id = request.player.id
|
|
|
+ match_group = request.player.match_group
|
|
|
match_id = qdata.get("id")
|
|
|
record_id = qdata.get("record_id")
|
|
|
if record_id:
|
|
|
records_set = cm.PlayerRecord.objects.filter(id=record_id)
|
|
|
match_id = records_set.first().match_id
|
|
|
+ match_group = records_set.first().match_group
|
|
|
player_id = records_set.first().player_id
|
|
|
records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
|
|
|
else:
|
|
|
@@ -108,11 +175,13 @@ def get_player_match_detail(request):
|
|
|
groups = list(cm.MatchGroup.objects.filter(match_id=match_id).values_list("name",flat=True))
|
|
|
match["groups"] = groups
|
|
|
if records_set:
|
|
|
- today_record = records_set.values().first()
|
|
|
- records = list(records_set.values())[:10]
|
|
|
+ #today_record = records_set.values().first()
|
|
|
+ records = list(records_set.values())
|
|
|
else:
|
|
|
- today_record = {}
|
|
|
+ #today_record = {}
|
|
|
records = []
|
|
|
+ today = get_today_date()
|
|
|
+ today_record = get_today_record(player_id,int(match_id),int(match_group),today)
|
|
|
|
|
|
for item in records:
|
|
|
item["today_stock"] = json.loads(item["today_stock"]) if item["today_stock"] else []
|
|
|
@@ -122,10 +191,6 @@ def get_player_match_detail(request):
|
|
|
item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
if today_record:
|
|
|
- group_income = get_group_income(today_record["match_id"],today_record["match_group"])
|
|
|
- group_rank = group_income.index(today_record["total_income"])+1
|
|
|
- today_record["group_rank"] = group_rank
|
|
|
-
|
|
|
today_record["today_income"] = "{}%".format(today_record["today_income"]*100)
|
|
|
today_record["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
today_record["match_group_name"] = cm.MatchGroup.objects.filter(id=today_record["match_group"]).first().name
|
|
|
@@ -136,87 +201,152 @@ def get_player_match_detail(request):
|
|
|
return ret
|
|
|
|
|
|
|
|
|
-def get_rank_list(request):
|
|
|
- """排名列表
|
|
|
+#@ccc.cache_data()
|
|
|
+#def get_today_record(player_id,match_id,match_group,today):
|
|
|
+# records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id,match_group=match_group,stock_date=today)
|
|
|
+# if records_set:
|
|
|
+# today_record = records_set.values().first()
|
|
|
+# else:
|
|
|
+# today_record = {}
|
|
|
+# return today_record
|
|
|
+
|
|
|
+def get_today_record(player_id,match_id,match_group,today):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ key = "%s_%s_%s_%s" % (player_id,match_id,match_group,today)
|
|
|
+ today_record = ccc.cache.get(key)
|
|
|
+ today_record = json.loads(today_record) if today_record else {}
|
|
|
+ return today_record
|
|
|
+
|
|
|
+@ccc.cache_data()
|
|
|
+def get_match_group_players(match_id,match_group):
|
|
|
+ players = list(cm.Player.objects.filter(match_id=match_id,match_group=match_group).values())
|
|
|
+ return players
|
|
|
+
|
|
|
+#@ccc.cache_data()
|
|
|
+def get_match_groups(match_id):
|
|
|
+ """
|
|
|
"""
|
|
|
- qdata = request.json
|
|
|
- player_id = request.player.id
|
|
|
- match_id = request.player.match_id
|
|
|
match = cm.Match.objects.filter(id=match_id).values().first()
|
|
|
-
|
|
|
- groups = list(cm.MatchGroup.objects.filter(match_id=match_id).values())
|
|
|
+ groups = list(cm.MatchGroup.objects.filter(match_id=match_id,is_active=1).values())
|
|
|
+ return match,groups
|
|
|
+
|
|
|
+#@ccc.cache_data()
|
|
|
+def get_cache_rank_list(player_id,match_id):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ match,groups = get_match_groups(match_id)
|
|
|
+
|
|
|
+ #if datetime.datetime.now().hour < 15:
|
|
|
+ # today = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
+ #else:
|
|
|
+ # today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ today = get_today_date()
|
|
|
|
|
|
for item in groups:
|
|
|
new_players = []
|
|
|
- players = list(cm.Player.objects.filter(match_id=match_id,match_group=item["id"]).values())
|
|
|
+ players = get_match_group_players(match_id,item["id"])
|
|
|
for player in players:
|
|
|
user_id = player["user_id"]
|
|
|
- user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
- username = user.username if user else ""
|
|
|
- records_set = cm.PlayerRecord.objects.filter(player_id=player["id"],match_id=match_id,match_group=item["id"]).order_by("-stock_date")
|
|
|
- if records_set:
|
|
|
- today_record = records_set.values().first()
|
|
|
- else:
|
|
|
- today_record = {}
|
|
|
+ user = get_user_info(user_id)
|
|
|
+ username = user["username"] if user else ""
|
|
|
+
|
|
|
+ player_id = player["id"]
|
|
|
+ match_group = item["id"]
|
|
|
+ today_record = get_today_record(player_id,match_id,match_group,today)
|
|
|
if today_record:
|
|
|
player.update(today_record)
|
|
|
player["username"] = username
|
|
|
player["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
- #计算分组排名
|
|
|
- group_income = get_group_income(today_record["match_id"],today_record["match_group"])
|
|
|
- if today_record["total_income"] in group_income:
|
|
|
- group_rank = group_income.index(today_record["total_income"])+1
|
|
|
- else:
|
|
|
- group_rank = 1
|
|
|
- player["group_rank"] = group_rank
|
|
|
- player["fund"] = round(player["fund"],2)
|
|
|
- player["init_fund"] = round(player["init_fund"],2)
|
|
|
- player["today_fund"] = round(player["today_fund"],2)
|
|
|
+
|
|
|
+ player["fund"] = round(player["fund"],4)
|
|
|
+ player["init_fund"] = round(player["init_fund"],4)
|
|
|
+ player["today_fund"] = round(player["today_fund"],4)
|
|
|
new_players.append(player)
|
|
|
new_players = sorted(new_players,key=lambda x:x["group_rank"])
|
|
|
item["players"] = new_players[:3]
|
|
|
+ return match,groups
|
|
|
+
|
|
|
+
|
|
|
+def get_rank_list(request):
|
|
|
+ """排名列表
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ player_id = request.player.id
|
|
|
+ match_id = request.player.match_id
|
|
|
+ match,groups = get_cache_rank_list(player_id,match_id)
|
|
|
|
|
|
ret = {"match":match,"groups":groups}
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
+@ccc.cache_data()
|
|
|
+def get_user_info(uid):
|
|
|
+ user = cm.UserInfo.objects.filter(id=uid).values().first()
|
|
|
+ return user
|
|
|
+
|
|
|
+@ccc.cache_data()
|
|
|
+def get_match_info(match_id):
|
|
|
+ match = cm.Match.objects.filter(id=match_id).values().first()
|
|
|
+ return match
|
|
|
+
|
|
|
+@ccc.cache_data()
|
|
|
+def get_group_info(group_id):
|
|
|
+ group = cm.MatchGroup.objects.filter(id=group_id).values().first()
|
|
|
+ return group
|
|
|
+
|
|
|
+
|
|
|
def get_group_rank_list(request):
|
|
|
"""排名列表
|
|
|
"""
|
|
|
qdata = request.json
|
|
|
- group_id = qdata.get("id")
|
|
|
+ kwargs = qdata
|
|
|
|
|
|
+ group_id = qdata.get("id")
|
|
|
player_id = request.player.id
|
|
|
match_id = request.player.match_id
|
|
|
- match = cm.Match.objects.filter(id=match_id).values().first()
|
|
|
-
|
|
|
- group = cm.MatchGroup.objects.filter(id=group_id).values().first()
|
|
|
|
|
|
- players = list(cm.Player.objects.filter(match_id=match_id,match_group=group_id).values())
|
|
|
+ match = get_match_info(match_id)
|
|
|
+ group = get_group_info(group_id)
|
|
|
+
|
|
|
+ #if datetime.datetime.now().hour < 15:
|
|
|
+ # today = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
+ #else:
|
|
|
+ # today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+
|
|
|
+ today = get_today_date()
|
|
|
+ #players = list(cm.Player.objects.filter(match_id=match_id,match_group=group_id).values())
|
|
|
+ players = get_match_group_players(match_id,group_id)
|
|
|
new_players = []
|
|
|
for player in players:
|
|
|
user_id = player["user_id"]
|
|
|
- user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
- username = user.username if user else ""
|
|
|
- records_set = cm.PlayerRecord.objects.filter(player_id=player["id"],match_id=match_id,match_group=group_id).order_by("-stock_date")
|
|
|
- if records_set:
|
|
|
- today_record = records_set.values().first()
|
|
|
- else:
|
|
|
- today_record = {}
|
|
|
+ user = get_user_info(user_id)
|
|
|
+ username = user["username"] if user else ""
|
|
|
+
|
|
|
+ player_id = player["id"]
|
|
|
+ match_group = group_id
|
|
|
+ today_record = get_today_record(player_id,match_id,int(match_group),today)
|
|
|
+
|
|
|
if today_record:
|
|
|
player.update(today_record)
|
|
|
- group_income = get_group_income(today_record["match_id"],today_record["match_group"])
|
|
|
- group_rank = group_income.index(today_record["total_income"])+1
|
|
|
- player["group_rank"] = group_rank
|
|
|
player["username"] = username
|
|
|
player["total_income"] = "{}%".format(player["total_income"]*100)
|
|
|
- player["fund"] = round(player["fund"],2)
|
|
|
- player["init_fund"] = round(player["init_fund"],2)
|
|
|
- player["today_fund"] = round(player["today_fund"],2)
|
|
|
+ player["fund"] = round(player["fund"],4)
|
|
|
+ player["init_fund"] = round(player["init_fund"],4)
|
|
|
+ player["today_fund"] = round(player["today_fund"],4)
|
|
|
new_players.append(player)
|
|
|
new_players = sorted(new_players,key=lambda x:x["group_rank"])
|
|
|
- ret = {"group":group,"players":new_players}
|
|
|
+
|
|
|
+ #分页
|
|
|
+ page = int(kwargs.get("page",0))
|
|
|
+ page_size = int(kwargs.get("page_size",20))
|
|
|
+ page_size = 50
|
|
|
+ if page and page_size:
|
|
|
+ total,new_players = ccf.get_page_list(new_players,page,page_size)
|
|
|
+ else:
|
|
|
+ total = len(new_players)
|
|
|
+ ret = {"group":group,"players":new_players,"total":total}
|
|
|
|
|
|
return ret
|
|
|
|
|
|
@@ -237,11 +367,11 @@ def get_player_match_records(request):
|
|
|
data = list(records_set.values())
|
|
|
for item in data:
|
|
|
today_stock = json.loads(item["today_stock"]) if item["today_stock"] else []
|
|
|
- today_stock = filter(lambda x:x["name"],today_stock)
|
|
|
+ today_stock = filter(lambda x:x["name"],today_stock if today_stock else [])
|
|
|
item["today_stock"] = today_stock
|
|
|
item["today_stock_img"] = json.loads(item["today_stock_img"]) if item["today_stock_img"] else []
|
|
|
yesterday_stock = json.loads(item["yesterday_stock"]) if item["yesterday_stock"] else []
|
|
|
- yesterday_stock = filter(lambda x:x["name"],yesterday_stock)
|
|
|
+ yesterday_stock = filter(lambda x:x["name"],yesterday_stock if yesterday_stock else [])
|
|
|
item["yesterday_stock"] = yesterday_stock
|
|
|
item["yesterday_stock_img"] = json.loads(item["yesterday_stock_img"]) if item["yesterday_stock_img"] else []
|
|
|
item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
@@ -275,12 +405,15 @@ def add_model(cls,**kwargs):
|
|
|
raise ce.TipException(u"重复添加选手!")
|
|
|
|
|
|
if model_name == "PlayerRecord":
|
|
|
+ now = datetime.datetime.now()
|
|
|
+ if now.weekday() in [5,6] or now.strftime("%Y-%m-%d") in MISS_DATES:
|
|
|
+ raise ce.TipException(u"今日不能提交数据!")
|
|
|
match_id = kwargs.get("match_id")
|
|
|
stock_date = kwargs.get("stock_date")
|
|
|
today_stock = json.dumps(kwargs.get("today_stock"))
|
|
|
today_stock_img = json.dumps(kwargs.get("today_stock_img"))
|
|
|
player_id = kwargs.get("player_id")
|
|
|
- today_fund = float(kwargs.get("today_fund"))
|
|
|
+ today_fund = float(kwargs.get("today_fund",0))
|
|
|
is_markt = int(kwargs.get("is_markt",0))
|
|
|
|
|
|
player = cm.Player.objects.filter(id=player_id).first()
|
|
|
@@ -296,9 +429,11 @@ def add_model(cls,**kwargs):
|
|
|
now_date = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
if match.end_time < now_date:
|
|
|
raise ce.TipException(u"该比赛已结束!")
|
|
|
+ cm.PlayerRecord.objects.filter(match_id=match_id,player_id=player_id,stock_date=stock_date).delete()
|
|
|
|
|
|
+ #yesterday_date = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
yesterday = cm.PlayerRecord.objects.filter(
|
|
|
- match_id=match_id,player_id=player_id).order_by("-id").first()
|
|
|
+ match_id=match_id,player_id=player_id).order_by("-stock_date").first()
|
|
|
if yesterday:
|
|
|
yesterday_fund = yesterday.today_fund
|
|
|
yesterday_stock = yesterday.today_stock
|
|
|
@@ -309,37 +444,43 @@ def add_model(cls,**kwargs):
|
|
|
yesterday_stock = ""
|
|
|
yesterday_stock_img = ""
|
|
|
yesterday_is_markt = 0
|
|
|
- obj,flag = cm.PlayerRecord.objects.get_or_create(
|
|
|
- player_id=player_id,
|
|
|
- match_id=match_id,
|
|
|
- stock_date=stock_date)
|
|
|
- obj.init_fund = init_fund
|
|
|
- obj.yesterday_fund = yesterday_fund
|
|
|
- obj.yesterday_stock = yesterday_stock
|
|
|
- obj.yesterday_stock_img = yesterday_stock_img
|
|
|
- obj.today_fund = today_fund
|
|
|
- obj.today_stock = today_stock
|
|
|
- obj.today_stock_img = today_stock_img
|
|
|
- obj.user_id = user_id
|
|
|
- obj.username = username
|
|
|
- obj.usercode = usercode
|
|
|
- obj.match_group = match_group
|
|
|
- obj.is_markt = is_markt
|
|
|
- obj.yesterday_is_markt = yesterday_is_markt
|
|
|
- #计算今日和昨日盈亏
|
|
|
- today_income = (today_fund - yesterday_fund)/float(yesterday_fund)
|
|
|
- total_income = (today_fund - init_fund)/float(init_fund)
|
|
|
- obj.today_income = round(today_income,4)
|
|
|
- obj.total_income = round(total_income,4)
|
|
|
- if not flag:
|
|
|
- obj.ctime = datetime.datetime.now()
|
|
|
- obj.save()
|
|
|
- #更新排名
|
|
|
- records_set = cm.PlayerRecord.objects.filter(match_id=match_id).order_by("-total_income")
|
|
|
- for index,item in enumerate(records_set):
|
|
|
- item.rank = index+1
|
|
|
- item.save()
|
|
|
- return obj.id
|
|
|
+ with transaction.atomic():
|
|
|
+ obj,flag = cm.PlayerRecord.objects.get_or_create(
|
|
|
+ player_id=player_id,
|
|
|
+ match_id=match_id,
|
|
|
+ stock_date=stock_date)
|
|
|
+ obj.init_fund = init_fund
|
|
|
+ obj.yesterday_fund = yesterday_fund
|
|
|
+ obj.yesterday_stock = yesterday_stock
|
|
|
+ obj.yesterday_stock_img = yesterday_stock_img
|
|
|
+ obj.today_fund = today_fund
|
|
|
+ obj.today_stock = today_stock
|
|
|
+ obj.today_stock_img = today_stock_img
|
|
|
+ obj.user_id = user_id
|
|
|
+ obj.username = username
|
|
|
+ obj.usercode = usercode
|
|
|
+ obj.match_group = match_group
|
|
|
+ obj.is_markt = is_markt
|
|
|
+ obj.yesterday_is_markt = yesterday_is_markt
|
|
|
+ #计算今日和昨日盈亏
|
|
|
+ if float(today_fund)>9999 or float(today_fund)<=0:
|
|
|
+ raise ce.TipException(u"数据错误,今日净资产不能超过9999万元,不能低于0万元,请仔细核对数据!")
|
|
|
+ today_income = (today_fund - yesterday_fund)/float(yesterday_fund)
|
|
|
+ total_income = (today_fund - init_fund)/float(init_fund)
|
|
|
+
|
|
|
+ if float(today_income)>0.4:
|
|
|
+ raise ce.TipException(u"今日盈利已超过40%,请仔细核对数据或直接联系副主编!")
|
|
|
+
|
|
|
+ obj.today_income = round(today_income,4)
|
|
|
+ obj.total_income = round(total_income,4)
|
|
|
+ if not flag:
|
|
|
+ obj.ctime = datetime.datetime.now()
|
|
|
+ obj.save()
|
|
|
+
|
|
|
+ #更新group_rank
|
|
|
+ #update_group_rank(match_id,match_group,obj.stock_date)
|
|
|
+ ccc.cache.lpush(settings.RANK_LIST,obj.id)
|
|
|
+ return obj.id
|
|
|
|
|
|
|
|
|
obj = model.objects.create(**kwargs)
|
|
|
@@ -394,23 +535,40 @@ def get_detail_info(cls,**kwargs):
|
|
|
id = kwargs.get("id")
|
|
|
rst = list(model.objects.filter(id=id).values())
|
|
|
rst = rst[0] if rst else {}
|
|
|
- if model_name == "PlayerRecord":
|
|
|
- group_income = get_group_income(rst["match_id"],rst["match_group"])
|
|
|
- if rst["total_income"] in group_income:
|
|
|
- group_rank = group_income.index(rst["total_income"])+1
|
|
|
- else:
|
|
|
- group_rank = 1
|
|
|
+ #if model_name == "PlayerRecord":
|
|
|
+ # rst["match_group"] = cm.MatchGroup.objects.filter(id=rst["match_group"]).first().name
|
|
|
+ # today_stock = json.loads(rst["today_stock"]) if rst["today_stock"] else []
|
|
|
+ # today_stock = filter(lambda x:x["fund"] and x["name"],today_stock if today_stock else [])
|
|
|
+ # rst["today_stock"] = today_stock
|
|
|
+ # today_stock_img = json.loads(rst["today_stock_img"]) if rst["today_stock_img"] else []
|
|
|
+ # rst["today_stock_img"] = today_stock_img
|
|
|
+
|
|
|
+ # yesterday_stock = json.loads(rst["yesterday_stock"]) if rst["yesterday_stock"] else []
|
|
|
+ # yesterday_stock = filter(lambda x:x["fund"] and x["name"],yesterday_stock if yesterday_stock else [])
|
|
|
+ # rst["yesterday_stock"] = yesterday_stock
|
|
|
+ #
|
|
|
+ # yesterday_stock_img = json.loads(rst["yesterday_stock_img"]) if rst["yesterday_stock_img"] else []
|
|
|
+ # rst["yesterday_stock_img"] = yesterday_stock_img
|
|
|
+
|
|
|
+ # rst["today_income"] = "{}%".format(rst["today_income"]*100)
|
|
|
+ # rst["total_income"] = "{}%".format(rst["total_income"]*100)
|
|
|
+ return rst
|
|
|
|
|
|
- rst["group_rank"] = group_rank
|
|
|
+#@ccc.cache_data()
|
|
|
+def get_record_info(rcid):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ rst = cm.PlayerRecord.objects.filter(id=rcid).values().first()
|
|
|
+ if rst:
|
|
|
rst["match_group"] = cm.MatchGroup.objects.filter(id=rst["match_group"]).first().name
|
|
|
today_stock = json.loads(rst["today_stock"]) if rst["today_stock"] else []
|
|
|
- today_stock = filter(lambda x:x["fund"] and x["name"],today_stock)
|
|
|
+ today_stock = filter(lambda x:x["fund"] and x["name"],today_stock if today_stock else [])
|
|
|
rst["today_stock"] = today_stock
|
|
|
today_stock_img = json.loads(rst["today_stock_img"]) if rst["today_stock_img"] else []
|
|
|
rst["today_stock_img"] = today_stock_img
|
|
|
|
|
|
yesterday_stock = json.loads(rst["yesterday_stock"]) if rst["yesterday_stock"] else []
|
|
|
- yesterday_stock = filter(lambda x:x["fund"] and x["name"],yesterday_stock)
|
|
|
+ yesterday_stock = filter(lambda x:x["fund"] and x["name"],yesterday_stock if yesterday_stock else [])
|
|
|
rst["yesterday_stock"] = yesterday_stock
|
|
|
|
|
|
yesterday_stock_img = json.loads(rst["yesterday_stock_img"]) if rst["yesterday_stock_img"] else []
|
|
|
@@ -420,6 +578,7 @@ def get_detail_info(cls,**kwargs):
|
|
|
rst["total_income"] = "{}%".format(rst["total_income"]*100)
|
|
|
return rst
|
|
|
|
|
|
+
|
|
|
def get_list_info(cls,**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
@@ -443,7 +602,6 @@ def get_list_info(cls,**kwargs):
|
|
|
for item in data:
|
|
|
user = cm.UserInfo.objects.filter(id=item["user_id"]).first()
|
|
|
match = cm.Match.objects.filter(id=item["match_id"]).first()
|
|
|
- print user
|
|
|
item["username"] = user.username
|
|
|
item["usercode"] = user.usercode
|
|
|
item["match_name"] = match.name if match else ""
|
|
|
@@ -457,6 +615,9 @@ def get_list_info(cls,**kwargs):
|
|
|
def add_player_record_single(**kwargs):
|
|
|
"""用户单独上传数据
|
|
|
"""
|
|
|
+ now = datetime.datetime.now()
|
|
|
+ if now.weekday() in [5,6] or now.strftime("%Y-%m-%d") in MISS_DATES:
|
|
|
+ raise ce.TipException(u"今日不能提交数据!")
|
|
|
usercode = kwargs.get("usercode")
|
|
|
match_id = kwargs.get("match_id")
|
|
|
if not cm.Player.objects.filter(usercode=usercode,match_id=match_id).exists():
|
|
|
@@ -483,8 +644,10 @@ def add_player_record_single(**kwargs):
|
|
|
if match.end_time < now_date:
|
|
|
raise ce.TipException(u"该比赛已结束!")
|
|
|
|
|
|
+ #yesterday = cm.PlayerRecord.objects.filter(
|
|
|
+ # match_id=match_id,player_id=player_id).order_by("-id").first()
|
|
|
yesterday = cm.PlayerRecord.objects.filter(
|
|
|
- match_id=match_id,player_id=player_id).order_by("-id").first()
|
|
|
+ match_id=match_id,player_id=player_id).order_by("-stock_date").first()
|
|
|
if yesterday:
|
|
|
yesterday_fund = yesterday.today_fund
|
|
|
yesterday_stock = yesterday.today_stock
|
|
|
@@ -512,16 +675,20 @@ def add_player_record_single(**kwargs):
|
|
|
#计算今日和昨日盈亏
|
|
|
today_income = (today_fund - yesterday_fund)/float(yesterday_fund)
|
|
|
total_income = (today_fund - init_fund)/float(init_fund)
|
|
|
+ if int(today_fund)>9999 or int(today_fund)<0:
|
|
|
+ raise ce.TipException(u"数据错误,今日净资产不能超过9999万元,不能低于0万元,请仔细核对数据!")
|
|
|
+ if int(today_income)>2:
|
|
|
+ raise ce.TipException(u"数据错误,今日盈利已超过2倍,请仔细核对数据!")
|
|
|
obj.today_income = round(today_income,4)
|
|
|
obj.total_income = round(total_income,4)
|
|
|
if not flag:
|
|
|
obj.ctime = datetime.datetime.now()
|
|
|
obj.save()
|
|
|
- #更新排名
|
|
|
- records_set = cm.PlayerRecord.objects.filter(match_id=match_id).order_by("-total_income")
|
|
|
- for index,item in enumerate(records_set):
|
|
|
- item.rank = index+1
|
|
|
- item.save()
|
|
|
+
|
|
|
+ #更新group_rank
|
|
|
+ #update_group_rank(match_id,match_group,obj.stock_date)
|
|
|
+ ccc.cache.lpush(settings.RANK_LIST,obj.id)
|
|
|
+
|
|
|
return obj.id
|
|
|
|
|
|
|
|
|
@@ -536,5 +703,19 @@ def get_single_match_info(match_id):
|
|
|
return now_date,match
|
|
|
|
|
|
|
|
|
-
|
|
|
+def get_cur_record(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player = request.player
|
|
|
+ player_id = player.id
|
|
|
+ match_id = player.match_id
|
|
|
+ match_group = player.match_group
|
|
|
+ stock_date = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ qset = cm.PlayerRecord.objects.filter(match_id=match_id,player_id=player_id,stock_date=stock_date).order_by("-stock_date")
|
|
|
+ data = qset.values().first() if qset else {}
|
|
|
+ #today_record = get_today_record(player_id,match_id,match_group,today)
|
|
|
+ if data:
|
|
|
+ data["today_stock_img"] = json.loads(data["today_stock_img"]) if data["today_stock_img"] else []
|
|
|
+ data["today_stock"] = json.loads(data["today_stock"]) if data["today_stock"] else []
|
|
|
+ return data
|
|
|
|