Merge pull request #33 from SDSRV-IDP/vietanh99-update-xlsx
Vietanh99 update xlsx
This commit is contained in:
commit
876fbe405d
@ -433,9 +433,7 @@ def dict2xlsx(input: json, _type='report'):
|
|||||||
border = Border(left=thin, right=thin, top=thin, bottom=thin)
|
border = Border(left=thin, right=thin, top=thin, bottom=thin)
|
||||||
fill_green = PatternFill(start_color=green, end_color=green, fill_type = "solid")
|
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_yellow = PatternFill(start_color=yellow, end_color=yellow, fill_type = "solid")
|
||||||
fill_gray = PatternFill(start_color=gray, end_color=gray, fill_type = "solid")
|
fill_gray = PatternFill(start_color=gray, end_color=gray, fill_type = "solid")
|
||||||
normal_cell = NamedStyle(name="normal_cell", font=font_black, border=border)
|
|
||||||
normal_cell_red = NamedStyle(name="normal_cell_red", font=font_red, border=border)
|
|
||||||
|
|
||||||
if _type == 'report':
|
if _type == 'report':
|
||||||
wb = load_workbook(filename = 'report.xlsx')
|
wb = load_workbook(filename = 'report.xlsx')
|
||||||
@ -490,49 +488,36 @@ def dict2xlsx(input: json, _type='report'):
|
|||||||
start_index = 4
|
start_index = 4
|
||||||
|
|
||||||
for subtotal in input:
|
for subtotal in input:
|
||||||
for key_index, key in enumerate(mapping.keys()):
|
for key in mapping.keys():
|
||||||
value = get_value(subtotal, mapping[key])
|
value = get_value(subtotal, mapping[key])
|
||||||
ws[key + str(start_index)] = value
|
ws[key + str(start_index)] = value
|
||||||
ws[key + str(start_index)].border = border
|
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]:
|
||||||
|
ws[key + str(start_index)].number_format = '0.0'
|
||||||
|
|
||||||
if _type == 'report':
|
if _type == 'report':
|
||||||
if subtotal['subs'] == '+':
|
if subtotal['subs'] == '+':
|
||||||
ws[key + str(start_index)].font = font_black_bold
|
ws[key + str(start_index)].font = font_black_bold
|
||||||
if key_index in [6, 8, 9, 10, 11, 12, 13]:
|
if key in ['A', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q']:
|
||||||
ws[key + str(start_index)].number_format = '0.0'
|
|
||||||
if key_index == 0 or (key_index >= 9 and key_index <= 15):
|
|
||||||
ws[key + str(start_index)].fill = fill_gray
|
ws[key + str(start_index)].fill = fill_gray
|
||||||
elif key_index == 1:
|
elif key == 'B':
|
||||||
ws[key + str(start_index)].fill = fill_green
|
ws[key + str(start_index)].fill = fill_green
|
||||||
elif key_index >= 4 and key_index <= 8:
|
elif key in ['C', 'D', 'E', 'F', 'G', 'H']:
|
||||||
ws[key + str(start_index)].fill = fill_yellow
|
ws[key + str(start_index)].fill = fill_yellow
|
||||||
else:
|
else:
|
||||||
if 'average_accuracy_rate' in mapping[key] and type(value) in [int, float]:
|
if 'average_accuracy_rate' in mapping[key] and type(value) in [int, float] and value < 98:
|
||||||
if value < 98:
|
ws[key + str(start_index)].font = font_red
|
||||||
ws[key + str(start_index)].style = normal_cell_red
|
elif 'average_processing_time' in mapping[key] and type(value) in [int, float] and value > 2.0:
|
||||||
ws[key + str(start_index)].number_format = '0.0'
|
ws[key + str(start_index)].font = font_red
|
||||||
elif 'average_processing_time' in mapping[key] and type(value) in [int, float]:
|
elif 'bad_percent' in mapping[key] and type(value) in [int, float] and value > 10:
|
||||||
if value > 2.0:
|
ws[key + str(start_index)].font = font_red
|
||||||
ws[key + str(start_index)].style = normal_cell_red
|
|
||||||
ws[key + str(start_index)].number_format = '0.0'
|
|
||||||
elif 'bad_percent' in mapping[key] and type(value) in [int, float]:
|
|
||||||
if value > 10:
|
|
||||||
ws[key + str(start_index)].style = normal_cell_red
|
|
||||||
ws[key + str(start_index)].number_format = '0.0'
|
|
||||||
elif 'percent' in mapping[key] and type(value) in [int, float]:
|
|
||||||
ws[key + str(start_index)].number_format = '0.0'
|
|
||||||
else :
|
|
||||||
ws[key + str(start_index)].style = normal_cell
|
|
||||||
elif _type == 'report_detail':
|
elif _type == 'report_detail':
|
||||||
if 'accuracy' in mapping[key] and type(value) in [int, float] and value < 75:
|
if 'accuracy' in mapping[key] and type(value) in [int, float] and value < 75:
|
||||||
ws[key + str(start_index)].number_format = '0.0'
|
ws[key + str(start_index)].font = font_red
|
||||||
ws[key + str(start_index)].style = normal_cell_red
|
|
||||||
elif 'speed' in mapping[key] and type(value) in [int, float] and value > 2.0:
|
elif 'speed' in mapping[key] and type(value) in [int, float] and value > 2.0:
|
||||||
ws[key + str(start_index)].number_format = '0.0'
|
ws[key + str(start_index)].font = font_red
|
||||||
ws[key + str(start_index)].style = normal_cell_red
|
|
||||||
else:
|
|
||||||
ws[key + str(start_index)].style = normal_cell
|
|
||||||
|
|
||||||
start_index += 1
|
start_index += 1
|
||||||
|
|
||||||
return wb
|
return wb
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user