xjc 1 jaar geleden
bovenliggende
commit
555ba08f78
6 gewijzigde bestanden met toevoegingen van 3976 en 3916 verwijderingen
  1. 36 9
      src/manage/controls.py
  2. 3880 3880
      src/tools/code.csv
  3. 2 4
      src/utils/plottool.py
  4. 44 23
      src/weixin/controls.py
  5. 1 0
      src/weixin/urls_backstage.py
  6. 13 0
      src/weixin/views.py

+ 36 - 9
src/manage/controls.py

@@ -62,6 +62,20 @@ def async(f):
     return wrapper
 
 
+def get_match_validdates(match_id):
+    """
+    """
+    #qdata = request.json
+    #match_id = qdata.get("match_id")
+
+    match = cm.Match.objects.filter(id=match_id).first()
+    if match:
+        validdates = json.loads(match.valid_dates) if match.valid_dates else []
+        validdates.sort()
+        return validdates
+    return []
+
+
 def add_model(cls,**kwargs):
     """
     """
@@ -123,8 +137,17 @@ 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.get_db_model(match_id).objects.filter(
-                        match_id=match_id,player_id=player_id).order_by("-stock_date").first()
+        #yesterday = cm.PlayerRecord.get_db_model(match_id).objects.filter(
+        #                match_id=match_id,player_id=player_id).order_by("-stock_date").first()
+
+        validdates = get_match_validdates(match_id)
+        today_index = validdates.index(stock_date)
+        yesterday_index = today_index -1 if today_index >=1 else 0
+        yesterday_date = validdates[yesterday_index]
+
+        yesterday = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,player_id=player_id,
+            stock_date=yesterday_date).exclude(stock_date=stock_date).first()
+
         if yesterday:
             yesterday_fund = yesterday.today_fund
             yesterday_stock = yesterday.today_stock
@@ -691,10 +714,12 @@ def download_records_image(request):
         return None
 
     qset = cm.PlayerRecord.get_db_model(match_id).objects.all()
-    match = cm.Match.objects.filter(id=match_id).values('name').first()
+    match = cm.Match.objects.filter(id=match_id).values('name', 'start_time', 'end_time').first()
     if match is None:
         return None
-    match_name = match['name']
+    match_name = match['name'][:7]
+    match_start_day_str = datetime.datetime.strptime(match['start_time'], '%Y-%m-%d').strftime('%-m.%-d')
+    match_stop_day_str = datetime.datetime.strptime(match['end_time'], '%Y-%m-%d').strftime('%-m.%-d')
 
     if kwargs.get("match_id"):
         qset = qset.filter(match_id=kwargs.get("match_id"))
@@ -711,13 +736,15 @@ def download_records_image(request):
         qset = qset.filter(Q(username__icontains=kwargs.get("username"))|Q(usercode__icontains=kwargs.get("username")))
     if kwargs.get("stock_date"):
         qset = qset.filter(stock_date=kwargs.get("stock_date"))
+        # this formatting method only works on linux
+        stock_day_str = datetime.datetime.strptime(kwargs.get("stock_date"), '%Y-%m-%d').strftime('%-m.%-d')
         if match_group_name:
-            title = u'{}-{}-{}'.format(match_name[:7], match_group_name, kwargs.get("stock_date")[5:])
+            title = u'{}-{}{}({}-{})'.format(match_name, match_group_name, stock_day_str, match_start_day_str, match_stop_day_str)
         else:
-            title = u'{}-{}'.format(match_name[:7], kwargs.get("stock_date")[5:])
+            title = u'{}-{}'.format(match_name, stock_day_str)
     else:
         if match_group_name:
-            title = u'{}-{}'.format(match_name[:7], match_group_name)
+            title = u'{}-{}'.format(match_name, match_group_name)
         else:
             title = match_name
 
@@ -779,8 +806,8 @@ def download_records_image(request):
         except Exception as e:
             print(e)
 
-    col_headers = [u"NO.", u"选手", u"初始资产", u"今日资产",
-                   u"今日盈亏", u"总盈亏", u"昨日持股\n(万元)", u"今日持股\n(万元)"]
+    col_headers = [u"NO.", u"选手", u"初始", u"今日",
+                   u"今日成绩", u"总成绩", u"昨日", u"今日"]
 
     ret = plot_records(data, col_headers, title, 'player_records')
     return ret 

File diff suppressed because it is too large
+ 3880 - 3880
src/tools/code.csv


+ 2 - 4
src/utils/plottool.py

@@ -76,15 +76,13 @@ def plot_records_as_table_and_convert_to_png(
 
     if col_headers:
         for i in range(ncols):
-            table.add_cell(t_offset, i, width=widths[i], height=height * 2, facecolor='yellow', text=col_headers[i], loc='center')
+            table.add_cell(t_offset, i, width=widths[i], height=height * 2, edgecolor='grey', facecolor='yellow', text=col_headers[i], loc='center')
             table[t_offset, i].set_fontsize(12)
-            table[t_offset, i].set_edgecolor('grey')
 
     for i in range(nrows):
         for j in range(ncols):
-            table.add_cell(i + offset, j, width=widths[j], height=height*row_heights_mul[i], text=table_data[i][j], loc='center')
+            table.add_cell(i + offset, j, width=widths[j], height=height*row_heights_mul[i], edgecolor='grey', text=table_data[i][j], loc='center')
             table[i + offset, j].set_fontsize(14)
-            table[i + offset, j].set_edgecolor('grey')
             if not table_data[i][5].startswith('-'):
                 table[i + offset, j].get_text().set_color('red')
 

+ 44 - 23
src/weixin/controls.py

@@ -3444,6 +3444,7 @@ def get_match_group_winlose_statistic(**qdata):
         match_group_dct[item.id] = item.name
         match_group_status_dct[item.id] = item.is_active
 
+    print(today)
     prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,stock_date=today)
 
     group_win_lose_list = []
