Browse Source

优化;

Jeff 5 years ago
parent
commit
65ccfedc0f

+ 8 - 10
ssat_sdk/MenuTree3/OptionConfig.py

@@ -1,11 +1,10 @@
 # -*- coding:utf-8 -*-
 import os
 from UIT_PathManage import UITPathManage
-from ssat_sdk.MenuTree3.BaseLog import CBaseLog
-from ssat_sdk.MenuTree3.TConfig import TConfig
+from BaseLog import CBaseLog
+from TConfig import TConfig
+from ExtraData import CExtraData
 
-# 测试加头文件;
-from TData import CTData
 
 g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
            'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth']
@@ -14,14 +13,15 @@ g_level = ['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth',
 # 注意:所有不对外暴露的变量和函数需要私有化,以明确哪些接口和参数是对外的。
 # 这样便于后期维护时,根据对外的变量和函数来做处理。
 class COptionConfig(TConfig, CBaseLog):
-    def __init__(self, menuTreeDir, pathManager):
+    def __init__(self, exData, pathManager):
+        self.__exData = exData
         self.__pathManager = pathManager
         if self.__pathManager is None:
             self.error(u"路径参数错误:None")
         # 状态:False表示路径值失败;
         self.status = False
         # menuTree目录;
-        self.__uiTreeDir = menuTreeDir
+        self.__uiTreeDir = self.__exData.menutreeDir
         # 判断是否为目录;
         if not os.path.isdir(self.__uiTreeDir):
             self.error(u"%s 不是menuTree目录" % self.__uiTreeDir)
@@ -184,7 +184,5 @@ class COptionConfig(TConfig, CBaseLog):
 
 
 if __name__ == "__main__":
-    tData = CTData()
-    upath = UITPathManage(tData)
-    opc = COptionConfig(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
-    print opc.getOptionICONConfig("picture")
+    exData = CExtraData()
+    

+ 357 - 24
ssat_sdk/MenuTree3/OptionExcel.py

@@ -1,5 +1,5 @@
 # -*- coding:utf-8 -*-
-import os
+import os, json
 from collections import OrderedDict
 from UIT_PathManage import UITPathManage
 from TExcelParser import CExcelParser
@@ -120,10 +120,45 @@ class COptionExcel(CBaseLog):
     def addExcel(self, xlsPath):
         self.__excelParse.read_excel(xlsPath)
 
-    
-    # 获取指定option/value_name下的所有子项(option/value)的ocr键对值;
-    # 示例:[{'suboption1': 'suboption1 ocr'}, {'suboption2': 'suboption2 ocr'}]
-    def getOptionSubitemMap(self, optionName, isOption = True):
+    '''
+    函数:获取指定option下的所有子项名称(option作为parent,获取该父项下的所有option字段)
+    '''
+    def getOptionAllChildItemName(self, optionName):
+        optionList = []
+        paths = self.__pathParams.paths
+        for level in paths:
+            if paths[level].has_key(optionName):
+                optionDictList = paths[level][optionName]["value"]
+                for optionDict in optionDictList:
+                    optionList.append(optionDict["option"])
+        # print "optionList:", optionList, type(optionList)
+        return optionList
+
+    '''
+        函数:获取指定option下的所有子项名称(option作为parent,获取该父项下的所有option字段)
+    '''
+
+    def getOptionAllChildItemOcr(self, optionName):
+        optionList = []
+        paths = self.__pathParams.paths
+        for level in paths:
+            if paths[level].has_key(optionName):
+                optionDictList = paths[level][optionName]["value"]
+                for optionDict in optionDictList:
+                    optionList.append(optionDict["option"])
+        # print "optionList:", optionList, type(optionList)
+        return optionList
+
+    '''
+    函数:获取指定option/value_name下的所有子项(option/value)的ocr键对值;
+    示例:
+        [
+            {'suboption1': 'suboption1 ocr'}, 
+            {'suboption2': 'suboption2 ocr'}
+        ]
+    '''
+
+    def getOptionAllChildItemMap(self, optionName, isOption=True):
         if type(optionName) == str:
             optionName = unicode(optionName)
         pairs = []
@@ -137,23 +172,98 @@ class COptionExcel(CBaseLog):
                         for item in self.__pathParams.paths[lev][optionName]["value"]:
                             pairs.append({item['option']: item['option_for_ocr'].split(';')})
                         break
-                    #endif
-                #endfor
+                    # endif
+                # endfor
                 if found is True:
                     break
-            #endfor
+            # endfor
         else:
             if optionName in self.__valueParams.values:
                 for item in self.__valueParams.values[optionName]["value"]:
                     pairs.append({item['value']: item['value_for_ocr'].split(';')})
-        #endif
+        # endif
 
         return pairs
 
-    
-    # 获取指定option/value_name下的所有子项(option/value)的ocr值;
-    # 示例:[['suboption1 ocr', 'ocr2', 'ocr3'],['suboption2 ocr'], ['suboption3 orc']]
-    def getOptionSubItemOcrList(self, optionName, isOption = True):
+    '''
+        函数:获取指定option/value_name下的所有兄弟项(相同parent)的ocr键对值;
+        示例:
+            [
+                {'suboption1': 'suboption1 ocr'}, 
+                {'suboption2': 'suboption2 ocr'}
+            ]
+    '''
+    def getOptionAllSiblingItemMap(self, optionName, isOption=True):
+        pass
+
+    '''
+    函数:获取指定option/value_name下的所有兄弟项(相同parent)的 ocr:option 字典值;
+    示例:
+        {
+            'option1_ocr': 'option1', 
+            'option2_ocr': 'option2',
+            'option3_ocr': 'option3',
+        }
+    '''
+    def getOptionAllSiblingItemDict(self, optionName, isOption=True):
+        # 编码转换;
+        if type(optionName) == str:
+            option = unicode(optionName)
+
+        found = False
+        dict_ocr = {}
+        list_ocr = []
+        if isOption is True:
+            # 首先,字典不排序,需要倒序;
+            paths = reversed(self.__pathParams.paths)
+            for level in paths:
+                for parent in self.__pathParams.paths[level]:
+                    for vals in self.__pathParams.paths[level][parent]["value"]:
+                        if vals['option'].lower() == option.lower():
+                            found = True
+                            break
+                    # endfor
+                    # 找到退出;
+                    if found is True:
+                        break
+                # endfor
+                # 找到退出;
+                if found is True:
+                    break
+
+            # 遍历value列表;
+            if found is True:
+                for val in self.__pathParams.paths[level][parent]["value"]:
+                    list_ocr = val['option_for_ocr'].split(';')
+                    for ocr in list_ocr:
+                        dict_ocr[ocr.lower()] = val['option']
+        else:
+            if option in self.__valueParams.values:
+                for val in self.__valueParams.values[option]["value"]:
+                    list_ocr = val['value_for_ocr'].split(';')
+                    for ocr in list_ocr:
+                        dict_ocr[ocr.lower()] = val['value']
+
+        print 'unsorted=', dict_ocr
+        # 按长度排序;
+        list_ocr = sorted(dict_ocr.keys(), key=lambda key: len(key), reverse=True)
+        dict_reuslt = OrderedDict()
+        for ocr in list_ocr:
+            dict_reuslt[ocr] = dict_ocr[ocr]
+        # 返回结果;
+        return dict_reuslt
+
+    '''
+        函数:获取指定option/value_name下的所有子项(option/value)的ocr值, 1d表示One-dimensional(一维数组);
+        示例:
+            [
+                ['suboption1 ocr', 'ocr2', 'ocr3'],
+                ['suboption2 ocr'], 
+                ['suboption3 orc']
+            ]
+        '''
+
+    def getOptionAllChildItemOcrList1d(self, optionName, isOption=True):
         if type(optionName) == str:
             optionName = unicode(optionName)
 
@@ -162,30 +272,253 @@ class COptionExcel(CBaseLog):
         if isOption is True:
             found = False
             for lev in self.__pathParams.paths:
-                for item in self.__pathParams.paths[lev]:
-                    if item.lower() == optionName.lower():
+                for parent in self.__pathParams.paths[lev]:
+                    if parent.lower() == optionName.lower():
+                        found = True
+                        for item in self.__pathParams.paths[lev][optionName]["value"]:
+                            list_ocr.extend(item['option_for_ocr'].split(';'))
+                        break
+                    # endif
+                # endfor
+                if found is True:
+                    break
+            # endfor
+        else:
+            if optionName in self.__valueParams.values:
+                self.info(u"找到%s的value表数据" % optionName)
+                for item in self.__valueParams.values[optionName]["value"]:
+                    list_ocr.extend(item['value_for_ocr'].split(';'))
+            else:
+                self.error(u"没有找到%s的value表数据" % optionName)
+        # endif
+        return list_ocr
+
+    '''
+    函数:获取指定option/value_name下的所有子项(option/value)的ocr值,2d表示Two-dimensional(二维数组);
+    示例:
+        [
+            ['suboption1 ocr', 'ocr2', 'ocr3'],
+            ['suboption2 ocr'], 
+            ['suboption3 orc']
+        ]
+    '''
+
+    def getOptionAllChildItemOcrList2d(self, optionName, isOption=True):
+        if type(optionName) == str:
+            optionName = unicode(optionName)
+
+        list_ocr = []
+        # 路径表或值表;
+        if isOption is True:
+            found = False
+            for lev in self.__pathParams.paths:
+                for parent in self.__pathParams.paths[lev]:
+                    if parent.lower() == optionName.lower():
                         found = True
                         for item in self.__pathParams.paths[lev][optionName]["value"]:
-                            if optionName.lower() != item['option'].lower():
-                                list_ocr.append(item['option_for_ocr'].split(';'))
+                            list_ocr.append(item['option_for_ocr'].split(';'))
                         break
-                    #endif
-                #endfor
+                    # endif
+                # endfor
                 if found is True:
                     break
-            #endfor
+            # endfor
         else:
             if optionName in self.__valueParams.values:
+                self.info(u"找到%s的value表数据" % optionName)
                 for item in self.__valueParams.values[optionName]["value"]:
                     list_ocr.append(item['value_for_ocr'].split(';'))
+            else:
+                self.error(u"没有找到%s的value表数据" % optionName)
         # endif
         return list_ocr
 
-    def getOption
+    '''
+    函数:获取指定option所有兄弟项(相同parent)的ocr值, 1d表示One-dimensional(一维数组);
+    示例:
+        [
+            ['option1 ocr', 'ocr2', 'ocr3'],
+            ['option2 ocr'], 
+            ['option3 orc']
+        ]
+    '''
+
+    def getOptionAllSiblingItemOcrList1d(self, optionName):
+        # 编码转换;
+        if type(optionName) == str:
+            optionName = unicode(optionName)
+
+        found = False
+        list_ocr = []
+        # 首先,字典不排序,需要倒序;
+        paths = reversed(self.__pathParams.paths)
+        for level in paths:
+            for parent in self.__pathParams.paths[level]:
+                for vals in self.__pathParams.paths[level][parent]["value"]:
+                    if vals['option'].lower() == optionName.lower():
+                        found = True
+                        break
+                # endfor
+                # 找到退出;
+                if found is True:
+                    break
+            # endfor
+            # 找到退出;
+            if found is True:
+                break
+        # endfor
+
+        # 遍历value列表;
+        if found is True:
+            for val in self.__pathParams.paths[level][parent]["value"]:
+                list_ocr.extend(val['option_for_ocr'].split(';'))
+        # 按长度排序;
+        list_ocr.sort(key=lambda i: len(i), reverse=True)
+        # 返回结果;
+        return list_ocr
+
+    '''
+    函数:获取指定option的ocr,以list返回
+    '''
+    def getOptionOcr(self, optionName):
+        # 编码转换;
+        if type(optionName) == str:
+            option = unicode(optionName)
+
+        found = False
+        list_ocr = []
+        # 首先,字典不排序,需要倒序;
+        paths = reversed(self.__pathParams.paths)
+        for level in paths:
+            for parent in self.__pathParams.paths[level]:
+                for vals in self.__pathParams.paths[level][parent]["value"]:
+                    if vals['option'].lower() == option.lower():
+                        list_ocr = vals['option_for_ocr'].split(';')
+                        found = True
+                        break
+                # endfor
+                # 找到退出;
+                if found is True:
+                    break
+            # endfor
+            # 找到退出;
+            if found is True:
+                break
+        # endfor
+        # 返回结果;
+        return list_ocr
+
+    '''
+        函数:获取指定option的value表值,如果参数value未指定具体值则获取全部valueName的值;
+        示例:
+        {
+            "option":"option名称",
+            "values":[option在value表中的所有value字段],
+            "value_for_ocr":[option在value表中所有value_for_ocr字段],
+            "enter_key":"",
+            "move_key":"",
+            "others":"",
+        }
+    '''
+    def getOptionValues(self, optionName, value=""):
+        # 编码转换;
+        if type(optionName) == str:
+            option = unicode(optionName)
+
+        # option/value name是否在value表中的;
+        if optionName not in self.__valueParams.values:
+            return []
+
+        optValues = self.valueParams.values[option]["value"]
+        valueList = []
+        valueOcrList = []
+        for item in optValues:
+            valueList.append(item["value"])
+            valueOcrList.append(item["value_for_ocr"])
+
+        vp = {"option": option, "value": valueList, "value_for_ocr": valueOcrList,
+              "enter_key": self.valueParams.values[option]["enter_key"],
+              "move_key": self.valueParams.values[option]["move_key"],
+              "others": self.valueParams.values[option]['others']}
+        # 找到value对应的ocr;
+        if value != "":
+            vp["value"] = value
+            for item in self.valueParams.values[option]["value"]:
+                if "range(" in item["value"]:
+                    vp["value_for_ocr"] = item["value_for_ocr"].split(';')
+                    break
+                elif item["value"].lower() == value.lower():
+                    vp["value_for_ocr"] = item["value_for_ocr"].split(';')
+                    break
+            # endfor
+        # endif
+        # 返回结果;
+        return vp
+
+    def getOptionInfo(self, optionName):
+        # 编码转换;
+        if type(optionName) == str:
+            option = unicode(optionName)
+
+        found = False
+        layers = 0
+        dict_option = {}
+        # 首先,字典不排序,需要倒序;
+        paths = reversed(self.__pathParams.paths)
+        for level in paths:
+            for parent in self.__pathParams.paths[level]:
+                for vals in self.__pathParams.paths[level][parent]["value"]:
+                    if vals['option'].lower() == option.lower():
+                        if dict_option.__len__() == 0:
+                            found = True
+                            dict_option['level'] = level
+                            dict_option['parent'] = parent
+                            dict_option['others'] = self.__pathParams.paths[level][parent]['others']
+                            dict_option['enter_key'] = self.__pathParams.paths[level][parent]['enter_key']
+                            dict_option['move_key'] = self.__pathParams.paths[level][parent]['move_key']
+                            dict_option['option_ocr'] = vals['option_for_ocr'].split(';')
+                            dict_option['option_move_key'] = vals['option_move_key']
+                            dict_option['option_enter_key'] = vals['option_enter_key']
+                            dict_option['option_others'] = vals['option_others']
+                        option = parent
+                        layers += 1  # 层数;
+                        break
+                # endfor
+            # endfor
+        # endfor
+        if found is True:
+            dict_option['layers'] = layers
+            # first层次的parent名称;
+            dict_option['first_parent'] = option
+        # 返回结果;
+        return found, dict_option
+
+    '''
+    函数:获取指定的option在value表中的所有value字段;
+    '''
+    def getOptionAllValueName(self, optionName):
+        valueList = []
+        if self.valueParams.values.has_key(optionName):
+            valueDictList = self.valueParams.values[optionName]["value"]
+            for valueDict in valueDictList:
+                valueList.append(valueDict["value"])
+        # print "valueList:", valueList, type(valueList)
+        if valueList.__len__() == 1 and "range(" in valueList[0]:
+            value_for_ocr_low = str(valueList[0]).lower()
+            str_num = value_for_ocr_low.replace("range", "")
+            list_num = eval(str_num)
+            min_num = list_num[0]
+            max_num = list_num[1]
+            return [min_num, max_num]
+
+        return valueList
 
 if __name__ == "__main__":
     exData = CExtraData()
     opxls = COptionExcel(exData)
-    # print opxls.pathParams.paths
-    print u"getOptionMap", opxls.getOptionSubitemMap('picture')
-    print u"getOptionSubItemOcrList", opxls.getOptionSubItemOcrList('picture', False)
+    # print json.dumps(opxls.pathParams.paths)
+    # print u"getOptionMap", opxls.getOptionAllChildItemMap('picture')
+    # print u"getOptionAllChildItemOcrList1d", opxls.getOptionAllChildItemOcrList1d('picture', False)
+    # print u"getOptionAllChildItemOcrList2d", opxls.getOptionAllChildItemOcrList2d('picture', False)
+    # print "getOptionAllSiblingItemOcrList", opxls.getOptionAllSiblingItemOcrList('picture')
+    print "getOptionAllChildItem", opxls.getOptionAllChildItem('picture')

+ 0 - 1
ssat_sdk/MenuTree3/OptionFocus.py

@@ -14,7 +14,6 @@ from BaseLog import CBaseLog
 from OptionConfig import COptionConfig
 
 # 测试加头文件;
-from TData import CTData
 from UIT_PathManage import UITPathManage
 
 

+ 1 - 4
ssat_sdk/MenuTree3/OptionOCR.py

@@ -110,7 +110,4 @@ class COptionOCR(CBaseLog):
 
 
 if __name__ == "__main__":
-    tData = CTData()
-    upath = UITPathManage(tData)
-    opcfg = COptionConfig(r'D:\SAT\resource\MenuTree\RT2851\2851', upath)
-    opfocus = COptionOCR(opcfg, upath)
+    pass

+ 1 - 1
ssat_sdk/MenuTree3/TExcelParser.py

@@ -63,7 +63,7 @@ class CExcelParser(CBaseLog):
             self.parsePath(sheet,pKeys, self.__optionExcel.pathParams)
 
 
-    def parsePath(self, sheet,pKeys, treeParams):
+    def parsePath(self, sheet, pKeys, treeParams):
         parentName = None
         for i in range(1, sheet.nrows):
             # 获取每行内容;