Fix minor bugs caused from merging in setupcontroller; Initialize vscode example loading
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
import pandas as pd
|
||||
import logging
|
||||
import operator
|
||||
from numbers import Number
|
||||
from typing import Any, Union
|
||||
from typing import Dict, List
|
||||
|
||||
import openpyxl
|
||||
import pandas as pd
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.worksheet.worksheet import Worksheet
|
||||
|
||||
from .utils import load_charts, load_sparklines
|
||||
import operator
|
||||
|
||||
from typing import Dict, List
|
||||
from typing import Any, Union
|
||||
from numbers import Number
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger("desktopenv.metric.table")
|
||||
|
||||
|
||||
def compare_table(actual: str, expected: str, **options) -> float:
|
||||
"""
|
||||
Args:
|
||||
@@ -44,28 +45,28 @@ def compare_table(actual: str, expected: str, **options) -> float:
|
||||
workbook1: Workbook = openpyxl.load_workbook(actual)
|
||||
workbook2: Workbook = openpyxl.load_workbook(expected)
|
||||
|
||||
if ftr=="sparkline":
|
||||
if ftr == "sparkline":
|
||||
sp1 = load_sparklines(actual)
|
||||
sp2 = load_sparklines(expected)
|
||||
new_metric: bool = sp1 == sp2
|
||||
logger.debug("Sparkline Metric: {:}".format(new_metric))
|
||||
elif ftr=="chart":
|
||||
elif ftr == "chart":
|
||||
charts1 = load_charts(workbook1, **options)
|
||||
charts2 = load_charts(workbook2, **options)
|
||||
new_metric: bool = charts1 == charts2
|
||||
logger.debug("Chart Metric: {:}".format(new_metric))
|
||||
elif ftr=="number_format":
|
||||
number_formats1: List[str] = [ c.number_format.lower()\
|
||||
for col in workbook1.active.iter_cols()\
|
||||
for c in col\
|
||||
if c.data_type=="n"
|
||||
]
|
||||
number_formats2: List[str] = [ c.number_format.lower()\
|
||||
for col in workbook2.active.iter_cols()\
|
||||
for c in col\
|
||||
if c.data_type=="n"
|
||||
]
|
||||
new_metric: bool = number_formats1==number_formats2
|
||||
elif ftr == "number_format":
|
||||
number_formats1: List[str] = [c.number_format.lower() \
|
||||
for col in workbook1.active.iter_cols() \
|
||||
for c in col \
|
||||
if c.data_type == "n"
|
||||
]
|
||||
number_formats2: List[str] = [c.number_format.lower() \
|
||||
for col in workbook2.active.iter_cols() \
|
||||
for c in col \
|
||||
if c.data_type == "n"
|
||||
]
|
||||
new_metric: bool = number_formats1 == number_formats2
|
||||
logger.debug("Number Format Metric: {:}".format(new_metric))
|
||||
else:
|
||||
raise NotImplementedError("Unsupported xlsx feature: {:}".format(ftr))
|
||||
@@ -73,6 +74,7 @@ def compare_table(actual: str, expected: str, **options) -> float:
|
||||
|
||||
return float(metric)
|
||||
|
||||
|
||||
def check_sheet_list(result: str, rules: List[Dict[str, Any]]) -> float:
|
||||
if result is None:
|
||||
return 0.
|
||||
@@ -114,6 +116,7 @@ def check_sheet_list(result: str, rules: List[Dict[str, Any]]) -> float:
|
||||
|
||||
return float(passes)
|
||||
|
||||
|
||||
def check_xlsx_freeze(result: str, rules: Dict[str, str]) -> float:
|
||||
if result is None:
|
||||
return 0.
|
||||
@@ -121,16 +124,18 @@ def check_xlsx_freeze(result: str, rules: Dict[str, str]) -> float:
|
||||
worksheet: Worksheet = openpyxl.load_workbook(filename=result).active
|
||||
return float(worksheet.freeze_panes == rules["position"])
|
||||
|
||||
|
||||
def check_xlsx_zoom(result: str, rules: Dict[str, Union[str, Number]]) -> float:
|
||||
if result is None:
|
||||
return 0.
|
||||
|
||||
worksheet = openpyxl.load_workbook(filename=result).active
|
||||
zoom_scale: Number = worksheet.sheet_view.zoomScale or 100.
|
||||
return float( getattr(operator, rules["relation"])( zoom_scale
|
||||
return float(getattr(operator, rules["relation"])(zoom_scale
|
||||
, rules["ref_value"]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# path1 = ""
|
||||
@@ -168,51 +173,51 @@ if __name__ == '__main__':
|
||||
# ]
|
||||
# print(check_sheet_list(path1, rule))
|
||||
|
||||
#path1 = "../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold.xlsx"
|
||||
#path2 = "../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold2.xlsx"
|
||||
#print(compare_table(path1, path2, features=["chart"], chart_props=["type", "direction"]))
|
||||
# path1 = "../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold.xlsx"
|
||||
# path2 = "../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold2.xlsx"
|
||||
# print(compare_table(path1, path2, features=["chart"], chart_props=["type", "direction"]))
|
||||
|
||||
#path1 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold.xlsx"
|
||||
#path2 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold3.xlsx"
|
||||
#path1 = "../../任务数据/LibreOffice Calc/Set_Decimal_Separator_Dot.xlsx"
|
||||
#path2 = "../../任务数据/LibreOffice Calc/Set_Decimal_Separator_Dot_gold.xlsx"
|
||||
#workbook1: Workbook = openpyxl.load_workbook(filename=path1)
|
||||
#worksheet1: Worksheet = workbook1.active
|
||||
#import itertools
|
||||
#for col, r in itertools.product( ['A', 'B']
|
||||
#, range(1, 20)
|
||||
#):
|
||||
#position: str = "{:}{:d}".format(col, r)
|
||||
#print(worksheet1[position])
|
||||
#print(worksheet1[position].value)
|
||||
#print(worksheet1[position].number_format)
|
||||
#workbook2: Workbook = openpyxl.load_workbook(filename=path2)
|
||||
#worksheet2: Worksheet = workbook2.active
|
||||
#for col, r in itertools.product( ['A', 'B']
|
||||
#, range(1, 20)
|
||||
#):
|
||||
#position: str = "{:}{:d}".format(col, r)
|
||||
#print(worksheet2[position])
|
||||
#print(worksheet2[position].value)
|
||||
#print(worksheet2[position].number_format)
|
||||
#print(compare_table(path1, path2, features=["number_format"]))
|
||||
# path1 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold.xlsx"
|
||||
# path2 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold3.xlsx"
|
||||
# path1 = "../../任务数据/LibreOffice Calc/Set_Decimal_Separator_Dot.xlsx"
|
||||
# path2 = "../../任务数据/LibreOffice Calc/Set_Decimal_Separator_Dot_gold.xlsx"
|
||||
# workbook1: Workbook = openpyxl.load_workbook(filename=path1)
|
||||
# worksheet1: Worksheet = workbook1.active
|
||||
# import itertools
|
||||
# for col, r in itertools.product( ['A', 'B']
|
||||
# , range(1, 20)
|
||||
# ):
|
||||
# position: str = "{:}{:d}".format(col, r)
|
||||
# print(worksheet1[position])
|
||||
# print(worksheet1[position].value)
|
||||
# print(worksheet1[position].number_format)
|
||||
# workbook2: Workbook = openpyxl.load_workbook(filename=path2)
|
||||
# worksheet2: Worksheet = workbook2.active
|
||||
# for col, r in itertools.product( ['A', 'B']
|
||||
# , range(1, 20)
|
||||
# ):
|
||||
# position: str = "{:}{:d}".format(col, r)
|
||||
# print(worksheet2[position])
|
||||
# print(worksheet2[position].value)
|
||||
# print(worksheet2[position].number_format)
|
||||
# print(compare_table(path1, path2, features=["number_format"]))
|
||||
|
||||
#path1 = "../../任务数据/LibreOffice Calc/Zoom_Out_Oversized_Cells_gold.xlsx"
|
||||
#path2 = "../../任务数据/LibreOffice Calc/Zoom_Out_Oversized_Cells.xlsx"
|
||||
#workbook1: Workbook = openpyxl.load_workbook(filename=path1)
|
||||
#worksheet1: Worksheet = workbook1.active
|
||||
#print(worksheet1.sheet_view.zoomScale)
|
||||
#print(type(worksheet1.sheet_view.zoomScale))
|
||||
#
|
||||
#import os
|
||||
#import os.path
|
||||
#for wb in filter( lambda f: f.endswith(".xlsx")
|
||||
#, os.listdir("../../任务数据/LibreOffice Calc/")
|
||||
#):
|
||||
#path = os.path.join("../../任务数据/LibreOffice Calc/", wb)
|
||||
#print(wb, openpyxl.load_workbook(filename=path).active.sheet_view.zoomScale)
|
||||
#print(check_zoom(path1, {"relation": "lt", "ref_value": 100}))
|
||||
#print(check_zoom(path2, {"relation": "lt", "ref_value": 100}))
|
||||
# path1 = "../../任务数据/LibreOffice Calc/Zoom_Out_Oversized_Cells_gold.xlsx"
|
||||
# path2 = "../../任务数据/LibreOffice Calc/Zoom_Out_Oversized_Cells.xlsx"
|
||||
# workbook1: Workbook = openpyxl.load_workbook(filename=path1)
|
||||
# worksheet1: Worksheet = workbook1.active
|
||||
# print(worksheet1.sheet_view.zoomScale)
|
||||
# print(type(worksheet1.sheet_view.zoomScale))
|
||||
#
|
||||
# import os
|
||||
# import os.path
|
||||
# for wb in filter( lambda f: f.endswith(".xlsx")
|
||||
# , os.listdir("../../任务数据/LibreOffice Calc/")
|
||||
# ):
|
||||
# path = os.path.join("../../任务数据/LibreOffice Calc/", wb)
|
||||
# print(wb, openpyxl.load_workbook(filename=path).active.sheet_view.zoomScale)
|
||||
# print(check_zoom(path1, {"relation": "lt", "ref_value": 100}))
|
||||
# print(check_zoom(path2, {"relation": "lt", "ref_value": 100}))
|
||||
|
||||
path1 = "../../任务数据/LibreOffice Calc/Padding_Decimals_In_Formular_gold.xlsx"
|
||||
data_frame: pd.DataFrame = pd.read_excel(path1)
|
||||
|
||||
Reference in New Issue
Block a user