update number format
This commit is contained in:
parent
5343623b59
commit
4b36448ede
@ -461,6 +461,15 @@ def get_value(_dict, keys):
|
||||
|
||||
|
||||
def dict2xlsx(input: json, _type='report'):
|
||||
if _type == 'report':
|
||||
wb = dump_excel_report(input=input)
|
||||
elif _type == 'report_detail':
|
||||
wb = dump_excel_report_detail(input=input)
|
||||
elif _type == 'billing_report':
|
||||
wb = dump_excel_billing_report(input=input)
|
||||
return wb
|
||||
|
||||
def dump_excel_report(input: json):
|
||||
red = "FF0000"
|
||||
black = "000000"
|
||||
green = "E2EFDA"
|
||||
@ -474,8 +483,6 @@ def dict2xlsx(input: json, _type='report'):
|
||||
fill_green = PatternFill(start_color=green, end_color=green, fill_type = "solid")
|
||||
fill_yellow = PatternFill(start_color=yellow, end_color=yellow, fill_type = "solid")
|
||||
fill_gray = PatternFill(start_color=gray, end_color=gray, fill_type = "solid")
|
||||
align_right = Alignment(horizontal='right')
|
||||
if _type == 'report':
|
||||
wb = load_workbook(filename = 'report.xlsx')
|
||||
ws = wb['Sheet1']
|
||||
mapping = {
|
||||
@ -499,8 +506,44 @@ def dict2xlsx(input: json, _type='report'):
|
||||
'R': 'review_progress'
|
||||
}
|
||||
start_index = 5
|
||||
for subtotal in input:
|
||||
for key in mapping.keys():
|
||||
value = get_value(subtotal, mapping[key])
|
||||
ws[key + str(start_index)] = value
|
||||
if key in ['C', 'D', 'E'] and value == 0:
|
||||
ws[key + str(start_index)] = "-"
|
||||
ws[key + str(start_index)].border = border
|
||||
ws[key + str(start_index)].font = font_black
|
||||
if 'accuracy' in mapping[key] or 'time' in mapping[key] or 'percent' in mapping[key] or 'speed' in mapping[key] or mapping[key] in ["review_progress"]:
|
||||
ws[key + str(start_index)].number_format = '0.0'
|
||||
|
||||
elif _type == 'report_detail':
|
||||
if subtotal['subs'] == '+':
|
||||
ws[key + str(start_index)].font = font_black_bold
|
||||
if key in ['A', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R']:
|
||||
ws[key + str(start_index)].fill = fill_gray
|
||||
elif key == 'B':
|
||||
ws[key + str(start_index)].fill = fill_green
|
||||
elif key in ['C', 'D', 'E', 'F', 'G', 'H']:
|
||||
ws[key + str(start_index)].fill = fill_yellow
|
||||
if 'average_accuracy_rate' in mapping[key] and type(value) in [int, float] and value < 98:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
elif 'average_processing_time' in mapping[key] and type(value) in [int, float] and value > 2.0:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
elif 'bad_percent' in mapping[key] and type(value) in [int, float] and value > 10:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
|
||||
if key in ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'K']:
|
||||
ws[key + str(start_index)].number_format= '#,##0'
|
||||
start_index += 1
|
||||
return wb
|
||||
|
||||
def dump_excel_report_detail(input: json):
|
||||
red = "FF0000"
|
||||
black = "000000"
|
||||
font_black = Font(name="Calibri", size=11, color=black)
|
||||
font_red = Font(name="Calibri", size=11, color=red)
|
||||
thin = Side(border_style="thin", color=black)
|
||||
border = Border(left=thin, right=thin, top=thin, bottom=thin)
|
||||
wb = load_workbook(filename = 'report_detail.xlsx')
|
||||
ws = wb['Sheet1']
|
||||
mapping = {
|
||||
@ -536,8 +579,30 @@ def dict2xlsx(input: json, _type='report'):
|
||||
'AD':'retailer_revised_accuracy',
|
||||
}
|
||||
start_index = 4
|
||||
for subtotal in input:
|
||||
for key in mapping.keys():
|
||||
value = get_value(subtotal, mapping[key])
|
||||
ws[key + str(start_index)] = value
|
||||
if key in ['C', 'D', 'E'] and value == 0:
|
||||
ws[key + str(start_index)] = "-"
|
||||
ws[key + str(start_index)].border = border
|
||||
ws[key + str(start_index)].font = font_black
|
||||
if 'accuracy' in mapping[key] or 'time' in mapping[key] or 'percent' in mapping[key] or 'speed' in mapping[key] or mapping[key] in ["review_progress"]:
|
||||
ws[key + str(start_index)].number_format = '0.0'
|
||||
|
||||
elif _type == 'billing_report':
|
||||
if 'accuracy' in mapping[key] and type(value) in [int, float] and value < 75:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
elif 'speed' in mapping[key] and type(value) in [int, float] and value > 2.0:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
start_index += 1
|
||||
return wb
|
||||
|
||||
def dump_excel_billing_report(input: json):
|
||||
black = "000000"
|
||||
font_black = Font(name="Calibri", size=11, color=black)
|
||||
thin = Side(border_style="thin", color=black)
|
||||
border = Border(left=thin, right=thin, top=thin, bottom=thin)
|
||||
align_right = Alignment(horizontal='right')
|
||||
wb = load_workbook(filename = 'billing_report.xlsx')
|
||||
ws = wb['Sheet1']
|
||||
mapping = {
|
||||
@ -553,37 +618,6 @@ def dict2xlsx(input: json, _type='report'):
|
||||
|
||||
for subtotal in input:
|
||||
for key in mapping.keys():
|
||||
if _type!="billing_report":
|
||||
value = get_value(subtotal, mapping[key])
|
||||
ws[key + str(start_index)] = value
|
||||
if key in ['C', 'D', 'E'] and value == 0:
|
||||
ws[key + str(start_index)] = "-"
|
||||
ws[key + str(start_index)].border = border
|
||||
ws[key + str(start_index)].font = font_black
|
||||
if 'accuracy' in mapping[key] or 'time' in mapping[key] or 'percent' in mapping[key] or 'speed' in mapping[key] or mapping[key] in ["review_progress"]:
|
||||
ws[key + str(start_index)].number_format = '0.0'
|
||||
|
||||
if _type == 'report':
|
||||
if subtotal['subs'] == '+':
|
||||
ws[key + str(start_index)].font = font_black_bold
|
||||
if key in ['A', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R']:
|
||||
ws[key + str(start_index)].fill = fill_gray
|
||||
elif key == 'B':
|
||||
ws[key + str(start_index)].fill = fill_green
|
||||
elif key in ['C', 'D', 'E', 'F', 'G', 'H']:
|
||||
ws[key + str(start_index)].fill = fill_yellow
|
||||
if 'average_accuracy_rate' in mapping[key] and type(value) in [int, float] and value < 98:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
elif 'average_processing_time' in mapping[key] and type(value) in [int, float] and value > 2.0:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
elif 'bad_percent' in mapping[key] and type(value) in [int, float] and value > 10:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
elif _type == 'report_detail':
|
||||
if 'accuracy' in mapping[key] and type(value) in [int, float] and value < 75:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
elif 'speed' in mapping[key] and type(value) in [int, float] and value > 2.0:
|
||||
ws[key + str(start_index)].font = font_red
|
||||
else:
|
||||
value = get_value(subtotal, mapping[key])
|
||||
value = "-" if value=="" else value
|
||||
ws[key + str(start_index)] = value
|
||||
|
Loading…
Reference in New Issue
Block a user