Merge branch 'develop' of https://github.com/myems/myems into develop
commit
9754b0b8cb
|
@ -351,8 +351,13 @@ def generate_excel(report,
|
|||
current_row_number = 19
|
||||
|
||||
has_child_flag = True
|
||||
|
||||
if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \
|
||||
len(report['child_space']["energy_category_names"]) == 0:
|
||||
len(report['child_space']["energy_category_names"]) == 0 \
|
||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
||||
or report['child_space']['energy_category_names'] is None \
|
||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
||||
or len(report['child_space']['child_space_names_array'][0]) == 0:
|
||||
has_child_flag = False
|
||||
|
||||
if has_child_flag:
|
||||
|
@ -362,6 +367,7 @@ def generate_excel(report,
|
|||
ws['B' + str(current_row_number)] = name + ' 子空间数据'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
|
@ -413,20 +419,21 @@ def generate_excel(report,
|
|||
ws[col + row] = round(every_day_sum, 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
table_end_row_number = current_row_number
|
||||
current_row_number += 1
|
||||
chart_start_row_number = current_row_number
|
||||
|
||||
# Pie
|
||||
for i in range(0, ca_len):
|
||||
pie = PieChart()
|
||||
labels = Reference(ws, min_col=2, min_row=current_row_number - space_len, max_row=current_row_number - 1)
|
||||
pie_data = Reference(ws, min_col=3 + i, min_row=current_row_number - space_len - 1,
|
||||
max_row=current_row_number - 1)
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number,
|
||||
max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 6.6
|
||||
pie.width = 8
|
||||
col = chr(ord('C') + i)
|
||||
pie.title = ws[col + '20'].value
|
||||
pie.title = ws.cell(column=3+i, row=table_start_row_number).value
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
|
@ -434,15 +441,17 @@ def generate_excel(report,
|
|||
s1.dLbls.showPercent = True
|
||||
chart_cell = ''
|
||||
if i % 2 == 0:
|
||||
chart_cell = 'B' + str(current_row_number)
|
||||
chart_cell = 'B' + str(chart_start_row_number)
|
||||
else:
|
||||
chart_cell = 'E' + str(current_row_number)
|
||||
current_row_number += 5
|
||||
chart_cell = 'E' + str(chart_start_row_number)
|
||||
chart_start_row_number += 5
|
||||
ws.add_chart(pie, chart_cell)
|
||||
|
||||
# chart_col = chr(ord('B') + 2 * i)
|
||||
# chart_cell = chart_col + str(current_row_number)
|
||||
# ws.add_chart(pie, chart_cell)
|
||||
current_row_number = chart_start_row_number
|
||||
|
||||
if ca_len % 2 == 1:
|
||||
current_row_number += 5
|
||||
|
||||
|
|
|
@ -395,9 +395,16 @@ def generate_excel(report,
|
|||
has_child_flag = True
|
||||
# Judge if the space has child space, if not, delete it.
|
||||
if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \
|
||||
len(report['child_space']["energy_category_names"]) == 0:
|
||||
len(report['child_space']["energy_category_names"]) == 0 \
|
||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
||||
or report['child_space']['energy_category_names'] is None \
|
||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
||||
or len(report['child_space']['child_space_names_array'][0]) == 0:
|
||||
|
||||
has_child_flag = False
|
||||
|
||||
current_row_number = 19
|
||||
|
||||
if has_child_flag:
|
||||
child = report['child_space']
|
||||
child_spaces = child['child_space_names_array'][0]
|
||||
|
@ -411,6 +418,8 @@ def generate_excel(report,
|
|||
ws['B20'].border = f_border
|
||||
ca_len = len(child['energy_category_names'])
|
||||
|
||||
table_start_row_number = 20
|
||||
|
||||
for i in range(0, ca_len):
|
||||
row = chr(ord('C') + i)
|
||||
ws[row + '20'].fill = table_fill
|
||||
|
@ -420,6 +429,7 @@ def generate_excel(report,
|
|||
ws[row + '20'] = child['energy_category_names'][i] + ' (' + child['units'][i] + ')'
|
||||
|
||||
space_len = len(child['child_space_names_array'][0])
|
||||
|
||||
for i in range(0, space_len):
|
||||
row = str(i + 21)
|
||||
|
||||
|
@ -434,12 +444,17 @@ def generate_excel(report,
|
|||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(child['subtotals_array'][j][i], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
table_end_row_number = 20 + space_len
|
||||
chart_start_row_number = 20 + space_len + 1
|
||||
|
||||
for i in range(0, ca_len):
|
||||
# pie
|
||||
# 25~30: pie
|
||||
pie = PieChart()
|
||||
pie.title = ws.cell(column=3 + j, row=20).value
|
||||
labels = Reference(ws, min_col=2, min_row=21, max_row=24)
|
||||
pie_data = Reference(ws, min_col=3 + j, min_row=20, max_row=24)
|
||||
pie.title = ws.cell(column=3 + i, row=table_start_row_number).value
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 6.6 # cm 1.05*5 1.05cm = 30 pt
|
||||
|
@ -447,45 +462,56 @@ def generate_excel(report,
|
|||
# pie.title = "Pies sold by category"
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = True # 标签显示
|
||||
s1.dLbls.showCatName = False # 标签显示
|
||||
s1.dLbls.showVal = True # 数量显示
|
||||
s1.dLbls.showPercent = True # 百分比显示
|
||||
# s1 = CharacterProperties(sz=1800) # 图表中字体大小 *100
|
||||
chart_col = chr(ord('B') + 2 * j)
|
||||
chart_cell = chart_col + '25'
|
||||
ws.add_chart(pie, chart_cell)
|
||||
chart_cell = ''
|
||||
if i % 2 == 0:
|
||||
chart_cell = 'B' + str(chart_start_row_number)
|
||||
else:
|
||||
for i in range(19, 36 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
for i in range(30, 35 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
chart_cell = 'E' + str(chart_start_row_number)
|
||||
chart_start_row_number += 5
|
||||
# ws.add_chart(pie, chart_cell)
|
||||
# chart_col = chr(ord('B') + 2 * j)
|
||||
# chart_cell = chart_col + '25'
|
||||
ws.add_chart(pie, chart_cell)
|
||||
|
||||
current_row_number = chart_start_row_number
|
||||
|
||||
if ca_len % 2 == 1:
|
||||
current_row_number += 5
|
||||
|
||||
current_row_number += 1
|
||||
|
||||
################################################
|
||||
# Fourth: 能耗详情
|
||||
# 37: title
|
||||
# 38~ 38+ca_len*6-1: line
|
||||
# 38+ca_len*6: table title
|
||||
# 38+ca_len*6~: table_data
|
||||
# current_row_number: title
|
||||
# current_row_number+1 ~ current_row_number+1+ca_len*6-1: line
|
||||
# current_row_number+1+ca_len*6: table title
|
||||
# current_row_number+1+ca_len*6~: table_data
|
||||
################################################
|
||||
reporting_period_data = report['reporting_period']
|
||||
times = reporting_period_data['timestamps']
|
||||
has_detail_data_flag = True
|
||||
ca_len = len(report['reporting_period']['names'])
|
||||
table_row = 38 + ca_len*6
|
||||
table_row = current_row_number + 1 + ca_len*6
|
||||
chart_start_row_number = current_row_number + 1
|
||||
if "timestamps" not in reporting_period_data.keys() or \
|
||||
reporting_period_data['timestamps'] is None or \
|
||||
len(reporting_period_data['timestamps']) == 0:
|
||||
has_detail_data_flag = False
|
||||
|
||||
if has_detail_data_flag:
|
||||
ws['B37'].font = title_font
|
||||
ws['B37'] = name+' 能耗详情'
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)] = name+' 详细数据'
|
||||
|
||||
ws.row_dimensions[table_row].height = 60
|
||||
ws['B'+str(table_row)].fill = table_fill
|
||||
ws['B' + str(table_row)].font = title_font
|
||||
ws['B'+str(table_row)].border = f_border
|
||||
ws['B'+str(table_row)].alignment = c_c_alignment
|
||||
ws['B'+str(table_row)] = '时间'
|
||||
ws['B'+str(table_row)] = '日期时间'
|
||||
time = times[0]
|
||||
has_data = False
|
||||
max_row = 0
|
||||
|
@ -526,31 +552,45 @@ def generate_excel(report,
|
|||
ws[col + row].alignment = c_c_alignment
|
||||
ws[col + row] = round(reporting_period_data['values'][i][j], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
current_row_number = table_row + 1 + len(times[0])
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
ws['B' + str(current_row_number)].alignment = c_c_alignment
|
||||
ws['B' + str(current_row_number)].border = f_border
|
||||
ws['B' + str(current_row_number)] = '小计'
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('C') + i)
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)] = reporting_period_data['subtotals'][i]
|
||||
|
||||
# line
|
||||
# 39~: line
|
||||
line = LineChart()
|
||||
line.title = '报告期消耗 - '
|
||||
labels = Reference(ws, min_col=2, min_row=table_row+1, max_row=max_row + 1)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_row, max_row=max_row + 1) # openpyxl bug
|
||||
line.title = '报告期消耗 - ' + ws.cell(column=3+i, row=table_row).value
|
||||
labels = Reference(ws, min_col=2, min_row=table_row+1, max_row=max_row)
|
||||
line_data = Reference(ws, min_col=3 + i, min_row=table_row, max_row=max_row) # openpyxl bug
|
||||
line.add_data(line_data, titles_from_data=True)
|
||||
line.set_categories(labels)
|
||||
line_data = line.series[0]
|
||||
line_data.marker.symbol = "circle"
|
||||
line_data.smooth = False
|
||||
line_data.smooth = True
|
||||
line.x_axis.crosses = 'min'
|
||||
line.height = 8.25 # cm 1.05*5 1.05cm = 30 pt
|
||||
line.width = 24
|
||||
# pie.title = "Pies sold by category"
|
||||
line.dLbls = DataLabelList()
|
||||
line.dLbls.dLblPos = 't'
|
||||
# line.dLbls.showCatName = True # label show
|
||||
line.dLbls.showVal = True # val show
|
||||
line.dLbls.showPercent = True # percent show
|
||||
# s1 = CharacterProperties(sz=1800) # font size *100
|
||||
chart_col = 'B'
|
||||
chart_cell = chart_col + str(38 + 6*i)
|
||||
chart_cell = chart_col + str(chart_start_row_number + 6*i)
|
||||
ws.add_chart(line, chart_cell)
|
||||
else:
|
||||
for i in range(37, 69 + 1):
|
||||
ws.row_dimensions[i].height = 0.1
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
wb.save(filename)
|
||||
|
|
|
@ -321,8 +321,13 @@ def generate_excel(report,
|
|||
#####################################
|
||||
|
||||
has_child_flag = True
|
||||
|
||||
if "child_space" not in report.keys() or "energy_item_names" not in report['child_space'].keys() or \
|
||||
len(report['child_space']["energy_item_names"]) == 0:
|
||||
len(report['child_space']["energy_item_names"]) == 0 \
|
||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
||||
or report['child_space']['child_space_names_array'] is None \
|
||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
||||
or len(report['child_space']['child_space_names_array'][0]) == 0:
|
||||
has_child_flag = False
|
||||
|
||||
if has_child_flag:
|
||||
|
@ -332,6 +337,7 @@ def generate_excel(report,
|
|||
ws['B' + str(current_row_number)] = name + ' 子空间数据'
|
||||
|
||||
current_row_number += 1
|
||||
table_start_row_number = current_row_number
|
||||
|
||||
ws.row_dimensions[current_row_number].height = 60
|
||||
ws['B' + str(current_row_number)].fill = table_fill
|
||||
|
@ -365,21 +371,22 @@ def generate_excel(report,
|
|||
ws[col + row] = round(child['subtotals_array'][j][i], 2)
|
||||
ws[col + row].border = f_border
|
||||
|
||||
table_end_row_number = current_row_number
|
||||
current_row_number += 1
|
||||
pie_start_row_number = current_row_number
|
||||
|
||||
# Pie
|
||||
for i in range(0, ca_len):
|
||||
pie = PieChart()
|
||||
labels = Reference(ws, min_col=2, min_row=current_row_number - space_len,
|
||||
max_row=current_row_number - 1)
|
||||
pie_data = Reference(ws, min_col=3 + i, min_row=current_row_number - space_len - 1,
|
||||
max_row=current_row_number - 1)
|
||||
labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1,
|
||||
max_row=table_end_row_number)
|
||||
pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number,
|
||||
max_row=table_end_row_number)
|
||||
pie.add_data(pie_data, titles_from_data=True)
|
||||
pie.set_categories(labels)
|
||||
pie.height = 6.6
|
||||
pie.width = 8
|
||||
col = chr(ord('C') + i)
|
||||
pie.title = ws[col + str(current_row_number - space_len - 1)].value
|
||||
pie.title = ws.cell(column=3 + i, row=table_start_row_number).value
|
||||
s1 = pie.series[0]
|
||||
s1.dLbls = DataLabelList()
|
||||
s1.dLbls.showCatName = False
|
||||
|
@ -387,12 +394,13 @@ def generate_excel(report,
|
|||
s1.dLbls.showPercent = True
|
||||
chart_cell = ''
|
||||
if i % 2 == 0:
|
||||
chart_cell = 'B' + str(current_row_number)
|
||||
chart_cell = 'B' + str(pie_start_row_number)
|
||||
else:
|
||||
chart_cell = 'E' + str(current_row_number)
|
||||
current_row_number += 5
|
||||
chart_cell = 'E' + str(pie_start_row_number)
|
||||
pie_start_row_number += 5
|
||||
ws.add_chart(pie, chart_cell)
|
||||
|
||||
current_row_number = pie_start_row_number
|
||||
if ca_len % 2 == 1:
|
||||
current_row_number += 5
|
||||
|
||||
|
@ -541,4 +549,3 @@ def group_by_category(category_list):
|
|||
category_dict[value] = list()
|
||||
category_dict[value].append(i)
|
||||
return category_dict
|
||||
|
||||
|
|
|
@ -432,11 +432,12 @@ def generate_excel(report,
|
|||
|
||||
has_child_space_data_flag = True
|
||||
|
||||
if 'child_space' not in report.keys() or \
|
||||
report['child_space'] is None or \
|
||||
'energy_category_names' not in report['child_space'].keys() or \
|
||||
report['child_space']['energy_category_names'] is None or \
|
||||
len(report['child_space']['energy_category_names']) == 0:
|
||||
if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \
|
||||
len(report['child_space']["energy_category_names"]) == 0 \
|
||||
or 'child_space_names_array' not in report['child_space'].keys() \
|
||||
or report['child_space']['energy_category_names'] is None \
|
||||
or len(report['child_space']['child_space_names_array']) == 0 \
|
||||
or len(report['child_space']['child_space_names_array'][0]) == 0:
|
||||
has_child_space_data_flag = False
|
||||
|
||||
if has_child_space_data_flag:
|
||||
|
|
Loading…
Reference in New Issue