2021/3/3
parent
d719e95ab0
commit
25a96729ae
|
@ -30,7 +30,6 @@ def export(report,
|
|||
if report is None:
|
||||
return None
|
||||
|
||||
|
||||
####################################################################################################################
|
||||
# Step 2: Generate excel file from the report data
|
||||
####################################################################################################################
|
||||
|
@ -211,7 +210,7 @@ def generate_excel(report,
|
|||
# table_data
|
||||
|
||||
for i, value in enumerate(category):
|
||||
row = i*2 + 8
|
||||
row = i * 2 + 8
|
||||
ws['B' + str(row)].font = name_font
|
||||
ws['B' + str(row)].alignment = c_c_alignment
|
||||
ws['B' + str(row)] = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + "/H )"
|
||||
|
@ -358,14 +357,14 @@ def generate_excel(report,
|
|||
# row_st == row_statistical analysis table
|
||||
row_sat = 12 + 3 * ca_len
|
||||
|
||||
ws['B' + str(row_sat+row_title)].font = title_font
|
||||
ws['B' + str(row_sat+row_title)] = name + ' 详细数据'
|
||||
ws['B' + str(row_sat + row_title)].font = title_font
|
||||
ws['B' + str(row_sat + row_title)] = name + ' 详细数据'
|
||||
# table_title
|
||||
ws['B' + str(row_sat+1+row_title)].fill = table_fill
|
||||
ws['B' + str(row_sat+1+row_title)].font = name_font
|
||||
ws['B' + str(row_sat+1+row_title)].alignment = c_c_alignment
|
||||
ws['B' + str(row_sat+1+row_title)] = "日期时间"
|
||||
ws['B' + str(row_sat+1+row_title)].border = f_border
|
||||
ws['B' + str(row_sat + 1 + row_title)].fill = table_fill
|
||||
ws['B' + str(row_sat + 1 + row_title)].font = name_font
|
||||
ws['B' + str(row_sat + 1 + row_title)].alignment = c_c_alignment
|
||||
ws['B' + str(row_sat + 1 + row_title)] = "日期时间"
|
||||
ws['B' + str(row_sat + 1 + row_title)].border = f_border
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col_average = chr(ord('C') + i)
|
||||
|
@ -392,27 +391,25 @@ def generate_excel(report,
|
|||
ws['B' + str(rows)].border = f_border
|
||||
|
||||
for index in range(0, ca_len):
|
||||
|
||||
col_average = chr(ord('C') + index * 2)
|
||||
col_maximum = chr(ord('C') + index * 2 + 1)
|
||||
|
||||
ws[col_average + str(rows)].font = name_font
|
||||
ws[col_average + str(rows)].alignment = c_c_alignment
|
||||
ws[col_average + str(rows)] = reporting_period_data['sub_averages'][index][i] \
|
||||
if reporting_period_data['sub_maximums'][index] is not None else ''
|
||||
if reporting_period_data['sub_maximums'][index] is not None else ''
|
||||
ws[col_average + str(rows)].number_format = '0.00'
|
||||
ws[col_average + str(rows)].border = f_border
|
||||
|
||||
ws[col_maximum + str(rows)].font = name_font
|
||||
ws[col_maximum + str(rows)].alignment = c_c_alignment
|
||||
ws[col_maximum + str(rows)] = reporting_period_data['sub_maximums'][index][i] \
|
||||
if reporting_period_data['sub_maximums'][index] is not None else ''
|
||||
if reporting_period_data['sub_maximums'][index] is not None else ''
|
||||
ws[col_maximum + str(rows)].number_format = '0.00'
|
||||
ws[col_maximum + str(rows)].border = f_border
|
||||
|
||||
# LineChart
|
||||
for i in range(0, ca_len):
|
||||
|
||||
lc = LineChart()
|
||||
lc.title = "报告期 最大负荷"
|
||||
lc.style = 10
|
||||
|
|
|
@ -7,6 +7,7 @@ from core import utilities
|
|||
from decimal import Decimal
|
||||
import excelexporters.shopfloorload
|
||||
|
||||
|
||||
class Reporting:
|
||||
@staticmethod
|
||||
def __init__():
|
||||
|
@ -66,7 +67,7 @@ class Reporting:
|
|||
try:
|
||||
base_start_datetime_utc = datetime.strptime(base_start_datetime_local,
|
||||
'%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \
|
||||
timedelta(minutes=timezone_offset)
|
||||
timedelta(minutes=timezone_offset)
|
||||
except ValueError:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description="API.INVALID_BASE_PERIOD_START_DATETIME")
|
||||
|
@ -77,7 +78,7 @@ class Reporting:
|
|||
try:
|
||||
base_end_datetime_utc = datetime.strptime(base_end_datetime_local,
|
||||
'%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \
|
||||
timedelta(minutes=timezone_offset)
|
||||
timedelta(minutes=timezone_offset)
|
||||
except ValueError:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description="API.INVALID_BASE_PERIOD_END_DATETIME")
|
||||
|
@ -95,7 +96,7 @@ class Reporting:
|
|||
try:
|
||||
reporting_start_datetime_utc = datetime.strptime(reporting_start_datetime_local,
|
||||
'%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \
|
||||
timedelta(minutes=timezone_offset)
|
||||
timedelta(minutes=timezone_offset)
|
||||
except ValueError:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description="API.INVALID_REPORTING_PERIOD_START_DATETIME")
|
||||
|
@ -108,7 +109,7 @@ class Reporting:
|
|||
try:
|
||||
reporting_end_datetime_utc = datetime.strptime(reporting_end_datetime_local,
|
||||
'%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) - \
|
||||
timedelta(minutes=timezone_offset)
|
||||
timedelta(minutes=timezone_offset)
|
||||
except ValueError:
|
||||
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
|
||||
description="API.INVALID_REPORTING_PERIOD_END_DATETIME")
|
||||
|
@ -278,10 +279,10 @@ class Reporting:
|
|||
period_type)
|
||||
base[energy_category_id]['factor'] = \
|
||||
(base[energy_category_id]['average'] / base[energy_category_id]['maximum']
|
||||
if (base[energy_category_id]['average'] is not None and
|
||||
base[energy_category_id]['maximum'] is not None and
|
||||
base[energy_category_id]['maximum'] > Decimal(0.0))
|
||||
else None)
|
||||
if (base[energy_category_id]['average'] is not None and
|
||||
base[energy_category_id]['maximum'] is not None and
|
||||
base[energy_category_id]['maximum'] > Decimal(0.0))
|
||||
else None)
|
||||
|
||||
for row_shopfloor_periodically in rows_shopfloor_periodically:
|
||||
current_datetime_local = row_shopfloor_periodically[0].replace(tzinfo=timezone.utc) + \
|
||||
|
@ -511,11 +512,11 @@ class Reporting:
|
|||
result['reporting_period']['sub_maximums'].append(reporting[energy_category_id]['sub_maximums'])
|
||||
result['reporting_period']['averages'].append(reporting[energy_category_id]['average'])
|
||||
result['reporting_period']['averages_per_unit_area'].append(
|
||||
reporting[energy_category_id]['average'] / shopfloor['area']
|
||||
if reporting[energy_category_id]['average'] is not None and
|
||||
shopfloor['area'] is not None and
|
||||
shopfloor['area'] > Decimal(0.0)
|
||||
else None)
|
||||
reporting[energy_category_id]['average'] / shopfloor['area']
|
||||
if reporting[energy_category_id]['average'] is not None and
|
||||
shopfloor['area'] is not None and
|
||||
shopfloor['area'] > Decimal(0.0)
|
||||
else None)
|
||||
result['reporting_period']['averages_increment_rate'].append(
|
||||
(reporting[energy_category_id]['average'] - base[energy_category_id]['average']) /
|
||||
base[energy_category_id]['average'] if (base[energy_category_id]['average'] is not None and
|
||||
|
@ -548,8 +549,8 @@ class Reporting:
|
|||
|
||||
# export result to Excel file and then encode the file to base64 string
|
||||
result['excel_bytes_base64'] = excelexporters.shopfloorload.export(result,
|
||||
shopfloor['name'],
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
shopfloor['name'],
|
||||
reporting_start_datetime_local,
|
||||
reporting_end_datetime_local,
|
||||
period_type)
|
||||
resp.body = json.dumps(result)
|
||||
|
|
Loading…
Reference in New Issue