|
@@ -119,7 +119,7 @@ def add_model(cls,**kwargs):
|
|
|
raise ce.TipException(u"该比赛已结束!")
|
|
|
|
|
|
#yesterday_date = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
- yesterday = cm.PlayerRecord.objects.filter(
|
|
|
+ yesterday = cm.PlayerRecord.get_db_model(match_id).objects.filter(
|
|
|
match_id=match_id,player_id=player_id).order_by("-stock_date").first()
|
|
|
if yesterday:
|
|
|
yesterday_fund = yesterday.today_fund
|
|
@@ -131,7 +131,7 @@ def add_model(cls,**kwargs):
|
|
|
yesterday_stock = ""
|
|
|
yesterday_stock_img = ""
|
|
|
yesterday_is_markt = 0
|
|
|
- obj,flag = cm.PlayerRecord.objects.get_or_create(
|
|
|
+ obj,flag = cm.PlayerRecord.get_db_model(match_id).objects.get_or_create(
|
|
|
player_id=player_id,
|
|
|
match_id=match_id,
|
|
|
stock_date=stock_date)
|
|
@@ -160,8 +160,11 @@ def add_model(cls,**kwargs):
|
|
|
#更新group_rank
|
|
|
|
|
|
return obj.id
|
|
|
-
|
|
|
- obj = model.objects.create(**kwargs)
|
|
|
+ if model_name == "PlayerRecord":
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ obj = model.get_db_model(match_id).objects.create(**kwargs)
|
|
|
+ else:
|
|
|
+ obj = model.objects.create(**kwargs)
|
|
|
#
|
|
|
if model_name == "Match":
|
|
|
cm.MatchGroup.objects.create(
|
|
@@ -210,10 +213,15 @@ def update_model(cls,**kwargs):
|
|
|
kwargs["today_stock"] = json.dumps(kwargs.get("today_stock"))
|
|
|
kwargs["today_stock_img"] = json.dumps(kwargs.get("today_stock_img"))
|
|
|
|
|
|
- rst = model.objects.filter(id=id).update(**kwargs)
|
|
|
+ if model_name == "PlayerRecord":
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ rst = model.get_db_model(match_id).objects.filter(id=id).update(**kwargs)
|
|
|
+ else:
|
|
|
+ rst = model.objects.filter(id=id).update(**kwargs)
|
|
|
|
|
|
if model_name == "PlayerRecord":
|
|
|
- obj = cm.PlayerRecord.objects.filter(id=id).first()
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ obj = cm.PlayerRecord.get_db_model(match_id).objects.filter(id=id).first()
|
|
|
today_fund = obj.today_fund
|
|
|
yesterday_fund = obj.yesterday_fund
|
|
|
init_fund = obj.init_fund
|
|
@@ -251,7 +259,14 @@ def delete_model(cls,**kwargs):
|
|
|
if model_name == "WanzhuConsult":
|
|
|
cm.WanzhuConsult.objects.filter(Q(user_id__in=ids)|Q(reply_user_id__in=ids)).delete()
|
|
|
else:
|
|
|
- rst = model.objects.filter(id__in=ids).delete()
|
|
|
+ if model_name == "PlayerRecord":
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ obj = cm.PlayerRecord.get_db_model(match_id).objects.filter(id__in=ids).first()
|
|
|
+ ##更新group_rank
|
|
|
+ update_group_rank(obj.stock_date,obj.match_group,obj.match_id)
|
|
|
+ rst = model.get_db_model(match_id).objects.filter(id__in=ids).delete()
|
|
|
+ else:
|
|
|
+ rst = model.objects.filter(id__in=ids).delete()
|
|
|
if model_name == "UserInfo":
|
|
|
cm.Player.objects.filter(user_id__in=ids).delete()
|
|
|
cm.PlayerRecord.objects.filter(user_id__in=ids).delete()
|
|
@@ -264,10 +279,7 @@ def delete_model(cls,**kwargs):
|
|
|
if model_name == "MatchGroup":
|
|
|
cm.PlayerRecord.objects.filter(match_group__in=ids).delete()
|
|
|
cm.Player.objects.filter(match_group__in=ids).delete()
|
|
|
- if model_name == "PlayerRecord":
|
|
|
- obj = cm.PlayerRecord.objects.filter(id__in=ids).first()
|
|
|
- ##更新group_rank
|
|
|
- update_group_rank(obj.stock_date,obj.match_group,obj.match_id)
|
|
|
+
|
|
|
return ids
|
|
|
|
|
|
|
|
@@ -306,7 +318,11 @@ def get_detail_info(cls,**kwargs):
|
|
|
model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
model = getattr(cm,model_name)
|
|
|
id = kwargs.get("id")
|
|
|
- rst = list(model.objects.filter(id=id).values())
|
|
|
+ if model_name == "PlayerRecord":
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ rst = list(model.get_db_model(match_id).objects.filter(id=id).values())
|
|
|
+ else:
|
|
|
+ rst = list(model.objects.filter(id=id).values())
|
|
|
rst = rst[0] if rst else {}
|
|
|
if model_name == "Player":
|
|
|
user = get_user_info(rst["user_id"])
|
|
@@ -347,7 +363,11 @@ def get_list_info(cls,**kwargs):
|
|
|
"""
|
|
|
model_name = re.search(r'.*\.(\w+)ListView',str(cls.__class__)).groups()[0]
|
|
|
model = getattr(cm,model_name)
|
|
|
- qset = model.objects.all()
|
|
|
+ if model_name == "PlayerRecord":
|
|
|
+ match_id = kwargs.get("match_id",0)
|
|
|
+ qset = model.get_db_model(match_id).objects.all()
|
|
|
+ else:
|
|
|
+ qset = model.objects.all()
|
|
|
if kwargs.get("name"):
|
|
|
qset = qset.filter(name__icontains=kwargs.get("name"))
|
|
|
if model_name == "UserInfo":
|
|
@@ -500,8 +520,9 @@ def download_records(request):
|
|
|
"""
|
|
|
kwargs = request.json
|
|
|
header = [u"排名",u"选手",u"初始资产(万)",u"昨日资产(万)",u"今日资产",u"今日盈亏",u"总盈亏",u"昨日持股",u"今日持股"]
|
|
|
-
|
|
|
- qset = cm.PlayerRecord.objects.all()
|
|
|
+
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ qset = cm.PlayerRecord.get_db_model(match_id).objects.all()
|
|
|
|
|
|
if kwargs.get("match_id"):
|
|
|
qset = qset.filter(match_id=kwargs.get("match_id"))
|
|
@@ -590,26 +611,29 @@ def fast_save_player(**kwargs):
|
|
|
def update_player_latest(record):
|
|
|
"""更新选手最后一次数据
|
|
|
"""
|
|
|
- player_id = record["player_id"]
|
|
|
+ user_id = record["user_id"]
|
|
|
match_id = record["match_id"]
|
|
|
stock_date = record["stock_date"]
|
|
|
match_group = record["match_group"]
|
|
|
+ wincnt = record["wincnt"]
|
|
|
+ total = record["totalcnt"]
|
|
|
|
|
|
+ key = "PLAYER_LATEST_{}".format(user_id)
|
|
|
if record:
|
|
|
- key = "PLAYER_LATEST_{}".format(player_id)
|
|
|
ccc.cache.hset(key,"stock_date",stock_date)
|
|
|
ccc.cache.hset(key,"match_id",match_id)
|
|
|
ccc.cache.hset(key,"match_group",match_group)
|
|
|
+
|
|
|
#更新胜率
|
|
|
- qset = cm.PlayerRecord.objects.filter(match_id=match_id,player_id=player_id)
|
|
|
- win_rate = qset.filter(today_income__gte=0).count()/float(qset.count()) if qset else 0.0
|
|
|
+ qset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,user_id=user_id)
|
|
|
+ #win_rate = qset.filter(today_income__gte=0).count()/float(qset.count()) if qset else 0.0
|
|
|
+ win_rate = wincnt/float(total) if total else 0.0
|
|
|
win_rate = round(win_rate,3)
|
|
|
ccc.cache.hset(key,"win_rate",win_rate)
|
|
|
|
|
|
- badest = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("today_income").first()
|
|
|
- if badest:
|
|
|
- key = "PLAYER_LATEST_{}".format(player_id)
|
|
|
- ccc.cache.hset(key,"badest_income",badest.today_income)
|
|
|
+ #badest = cm.PlayerRecord.get_db_model(match_id).objects.filter(user_id=user_id,match_id=match_id).order_by("today_income").first()
|
|
|
+ #if badest:
|
|
|
+ # ccc.cache.hset(key,"badest_income",badest.today_income)
|
|
|
|
|
|
|
|
|
def update_group_rank(stock_date=None,match_id=None,group_id=None):
|
|
@@ -624,12 +648,7 @@ def update_group_rank(stock_date=None,match_id=None,group_id=None):
|
|
|
for gp in groups:
|
|
|
match_id = gp.match_id
|
|
|
match_group = gp.id
|
|
|
- delkey = "*_%s_%s_%s" % (match_id,match_group,stock_date)
|
|
|
- #del_keys = ccc.cache.keys(delkey)
|
|
|
- #if del_keys:
|
|
|
- # for key in del_keys:
|
|
|
- # ccc.cache.delete(key)
|
|
|
- prset = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,stock_date=stock_date).order_by("-total_income")
|
|
|
+ prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,match_group=match_group,stock_date=stock_date).order_by("-total_income")
|
|
|
if prset:
|
|
|
records = prset.values()
|
|
|
case_id = " case id "
|
|
@@ -640,10 +659,31 @@ def update_group_rank(stock_date=None,match_id=None,group_id=None):
|
|
|
cases.append(case)
|
|
|
where.append(str(pr["id"]))
|
|
|
#
|
|
|
- key = "%s_%s_%s_%s" % (pr["player_id"],match_id,match_group,stock_date)
|
|
|
+ key = "%s_%s_%s_%s" % (pr["user_id"],match_id,match_group,stock_date)
|
|
|
pr.update({"group_rank":index+1})
|
|
|
ccc.pl.set(key,json.dumps(pr,cls=ccc.CusJSONEncoder))
|
|
|
+
|
|
|
ccc.pl.execute()
|
|
|
+
|
|
|
+ winset = cm.PlayerRecord.get_db_model(match_id).objects.filter(
|
|
|
+ match_id=match_id,match_group=match_group,today_income__gte=0)\
|
|
|
+ .values("user_id").annotate(wincnt=Count("user_id")).values("user_id","match_id","match_group","wincnt")
|
|
|
+ totalset = cm.PlayerRecord.get_db_model(match_id).objects.filter(
|
|
|
+ match_id=match_id,match_group=match_group)\
|
|
|
+ .values("user_id").annotate(totalcnt=Count("user_id")).values("user_id","totalcnt")
|
|
|
+ totallist = list(totalset)
|
|
|
+ for item in winset:
|
|
|
+ item["stock_date"] = stock_date
|
|
|
+ user_id = item["user_id"]
|
|
|
+ total = filter(lambda x:x["user_id"]==user_id,totallist)
|
|
|
+ if total:
|
|
|
+ item.update(total[0])
|
|
|
+ else:
|
|
|
+ item.update({"totalcnt":0})
|
|
|
+
|
|
|
+ #更新最后一次数据
|
|
|
+ update_player_latest(item)
|
|
|
+
|
|
|
if cases and where:
|
|
|
case = case_id + " ".join(cases)
|
|
|
where = ",".join(where)
|
|
@@ -652,8 +692,8 @@ def update_group_rank(stock_date=None,match_id=None,group_id=None):
|
|
|
cursor.execute(sql)
|
|
|
cursor.close()
|
|
|
|
|
|
- #更新最后一次数据
|
|
|
- update_player_latest(pr)
|
|
|
+ ##更新最后一次数据
|
|
|
+ #update_player_latest(pr)
|
|
|
|
|
|
|
|
|
def update_comment(**kwargs):
|