@@ 54-121 (lines=68) @@ | ||
51 | return base64_message |
|
52 | ||
53 | ||
54 | def generate_excel(report, space_name, reporting_start_datetime_local, reporting_end_datetime_local, language): |
|
55 | ||
56 | trans = get_translation(language) |
|
57 | trans.install() |
|
58 | _ = trans.gettext |
|
59 | ||
60 | wb = Workbook() |
|
61 | ws = wb.active |
|
62 | ws.title = "OfflineMeterBatch" |
|
63 | ||
64 | # Col width |
|
65 | for i in range(ord('A'), ord('L')): |
|
66 | ws.column_dimensions[chr(i)].width = 20.0 |
|
67 | ||
68 | # Head image |
|
69 | ws.row_dimensions[1].height = 105 |
|
70 | img = Image("excelexporters/myems.png") |
|
71 | ws.add_image(img, 'A1') |
|
72 | ||
73 | # Query Parameters |
|
74 | b_r_alignment = Alignment(vertical='bottom', |
|
75 | horizontal='right', |
|
76 | text_rotation=0, |
|
77 | wrap_text=True, |
|
78 | shrink_to_fit=False, |
|
79 | indent=0) |
|
80 | ws['A3'].alignment = b_r_alignment |
|
81 | ws['A3'] = _('Space') + ':' |
|
82 | ws['B3'] = space_name |
|
83 | ws['A4'].alignment = b_r_alignment |
|
84 | ws['A4'] = _('Start Datetime') + ':' |
|
85 | ws['B4'] = reporting_start_datetime_local |
|
86 | ws['A5'].alignment = b_r_alignment |
|
87 | ws['A5'] = _('End Datetime') + ':' |
|
88 | ws['B5'] = reporting_end_datetime_local |
|
89 | ||
90 | # Title |
|
91 | title_font = Font(size=12, bold=True) |
|
92 | ws['A6'].font = title_font |
|
93 | ws['A6'] = _('ID') |
|
94 | ws['B6'].font = title_font |
|
95 | ws['B6'] = _('Name') |
|
96 | ws['C6'].font = title_font |
|
97 | ws['C6'] = _('Space') |
|
98 | ||
99 | ca_len = len(report['energycategories']) |
|
100 | for i in range(0, ca_len): |
|
101 | col = chr(ord('D') + i) |
|
102 | ws[col + '6'].font = title_font |
|
103 | ws[col + '6'] = report['energycategories'][i]['name'] + " (" + \ |
|
104 | report['energycategories'][i]['unit_of_measure'] + ")" |
|
105 | ||
106 | current_row_number = 7 |
|
107 | for i in range(0, len(report['offline_meters'])): |
|
108 | ws['A' + str(current_row_number)] = str(report['offline_meters'][i]['id']) |
|
109 | ws['B' + str(current_row_number)] = report['offline_meters'][i]['offline_meter_name'] |
|
110 | ws['C' + str(current_row_number)] = report['offline_meters'][i]['space_name'] |
|
111 | ca_len = len(report['offline_meters'][i]['values']) |
|
112 | for j in range(0, ca_len): |
|
113 | col = chr(ord('D') + j) |
|
114 | ws[col + str(current_row_number)] = report['offline_meters'][i]['values'][j] |
|
115 | ||
116 | current_row_number += 1 |
|
117 | ||
118 | filename = str(uuid.uuid4()) + '.xlsx' |
|
119 | wb.save(filename) |
|
120 | ||
121 | return filename |
|
122 |
@@ 54-121 (lines=68) @@ | ||
51 | return base64_message |
|
52 | ||
53 | ||
54 | def generate_excel(report, space_name, reporting_start_datetime_local, reporting_end_datetime_local, language): |
|
55 | ||
56 | trans = get_translation(language) |
|
57 | trans.install() |
|
58 | _ = trans.gettext |
|
59 | ||
60 | wb = Workbook() |
|
61 | ws = wb.active |
|
62 | ws.title = "MeterBatch" |
|
63 | ||
64 | # Col width |
|
65 | for i in range(ord('A'), ord('L')): |
|
66 | ws.column_dimensions[chr(i)].width = 20.0 |
|
67 | ||
68 | # Head image |
|
69 | ws.row_dimensions[1].height = 105 |
|
70 | img = Image("excelexporters/myems.png") |
|
71 | ws.add_image(img, 'A1') |
|
72 | ||
73 | # Query Parameters |
|
74 | b_r_alignment = Alignment(vertical='bottom', |
|
75 | horizontal='right', |
|
76 | text_rotation=0, |
|
77 | wrap_text=True, |
|
78 | shrink_to_fit=False, |
|
79 | indent=0) |
|
80 | ws['A3'].alignment = b_r_alignment |
|
81 | ws['A3'] = _('Space') + ':' |
|
82 | ws['B3'] = space_name |
|
83 | ws['A4'].alignment = b_r_alignment |
|
84 | ws['A4'] = _('Start Datetime') + ':' |
|
85 | ws['B4'] = reporting_start_datetime_local |
|
86 | ws['A5'].alignment = b_r_alignment |
|
87 | ws['A5'] = _('End Datetime') + ':' |
|
88 | ws['B5'] = reporting_end_datetime_local |
|
89 | ||
90 | # Title |
|
91 | title_font = Font(size=12, bold=True) |
|
92 | ws['A6'].font = title_font |
|
93 | ws['A6'] = _('ID') |
|
94 | ws['B6'].font = title_font |
|
95 | ws['B6'] = _('Name') |
|
96 | ws['C6'].font = title_font |
|
97 | ws['C6'] = _('Space') |
|
98 | ||
99 | ca_len = len(report['energycategories']) |
|
100 | for i in range(0, ca_len): |
|
101 | col = chr(ord('D') + i) |
|
102 | ws[col + '6'].font = title_font |
|
103 | ws[col + '6'] = report['energycategories'][i]['name'] + " (" + \ |
|
104 | report['energycategories'][i]['unit_of_measure'] + ")" |
|
105 | ||
106 | current_row_number = 7 |
|
107 | for i in range(0, len(report['meters'])): |
|
108 | ws['A' + str(current_row_number)] = str(report['meters'][i]['id']) |
|
109 | ws['B' + str(current_row_number)] = report['meters'][i]['meter_name'] |
|
110 | ws['C' + str(current_row_number)] = report['meters'][i]['space_name'] |
|
111 | ca_len = len(report['meters'][i]['values']) |
|
112 | for j in range(0, ca_len): |
|
113 | col = chr(ord('D') + j) |
|
114 | ws[col + str(current_row_number)] = report['meters'][i]['values'][j] |
|
115 | ||
116 | current_row_number += 1 |
|
117 | ||
118 | filename = str(uuid.uuid4()) + '.xlsx' |
|
119 | wb.save(filename) |
|
120 | ||
121 | return filename |
|
122 |
@@ 54-121 (lines=68) @@ | ||
51 | return base64_message |
|
52 | ||
53 | ||
54 | def generate_excel(report, space_name, reporting_start_datetime_local, reporting_end_datetime_local, language): |
|
55 | ||
56 | trans = get_translation(language) |
|
57 | trans.install() |
|
58 | _ = trans.gettext |
|
59 | ||
60 | wb = Workbook() |
|
61 | ws = wb.active |
|
62 | ws.title = "VirtualMeterBatch" |
|
63 | ||
64 | # Col width |
|
65 | for i in range(ord('A'), ord('L')): |
|
66 | ws.column_dimensions[chr(i)].width = 20.0 |
|
67 | ||
68 | # Head image |
|
69 | ws.row_dimensions[1].height = 105 |
|
70 | img = Image("excelexporters/myems.png") |
|
71 | ws.add_image(img, 'A1') |
|
72 | ||
73 | # Query Parameters |
|
74 | b_r_alignment = Alignment(vertical='bottom', |
|
75 | horizontal='right', |
|
76 | text_rotation=0, |
|
77 | wrap_text=True, |
|
78 | shrink_to_fit=False, |
|
79 | indent=0) |
|
80 | ws['A3'].alignment = b_r_alignment |
|
81 | ws['A3'] = _('Space') + ':' |
|
82 | ws['B3'] = space_name |
|
83 | ws['A4'].alignment = b_r_alignment |
|
84 | ws['A4'] = _('Start Datetime') + ':' |
|
85 | ws['B4'] = reporting_start_datetime_local |
|
86 | ws['A5'].alignment = b_r_alignment |
|
87 | ws['A5'] = _('End Datetime') + ':' |
|
88 | ws['B5'] = reporting_end_datetime_local |
|
89 | ||
90 | # Title |
|
91 | title_font = Font(size=12, bold=True) |
|
92 | ws['A6'].font = title_font |
|
93 | ws['A6'] = _('ID') |
|
94 | ws['B6'].font = title_font |
|
95 | ws['B6'] = _('Name') |
|
96 | ws['C6'].font = title_font |
|
97 | ws['C6'] = _('Space') |
|
98 | ||
99 | ca_len = len(report['energycategories']) |
|
100 | for i in range(0, ca_len): |
|
101 | col = chr(ord('D') + i) |
|
102 | ws[col + '6'].font = title_font |
|
103 | ws[col + '6'] = report['energycategories'][i]['name'] + " (" + \ |
|
104 | report['energycategories'][i]['unit_of_measure'] + ")" |
|
105 | ||
106 | current_row_number = 7 |
|
107 | for i in range(0, len(report['virtual_meters'])): |
|
108 | ws['A' + str(current_row_number)] = str(report['virtual_meters'][i]['id']) |
|
109 | ws['B' + str(current_row_number)] = report['virtual_meters'][i]['virtual_meter_name'] |
|
110 | ws['C' + str(current_row_number)] = report['virtual_meters'][i]['space_name'] |
|
111 | ca_len = len(report['virtual_meters'][i]['values']) |
|
112 | for j in range(0, ca_len): |
|
113 | col = chr(ord('D') + j) |
|
114 | ws[col + str(current_row_number)] = report['virtual_meters'][i]['values'][j] |
|
115 | ||
116 | current_row_number += 1 |
|
117 | ||
118 | filename = str(uuid.uuid4()) + '.xlsx' |
|
119 | wb.save(filename) |
|
120 | ||
121 | return filename |
|
122 |