xjc 10 months ago
parent
commit
9babf7be59
1 changed files with 34 additions and 13 deletions
  1. 34 13
      src/weixin/controls.py

+ 34 - 13
src/weixin/controls.py

@@ -3611,27 +3611,48 @@ def get_match_group_winlose_avg_allday(**qdata):
     match_id = qdata.get("match_id")
     group_id = qdata.get("group_id")
 
-    prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id)
-
-    all_day = list(set(prset.values_list("stock_date",flat=True)))
-
-    nall_day = sorted(all_day,reverse=False)
+    #prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id)
+    #all_day = list(set(prset.values_list("stock_date",flat=True)))
+    #nall_day = sorted(all_day,reverse=False)
 
     allday_winlose_avg_list = []
     money = 10000.0
-    for stock_date in nall_day: 
-        #今日全部人均收益率
-        prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,stock_date=stock_date)
-        total = prset.aggregate(total=Sum("today_income")).get("total")
-        today_win_lose_avg = "{}%".format(round(total/prset.count()*100,2)) if prset.count()>0 else 0.0
-        money += money * (total/prset.count() if prset.count() > 0 else 0)
+    prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id).values("stock_date")\
+        .annotate(cnt=Count("stock_date"),total=Sum("today_income"))
+    for item in prset:
+        stock_date = item["stock_date"]
+        cnt = item["cnt"]
+        total = item["total"]
+
+        today_win_lose_avg = "{}%".format(round(total/cnt*100,2)) if cnt>0 else 0.0
+        money += money * (total/cnt if cnt > 0 else 0)
+
         total_income = (money-10000.0)/10000.0
         total_avg    = "{}%".format(round(total_income*100,2))
+
         allday_winlose_avg_list.append({
             "stock_date":stock_date,     
             "today_income":today_win_lose_avg,     
             "total_income":total_avg,
         })
+
+    #for stock_date in nall_day: 
+    #    #今日全部人均收益率
+    #    prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,stock_date=stock_date)
+    #    total = prset.aggregate(total=Sum("today_income")).get("total")
+
+    #    today_win_lose_avg = "{}%".format(round(total/prset.count()*100,2)) if prset.count()>0 else 0.0
+    #    money += money * (total/prset.count() if prset.count() > 0 else 0)
+
+    #    total_income = (money-10000.0)/10000.0
+    #    total_avg    = "{}%".format(round(total_income*100,2))
+
+    #    allday_winlose_avg_list.append({
+    #        "stock_date":stock_date,     
+    #        "today_income":today_win_lose_avg,     
+    #        "total_income":total_avg,
+    #    })
+
     allday_winlose_avg_list = sorted(allday_winlose_avg_list,key=lambda x:x["stock_date"],reverse=True)
     rst = {"list":allday_winlose_avg_list}
     return rst
@@ -3659,13 +3680,13 @@ def get_user_match_stock_winloss_rank_list(**kwargs):
                 if sitem["fund"] in ["0.0","0",""]:
                     sitem["stock_date"] = stock_date
                     data.append(sitem)
-
+				
     if rank_type == "win":
         data = filter(lambda x:float(x.get("money",0))>0,data)
         data = sorted(data,key=lambda x:float(x.get("money",0)),reverse=True)
     else:
         data = filter(lambda x:float(x.get("money",0))<0,data)
-        data = sorted(data,key=lambda x:float(x.get("money",0)),reverse=True)
+        data = sorted(data,key=lambda x:float(x.get("money",0)))
 
     return data