@@ -3451,13 +3452,16 @@ def get_match_group_winlose_statistic(**qdata):
     prdata = prset.values("match_group").annotate(today_fund=Sum("today_fund"),
         today_income=Sum("today_income"),cnt=Count("today_income")).order_by("match_group")
 
+    match_name = get_match_info(match_id).get("name")
+	
     for item in prdata:
         group_id = int(item["match_group"])
         if match_group_status_dct.get(group_id)>0:
             group_win_lose_list.append({
 	            "match_id":match_id,
+	            "match_name":match_name,
                 "match_group":group_id,
-                "match_group_name":match_group_dct.get(group_id),
+                "name":match_group_dct.get(group_id),
                 "today_fund":"{}".format(round(item["today_fund"],2)),
                 "today_income":"{}%".format(round(item["today_income"]*100,2)),
                 "today_income_avg":"{}%".format(round(item["today_income"]/item["cnt"]*100,2)) if item["cnt"] else 0.0
@@ -3544,29 +3548,46 @@ def get_match_group_winlose_allday(**qdata):
 
     prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,match_group=group_id)
 
-    all_day = list(set(prset.values_list("stock_date",flat=True)))
-    for stock_date in all_day: 
-        group_win_lose_list = []
-        #今日总资产,总收益,平均收益
-        prdata = prset.values("match_group","stock_date").annotate(today_fund=Sum("today_fund"),
-            today_income=Sum("today_income"),cnt=Count("today_income")).order_by("match_group")
+    group_win_lose_list = []
+    prdata = prset.values("match_group","stock_date").annotate(today_fund=Sum("today_fund"),
+        today_income=Sum("today_income"),cnt=Count("today_income")).order_by("match_group").order_by("-stock_date")
 
-        for item in prdata:
-            group_id = int(item["match_group"])
-            group_win_lose_list.append({
-                "stock_date":stock_date,
-                "match_group":group_id,
-                "match_group_name":match_group_dct.get(group_id),
-                "today_fund":"{}".format(round(item["today_fund"],2)),
-                "today_income":"{}%".format(round(item["today_income"]*100,2)),
-                "today_income_avg":"{}%".format(round(item["today_income"]/item["cnt"]*100,2)) if item["cnt"] else 0.0
-            })
-    #group_win_lose_list = sorted(group_win_lose_list,key=lambda x:x["match_group"],reverse=True)
+    for item in prdata:
+        group_id = int(item["match_group"])
+        stock_date = item["stock_date"]
+        group_win_lose_list.append({
+            "stock_date":stock_date,
+            "match_group":group_id,
+            "name":match_group_dct.get(group_id),
+            "today_fund":"{}".format(round(item["today_fund"],2)),
+            "total_income":"{}%".format(round(item["today_income"]/item["cnt"]*100,2)) if item["cnt"] else 0.0,
+            "today_income":"{}%".format(round(item["today_income"]/item["cnt"]*100,2)) if item["cnt"] else 0.0
+        })
 
-    prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,stock_date=today)
-    #今日全部人均收益率
-    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
+    rst = {"list":group_win_lose_list}
+    return rst
+
+
+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)))
+
+    allday_winlose_avg_list = []
+    for stock_date in all_day: 
+        #今日全部人均收益率
+        total = prset.filter(stock_date=stock_date).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
+        allday_winlose_avg_list.append({
+            "stock_date":stock_date,     
+            "today_income":today_win_lose_avg,     
+        })
 
-    rst = {"today_win_lose_avg":today_win_lose_avg,"group_win_lose_list":group_win_lose_list}
+    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

+ 1 - 0
src/weixin/urls_backstage.py

@@ -113,6 +113,7 @@ urlpatterns = [
     url(r'^v3/user/markscore/list$', views.UserMarkScoreListView.as_view()),
     url(r'^v3/user/markscore/check$', views.UserMarkScoreCheckView.as_view()),
     url(r'^v3/match/group/winlose/allday$', views.MatchGroupWinloseAllDayView.as_view()),
+    url(r'^v3/match/group/winlose/avg/allday$', views.MatchGroupWinloseAvgAllDayView.as_view()),
     
 ]
 

+ 13 - 0
src/weixin/views.py

@@ -1692,3 +1692,16 @@ class MatchGroupWinloseAllDayView(cv.BaseView):
         except Exception as e:
             cv.tracefail()
             return cv.to_fail(e)
+
+
+class MatchGroupWinloseAvgAllDayView(cv.BaseView):
+    def get(self, request):
+        """#获取分组盈亏统计量
+        """
+        qdata = request.json
+        try:
+            rst = ctl.get_match_group_winlose_avg_allday(**qdata)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)