xjconline 10 bulan lalu
induk
melakukan
563e5cac93
5 mengubah file dengan 4272 tambahan dan 9464 penghapusan
  1. 12 3
      src/manage/controls.py
  2. 4136 9407
      src/tools/code.csv
  3. 119 51
      src/utils/ocrmanage.py
  4. 5 3
      src/weixin/controls.py
  5. TEMPAT SAMPAH
      templates/wzb/wanzhubei.apk

+ 12 - 3
src/manage/controls.py

@@ -154,10 +154,19 @@ def add_model(cls,**kwargs):
             yesterday_stock_img = yesterday.today_stock_img
             yesterday_is_markt = yesterday.is_markt
         else:
-            yesterday_fund = init_fund 
+            yesterday_fund = today_fund 
             yesterday_stock = ""
             yesterday_stock_img = "" 
             yesterday_is_markt = 0
+            if kwargs.get("id"):
+                if cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,user_id=user_id).count()==1:
+                    init_fund = today_fund
+                    cm.Player.objects.filter(user_id=user_id,match_id=match_id).update(fund=today_fund)
+            else:
+                if not cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,user_id=user_id).exists():
+                    init_fund = today_fund
+                    cm.Player.objects.filter(user_id=user_id,match_id=match_id).update(fund=today_fund)
+                    
         obj,flag = cm.PlayerRecord.get_db_model(match_id).objects.get_or_create(
                         player_id=player_id,
                         match_id=match_id,
@@ -770,11 +779,11 @@ def download_records_image(request):
 
             today_stock = json.loads(item["today_stock"]) if item["today_stock"] else []
             today_stock = list(filter(lambda x:x["name"],today_stock if today_stock else []))
-            today_stock = ",".join([x["name"]+str(x["fund"]) for x in today_stock]) if today_stock else ""
+            today_stock = ",".join([x["name"]+str(x["fund"]) for x in today_stock if x['fund'] != '0.0']) if today_stock else ""
 
             yesterday_stock = json.loads(item["yesterday_stock"]) if item["yesterday_stock"] else []
             yesterday_stock = list(filter(lambda x:x["name"],yesterday_stock if yesterday_stock else []))
-            yesterday_stock = ",".join([x["name"]+str(x["fund"]) for x in yesterday_stock]) if yesterday_stock else ""
+            yesterday_stock = ",".join([x["name"]+str(x["fund"]) for x in yesterday_stock if x['fund'] != '0.0']) if yesterday_stock else ""
 
             #空仓、开超市、请假判断
             if item["auto_complete"] > 0:

File diff ditekan karena terlalu besar
+ 4136 - 9407
src/tools/code.csv


+ 119 - 51
src/utils/ocrmanage.py

@@ -61,28 +61,31 @@ class OcrManage:
     @classmethod
     def parse(self,result,source):
         list  = result['words_result']
+        words = []
+        for dic in list:
+            word = dic['words']
+            word = self.deleteWords(word)
+            if len(word) > 0:
+                words.append(word)
+        wlist = self.wordsSeperate(words)
+        
         if source == 'pc': #电脑截图
-            words = []
-            for dic in list:
-                word = dic['words']
-                word = self.deleteWords(word)
-                if len(word) > 0:
-                    words.append(word)
-            wlist = self.wordsSeperate(words)
             return self.lookCPAsset(wlist,list)
         else:
-            return self.lookAsset(list)
+            return self.lookAsset(wlist,list)
     
     @classmethod
-    def lookAsset(self,list):
+    def lookAsset(self,wlist,list):
         dic   = {}
         asset = ''
         if self.indexObject('净资产',list) > 0:
             asset = self.caculateAsset(list,'净资产')
         else:
             asset = self.caculateAsset(list,'总资产')
-
-
+            if(self.floatValue(asset) == 0):
+                asset = self.caculateAsset(list,'账户资产')
+            if(self.floatValue(asset) == 0):
+                asset = self.assetWords(wlist)
         
         dic['today'] = self.wangWord(asset)
         dic['list']  = self.lookMarket(list)
@@ -93,14 +96,44 @@ class OcrManage:
     def lookMarket(self,list):
         flist = []
         index = self.indexObject('市值',list)
-        i = index
-        for i in range(len(list)):
+        beforeLoc = 0
+
+        for i in range(index,len(list)):
             dic = list[i]
             words = dic['words']
             codeName = self.codeName(words)
             if len(codeName['name']) > 0:
                 fund = 0
                 market = '0'
+                money  = 0
+            
+                if beforeLoc == 0:
+                    for n in range(i,index,-1):
+                        ndic = list[n]
+                        nstr = ndic['words']
+                        nstr = self.replaceWords(nstr)
+                        if('当日盈亏' in nstr or '比' in nstr):
+                            continue
+
+                        if '持仓盈' in nstr or '浮动盈亏' in nstr or '参考盈亏' in nstr or '盈亏/盈亏率' in nstr or '总盈亏' in nstr or '盈亏' in nstr:
+                            bnloc = list[n-1]['location']
+                            beforeLoc = float(bnloc['left']) + float(bnloc['width'])
+                            break
+
+                if beforeLoc > 0:
+                    for m in range(i+1,len(list)):
+                        mdic = list[m]
+                        mloc = mdic['location']
+                        mstr = mdic['words']
+
+                        if mloc['left'] > beforeLoc:
+                            mstr = self.replaceWords(mstr)
+                            mstr = self.replaceDot(mstr)
+                            mstr = self.wangWord(mstr)
+                            money = float(mstr)
+                            
+                            break
+
                 for m in range(i+1,len(list)):
                     mdic = list[m]
                     mloc = mdic['location']
@@ -108,29 +141,25 @@ class OcrManage:
                     nstr = mdic['words']
                     if len(nstr) == 6 and ((',' not in nstr) or ('.' not in nstr)) and self.isNumber(nstr):
                         continue
-                    if float(mloc['left']) < (float(loc['left']) + float(loc['width'])):
+                    if float(mloc['left']) < (float(loc['left']) + float(loc['width'])/2.0):
                         market = mdic['words']
                         break
                 
                 
                 fund = self.wangWord(market)
 
-                if fund > 0:
-                    ndic = {}
-                    ndic['name'] = codeName['name']
-                    ndic['code'] = codeName['code']
-                    ndic['fund'] = str(round(fund,2))
-                    flist.append(ndic)
+                ndic = {}
+                ndic['name'] = codeName['name']
+                ndic['code'] = codeName['code']
+                ndic['fund'] = str(round(fund,2))
+                ndic['money'] = str(round(money,3))
+                flist.append(ndic)
 
         return flist
     
     @classmethod
     def lookCPAsset(self,wlist,list):
         dic   = {}
-
-        # print(str(wlist))
-
-
         asset = self.assetWords(wlist)
         if self.floatValue(asset) >= 0:
             today = self.floatValue(asset)/10000.0
@@ -138,29 +167,30 @@ class OcrManage:
 
         dic['list'] = self.lookCPMarket(list)
 
-        print(str(dic))
 
         return dic
 
     @classmethod
     def lookCPMarket(self,list):
         flist = []
-        index = self.indexEquel('市值',list)
+        mindex = self.indexObject('名称',list)
+       
+        index = self.indexEquel('市值',list,mindex)
         if index == 0:
-            index = self.indexEquel('最新市值',list)
+            index = self.indexEquel('最新市值',list,mindex)
 
         if index == 0:
-            index = self.indexEquel('最新沛值',list)
+            index = self.indexEquel('最新沛值',list,mindex)
         
         before = 0.0
 
         if index - 1 > 0:
             sdic = list[index-1]
             sloc = sdic['location']
-           
+            print(sdic)
             before = float(sloc['left']) + float(sloc['width'])
             
-        
+        beforeLoc = 0
         
         for i in range(index,len(list)):
             dic = list[i]
@@ -175,6 +205,37 @@ class OcrManage:
             if len(codeName['name']) > 0:
                 fund = 0
                 market = '0'
+                money = 0
+
+                if beforeLoc == 0:
+                    for n in range(len(list)-1,-1,-1):
+                        ndic = list[n]
+                        nstr = ndic['words']
+                        nstr = self.replaceWords(nstr)
+                        if('当日盈亏' in nstr or '比例' in nstr):
+                            continue
+                        if '持仓盈亏' == nstr or '浮动盈亏' == nstr or '参考盈亏' == nstr or '盈亏/盈亏率' in nstr or '总盈亏' == nstr or '盈亏' == nstr:
+                            bnloc = list[n-1]['location']
+                            beforeLoc = float(bnloc['left']) + float(bnloc['width'])
+                            break
+                  
+
+
+                if beforeLoc > 0:
+                    for m in range(i+1,len(list)):
+                        mdic = list[m]
+                        mloc = mdic['location']
+                        mstr = mdic['words']
+
+                        if mloc['left'] > beforeLoc:
+                            mstr = self.replaceWords(mstr)
+                            mstr = self.replaceDot(mstr)
+                            mstr = self.wangWord(mstr)
+                            money = float(mstr)
+                            
+                            break
+
+
                 for m in range(i+1,len(list)):
                     mdic = list[m]
                     mloc = mdic['location']
@@ -186,12 +247,13 @@ class OcrManage:
                 
                 fund = self.wangWord(market)
                 
-                if fund > 0:
-                    ndic = {}
-                    ndic['name'] = codeName['name']
-                    ndic['code'] = codeName['code']
-                    ndic['fund'] = str(round(fund,2))
-                    flist.append(ndic)
+  
+                ndic = {}
+                ndic['name'] = codeName['name']
+                ndic['code'] = codeName['code']
+                ndic['fund'] = str(round(fund,2))
+                ndic['money'] = str(round(money,3))
+                flist.append(ndic)
 
         return flist
 
@@ -213,6 +275,10 @@ class OcrManage:
                     width = float(jdic['width'])
                     if jx < ix and ix < (jx + width):
                         strAsset = ndic['words']
+                        if(self.isChinese(strAsset)):
+                            if ('万' not in strAsset):
+                                clist    = self.seperateChinense(strAsset)
+                                strAsset = clist[0]
                         break
                 
                 if self.wangWord(strAsset) == 0:
@@ -260,7 +326,7 @@ class OcrManage:
                     if len(cword) > 0:
                         list.append(cword)
                         cword = ''
-                if strw == '-' or strw == ':':
+                if strw == ':':
                     if len(nword) > 0:
                         list.append(nword)
                         nword = ''
@@ -425,6 +491,9 @@ class OcrManage:
         words = words.replace(':','')
         words = words.replace(':','')
         words = words.replace('A','')
+        words = words.replace('▲','')
+        words = words.replace('◆','')
+        words = words.replace('+','')
         words = words.upper()
 
         return words
@@ -462,6 +531,7 @@ class OcrManage:
         for i in range(len(list)):
             dic = list[i]
             nword = dic['words']
+            nword = self.replaceWords(nword)
             if words in nword:
                 index = i
                 break
@@ -469,13 +539,14 @@ class OcrManage:
         return index
     
     @classmethod
-    def indexEquel(self,words,list):
+    def indexEquel(self,words,list,m):
         index = -1
         i=0
-        for i in range(len(list)):
+        for i in range(m,len(list)):
             dic = list[i]
             nword = dic['words']
-            if words == nword:
+            nword = self.replaceWords(nword)
+            if words in nword:
                 index = i
                 break
 
@@ -488,6 +559,10 @@ class OcrManage:
             # print('ischinese:' + number)
             return False
 
+        fushu = r'-\w*'
+        if re.match(fushu, str(number)):
+            return True
+        
         zhengshu = r'^([1-9][\d]*|0)(\.[\d]+)?$'
         if re.match(zhengshu, str(number)):
             return True
@@ -512,14 +587,10 @@ class OcrManage:
         if word == '':
             return 0
 
-        # print('floatValue:' + word)
-
         return float(word)
     
     @classmethod
     def wangWord(self,word):
-        print(word)
-
         isWang = 0
         if '万' in word:
             wlist = self.seperateChinense(word)
@@ -528,14 +599,11 @@ class OcrManage:
                 isWang = 1
 
         
-        if self.floatValue(word) >= 0:
-            if isWang == 1:
-                nvalue = self.floatValue(word)
-            else:
-                nvalue = self.floatValue(word)/10000.0
-            word = round(nvalue,2)
+        if isWang == 1:
+            nvalue = self.floatValue(word)
         else:
-            word = 0
+            nvalue = self.floatValue(word)/10000.0
+        word = round(nvalue,3)
 
         return word
 

+ 5 - 3
src/weixin/controls.py

@@ -1890,9 +1890,11 @@ def get_stock_players(**kwargs):
                 for item in today_record["today_stock"]:
                     if int(item["stock_id"]) == int(stock_id):
                         today_record["cur_stock_fund"] = float(item["fund"]) if item["fund"] else 0.0
+                    else:
+                        today_record["cur_stock_fund"] = 0.0
                 data.append(today_record)
     #data = sorted(data,key=lambda x:x["today_fund"],reverse=True)
-    data = sorted(data,key=lambda x:x["cur_stock_fund"],reverse=True)
+    data = sorted(data,key=lambda x:x.get("cur_stock_fund",0),reverse=True)
     #分页
     page = int(kwargs.get("page",0))
     page_size = int(kwargs.get("page_size",20))
@@ -2460,8 +2462,8 @@ def add_wanzhu_consult(request):
     aliyunpush.push_notice_by_userid(0,title,body,params,"android")
 
     #退款短信通知
-    if '退款' in content:
-        send_verify_code('18397565872','0000')
+#     if '退款' in content:
+#         send_verify_code('18397565872','0000')
 
 
 def add_comments(request):

TEMPAT SAMPAH
templates/wzb/wanzhubei.apk