From 32e8d3b51a6f921fe1782921630af42b054d7fbb Mon Sep 17 00:00:00 2001 From: areza-blocpower Date: Tue, 18 Apr 2017 16:55:58 -0400 Subject: [PATCH 1/8] add script to generate reports for all excel in working directory --- bpeng/reports/run_repgen.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bpeng/reports/run_repgen.py diff --git a/bpeng/reports/run_repgen.py b/bpeng/reports/run_repgen.py new file mode 100644 index 0000000..1de1548 --- /dev/null +++ b/bpeng/reports/run_repgen.py @@ -0,0 +1,22 @@ +import os +import sys +import pandas as pd +from bpeng.reports.cbra_diag import CbraDiagnostic + +CBRA_PPTX = 'C:\\Users\\Areza\\Documents\\test_repgen\\EEDR_CBRA_Template_Final.pptx' +file_list = [] + +for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: + + file_list.append(file) + +print(file_list) + +for i in range(len(file_list)): + template_file = CBRA_PPTX + file_name = file_list[i] + file_input = pd.ExcelFile(file_name) + sheet_input = file_input.parse("Inputs", header=None) + proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) + prs.save('EEDR {}.pptx'.format(proj_loc)) + -- GitLab From be21d303d510856a418c29b1aef852dcbc32a1bc Mon Sep 17 00:00:00 2001 From: areza-blocpower Date: Tue, 18 Apr 2017 17:05:38 -0400 Subject: [PATCH 2/8] add script to generate reports for all excel in working directory --- bpeng/reports/run_cbra_repgen.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bpeng/reports/run_cbra_repgen.py diff --git a/bpeng/reports/run_cbra_repgen.py b/bpeng/reports/run_cbra_repgen.py new file mode 100644 index 0000000..0f52b79 --- /dev/null +++ b/bpeng/reports/run_cbra_repgen.py @@ -0,0 +1,23 @@ +''' Module is designed to use the CBRA Diagnostic Report Generator function to + create reports for all excel files in the current working directory ''' + +import os +import pandas as pd +from bpeng.reports.cbra_diag import CbraDiagnostic + +CBRA_PPTX = 'C:\\Users\\Areza\\Documents\\test_repgen\\EEDR_CBRA_Template_Final.pptx' +file_list = [] + +for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: + + file_list.append(file) + +print(file_list) + +for i in range(len(file_list)): + template_file = CBRA_PPTX + file_name = file_list[i] + file_input = pd.ExcelFile(file_name) + sheet_input = file_input.parse("Inputs", header=None) + proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) + prs.save('EEDR {}.pptx'.format(proj_loc)) -- GitLab From 6fa067f393c383de8bd559666fabe817d27b861a Mon Sep 17 00:00:00 2001 From: areza-blocpower Date: Tue, 18 Apr 2017 17:09:24 -0400 Subject: [PATCH 3/8] add doc string and remove unecessary sys import and print statement --- bpeng/reports/run_cbra_repgen.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bpeng/reports/run_cbra_repgen.py b/bpeng/reports/run_cbra_repgen.py index 0f52b79..f65c367 100644 --- a/bpeng/reports/run_cbra_repgen.py +++ b/bpeng/reports/run_cbra_repgen.py @@ -6,17 +6,16 @@ import pandas as pd from bpeng.reports.cbra_diag import CbraDiagnostic CBRA_PPTX = 'C:\\Users\\Areza\\Documents\\test_repgen\\EEDR_CBRA_Template_Final.pptx' -file_list = [] -for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: +REPGEN_LIST = [] - file_list.append(file) +for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: -print(file_list) + REPGEN_LIST.append(file) -for i in range(len(file_list)): +for i in range(len(REPGEN_LIST)): template_file = CBRA_PPTX - file_name = file_list[i] + file_name = REPGEN_LIST[i] file_input = pd.ExcelFile(file_name) sheet_input = file_input.parse("Inputs", header=None) proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) -- GitLab From 49c3886d3fb396fc50def12652f3a381180c2121 Mon Sep 17 00:00:00 2001 From: areza-blocpower Date: Tue, 18 Apr 2017 17:15:22 -0400 Subject: [PATCH 4/8] remove old misnamed cbra multi-report script --- bpeng/reports/run_repgen.py | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 bpeng/reports/run_repgen.py diff --git a/bpeng/reports/run_repgen.py b/bpeng/reports/run_repgen.py deleted file mode 100644 index 1de1548..0000000 --- a/bpeng/reports/run_repgen.py +++ /dev/null @@ -1,22 +0,0 @@ -import os -import sys -import pandas as pd -from bpeng.reports.cbra_diag import CbraDiagnostic - -CBRA_PPTX = 'C:\\Users\\Areza\\Documents\\test_repgen\\EEDR_CBRA_Template_Final.pptx' -file_list = [] - -for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: - - file_list.append(file) - -print(file_list) - -for i in range(len(file_list)): - template_file = CBRA_PPTX - file_name = file_list[i] - file_input = pd.ExcelFile(file_name) - sheet_input = file_input.parse("Inputs", header=None) - proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) - prs.save('EEDR {}.pptx'.format(proj_loc)) - -- GitLab From f90ebe52defa305187cb308e68fe64e957d80256 Mon Sep 17 00:00:00 2001 From: areza-blocpower Date: Wed, 19 Apr 2017 13:51:10 -0400 Subject: [PATCH 5/8] Add function to generate reports for every excel file in current working directory --- bpeng/reports/cbra_diag.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/bpeng/reports/cbra_diag.py b/bpeng/reports/cbra_diag.py index c0c9299..21ee046 100644 --- a/bpeng/reports/cbra_diag.py +++ b/bpeng/reports/cbra_diag.py @@ -5,6 +5,7 @@ from datetime import datetime +import os import pandas as pd from pptx import Presentation from pptx.chart.data import ChartData @@ -183,7 +184,6 @@ class CbraDiagnostic: util_break_plug = sheet_input.loc[16:17, 4] util_break_h2o = sheet_input.loc[16:17, 5] - util_break_data = ChartData() util_break_data.categories = util_cat util_break_data.add_series("Space Heating", util_break_sh) @@ -196,9 +196,9 @@ class CbraDiagnostic: chart_horz_pos, chart_vert_pos = Inches(0.05), Inches(2.4) chart_width, chart_height = Inches(3.5), Inches(2.5) util_break_chart = utility_projection_slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_STACKED, - chart_horz_pos, chart_vert_pos, - chart_width, chart_height, - util_break_data).chart + chart_horz_pos, chart_vert_pos, + chart_width, chart_height, + util_break_data).chart # Formatting for chart # Legend @@ -226,8 +226,8 @@ class CbraDiagnostic: # Create ECM summary table ecm_count = input_values.str.contains('Y').sum() ecm_table = utility_projection_slide.shapes.add_table(ecm_count+2, 3, Inches(3.81), - Inches(0.25), Inches(5.83), - Inches(3.76)) + Inches(0.25), Inches(5.83), + Inches(3.76)) ecm_table.last_row = True ecm_table.horz_banding = False ecm_table_head = ['ECM', "Heating Savings *", "Electricity Savings *"] @@ -262,7 +262,6 @@ class CbraDiagnostic: prs.slides.delete_slide(prs, slide_idx) counter = counter + 1 - return project_address, prs @staticmethod @@ -276,3 +275,25 @@ class CbraDiagnostic: sheet_input = file_input.parse("Inputs", header=None) project_address, prs = CbraDiagnostic._generate_report(template_file, sheet_input) prs.save('EEDR {}.pptx'.format(project_address)) + + @staticmethod + def cbra_multi_rep(): + """ + + Generate report for every excel file in the current working directory + """ + cbra_pptx = 'C:\\Users\\Areza\\Documents\\test_repgen\\EEDR_CBRA_Template_Final.pptx' + + repgen_list = [] + + for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: + + repgen_list.append(file) + + for i in range(len(repgen_list)): + template_file = cbra_pptx + file_name = repgen_list[i] + file_input = pd.ExcelFile(file_name) + sheet_input = file_input.parse("Inputs", header=None) + proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) + prs.save('EEDR {}.pptx'.format(proj_loc)) -- GitLab From 534dcfd0bfbb6900501ec752be99ef9f5110c021 Mon Sep 17 00:00:00 2001 From: areza-blocpower Date: Thu, 20 Apr 2017 11:24:52 -0400 Subject: [PATCH 6/8] Remove standalone script. Make multi-rep function check if template is present. --- bpeng/reports/cbra_diag.py | 39 ++++++++++++++++++-------------- bpeng/reports/run_cbra_repgen.py | 22 ------------------ 2 files changed, 22 insertions(+), 39 deletions(-) delete mode 100644 bpeng/reports/run_cbra_repgen.py diff --git a/bpeng/reports/cbra_diag.py b/bpeng/reports/cbra_diag.py index 21ee046..92e0888 100644 --- a/bpeng/reports/cbra_diag.py +++ b/bpeng/reports/cbra_diag.py @@ -10,7 +10,7 @@ import pandas as pd from pptx import Presentation from pptx.chart.data import ChartData from pptx.dml.color import RGBColor -from pptx.enum.chart import (XL_CHART_TYPE, XL_LABEL_POSITION, +from pptx.enum.chart import (XL_CHART_TYPE, XL_LEGEND_POSITION, XL_TICK_LABEL_POSITION) from pptx.enum.text import MSO_AUTO_SIZE, PP_ALIGN from pptx.util import Inches, Pt @@ -280,20 +280,25 @@ class CbraDiagnostic: def cbra_multi_rep(): """ - Generate report for every excel file in the current working directory + Generate report for every excel file in a given directory """ - cbra_pptx = 'C:\\Users\\Areza\\Documents\\test_repgen\\EEDR_CBRA_Template_Final.pptx' - - repgen_list = [] - - for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: - - repgen_list.append(file) - - for i in range(len(repgen_list)): - template_file = cbra_pptx - file_name = repgen_list[i] - file_input = pd.ExcelFile(file_name) - sheet_input = file_input.parse("Inputs", header=None) - proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) - prs.save('EEDR {}.pptx'.format(proj_loc)) + target_dir = input('Enter directory where pptx template is located: ') + cbra_pptx = ''.join([target_dir, '/EEDR_CBRA_Template_Final.pptx']) + + if os.path.exists(cbra_pptx): + repgen_list = [] + + for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: + + repgen_list.append(file) + + for i in range(len(repgen_list)): + template_file = cbra_pptx + file_name = repgen_list[i] + file_input = pd.ExcelFile(file_name) + sheet_input = file_input.parse("Inputs", header=None) + proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) + prs.save('EEDR {}.pptx'.format(proj_loc)) + print('Reports generated!') + else: + raise Exception('Template not found. Please download pptx template to directory') diff --git a/bpeng/reports/run_cbra_repgen.py b/bpeng/reports/run_cbra_repgen.py deleted file mode 100644 index f65c367..0000000 --- a/bpeng/reports/run_cbra_repgen.py +++ /dev/null @@ -1,22 +0,0 @@ -''' Module is designed to use the CBRA Diagnostic Report Generator function to - create reports for all excel files in the current working directory ''' - -import os -import pandas as pd -from bpeng.reports.cbra_diag import CbraDiagnostic - -CBRA_PPTX = 'C:\\Users\\Areza\\Documents\\test_repgen\\EEDR_CBRA_Template_Final.pptx' - -REPGEN_LIST = [] - -for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: - - REPGEN_LIST.append(file) - -for i in range(len(REPGEN_LIST)): - template_file = CBRA_PPTX - file_name = REPGEN_LIST[i] - file_input = pd.ExcelFile(file_name) - sheet_input = file_input.parse("Inputs", header=None) - proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) - prs.save('EEDR {}.pptx'.format(proj_loc)) -- GitLab From 72fbe1881f993d8af27633a9ee5f8986b8bcdb49 Mon Sep 17 00:00:00 2001 From: areza-blocpower Date: Fri, 21 Apr 2017 10:58:33 -0400 Subject: [PATCH 7/8] Use os.path.join instead of combining strings for pptx directory --- bpeng/reports/cbra_diag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bpeng/reports/cbra_diag.py b/bpeng/reports/cbra_diag.py index 92e0888..56f1047 100644 --- a/bpeng/reports/cbra_diag.py +++ b/bpeng/reports/cbra_diag.py @@ -283,7 +283,7 @@ class CbraDiagnostic: Generate report for every excel file in a given directory """ target_dir = input('Enter directory where pptx template is located: ') - cbra_pptx = ''.join([target_dir, '/EEDR_CBRA_Template_Final.pptx']) + cbra_pptx = os.path.join(target_dir, "EEDR_CBRA_Template_Final.pptx") if os.path.exists(cbra_pptx): repgen_list = [] -- GitLab From 0a9ab20eb765effe82d5ccf002b1ae551055ff18 Mon Sep 17 00:00:00 2001 From: areza-blocpower Date: Fri, 21 Apr 2017 14:00:46 -0400 Subject: [PATCH 8/8] Change multi-line entry formatting. Change prs var to diag_rep. Change file var to xlsx_item --- bpeng/reports/cbra_diag.py | 58 +++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/bpeng/reports/cbra_diag.py b/bpeng/reports/cbra_diag.py index 56f1047..6d4c341 100644 --- a/bpeng/reports/cbra_diag.py +++ b/bpeng/reports/cbra_diag.py @@ -10,8 +10,11 @@ import pandas as pd from pptx import Presentation from pptx.chart.data import ChartData from pptx.dml.color import RGBColor -from pptx.enum.chart import (XL_CHART_TYPE, - XL_LEGEND_POSITION, XL_TICK_LABEL_POSITION) +from pptx.enum.chart import ( + XL_CHART_TYPE, + XL_LEGEND_POSITION, + XL_TICK_LABEL_POSITION +) from pptx.enum.text import MSO_AUTO_SIZE, PP_ALIGN from pptx.util import Inches, Pt @@ -40,11 +43,11 @@ class CbraDiagnostic: input_values = sheet_input[1] # Define presentation to edit as the finished template - prs = Presentation(template_file) + diag_rep = Presentation(template_file) # Slide 1: cover slide - # cover_slide_layout = prs.slide_layouts[0] - cover_slide = prs.slides[0] + # cover_slide_layout = diag_rep.slide_layouts[0] + cover_slide = diag_rep.slides[0] cover_title = cover_slide.shapes.title cover_subtitle = cover_slide.placeholders[1] @@ -58,7 +61,7 @@ class CbraDiagnostic: # Slide 2: Executive Summary + Table of Contents # shapes[0] = slide #, 1 = executive summary text box, 2 = title , 3 = table of contents - exec_summary_slide = prs.slides[1] + exec_summary_slide = diag_rep.slides[1] exec_results_box = exec_summary_slide.shapes[1] exec_results_box.text_frame.auto_size = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT exec_results_box.text_frame.alignment = PP_ALIGN.LEFT @@ -132,7 +135,7 @@ class CbraDiagnostic: # Slide 3: Energy Analysis, includes heatload pie chart + image from # BlocMaps (might be static) + efficiency % from BlocMaps - heat_load_slide = prs.slides[2] + heat_load_slide = diag_rep.slides[2] energy_analyze_box = heat_load_slide.shapes[3] # BlocMaps Efficiency Comparison @@ -174,7 +177,7 @@ class CbraDiagnostic: # pre+post-retrofit, ECM table w/ names, savings for elec and gas, and total savings # Slide 4: Utility breakdown (chart is in bottom right corner) - utility_projection_slide = prs.slides[3] + utility_projection_slide = diag_rep.slides[3] # Define stacked bar chart data util_cat = ["Existing", "Projected"] @@ -195,10 +198,14 @@ class CbraDiagnostic: # Set chart location and formatting chart_horz_pos, chart_vert_pos = Inches(0.05), Inches(2.4) chart_width, chart_height = Inches(3.5), Inches(2.5) - util_break_chart = utility_projection_slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_STACKED, - chart_horz_pos, chart_vert_pos, - chart_width, chart_height, - util_break_data).chart + util_break_chart = utility_projection_slide.shapes.add_chart( + XL_CHART_TYPE.COLUMN_STACKED, + chart_horz_pos, + chart_vert_pos, + chart_width, + chart_height, + util_break_data + ).chart # Formatting for chart # Legend @@ -225,9 +232,14 @@ class CbraDiagnostic: # Create ECM summary table ecm_count = input_values.str.contains('Y').sum() - ecm_table = utility_projection_slide.shapes.add_table(ecm_count+2, 3, Inches(3.81), - Inches(0.25), Inches(5.83), - Inches(3.76)) + ecm_table = utility_projection_slide.shapes.add_table( + ecm_count + 2, + 3, + Inches(3.81), + Inches(0.25), + Inches(5.83), + Inches(3.76) + ) ecm_table.last_row = True ecm_table.horz_banding = False ecm_table_head = ['ECM', "Heating Savings *", "Electricity Savings *"] @@ -259,10 +271,10 @@ class CbraDiagnostic: for j in range(len(input_values)): if input_values[j] == 'N': slide_idx = int(((j-6)/3) - counter) - prs.slides.delete_slide(prs, slide_idx) + diag_rep.slides.delete_slide(diag_rep, slide_idx) counter = counter + 1 - return project_address, prs + return project_address, diag_rep @staticmethod def generate_report(): @@ -273,8 +285,8 @@ class CbraDiagnostic: file_name = input('Enter File Name (with .xlsx extension): ') file_input = pd.ExcelFile(file_name) sheet_input = file_input.parse("Inputs", header=None) - project_address, prs = CbraDiagnostic._generate_report(template_file, sheet_input) - prs.save('EEDR {}.pptx'.format(project_address)) + project_address, diag_rep = CbraDiagnostic._generate_report(template_file, sheet_input) + diag_rep.save('EEDR {}.pptx'.format(project_address)) @staticmethod def cbra_multi_rep(): @@ -288,17 +300,17 @@ class CbraDiagnostic: if os.path.exists(cbra_pptx): repgen_list = [] - for file in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: + for xlsx_item in [xl for xl in os.listdir(os.getcwd()) if xl.endswith(".xlsx")]: - repgen_list.append(file) + repgen_list.append(xlsx_item) for i in range(len(repgen_list)): template_file = cbra_pptx file_name = repgen_list[i] file_input = pd.ExcelFile(file_name) sheet_input = file_input.parse("Inputs", header=None) - proj_loc, prs = CbraDiagnostic._generate_report(template_file, sheet_input) - prs.save('EEDR {}.pptx'.format(proj_loc)) + proj_loc, diag_rep = CbraDiagnostic._generate_report(template_file, sheet_input) + diag_rep.save('EEDR {}.pptx'.format(proj_loc)) print('Reports generated!') else: raise Exception('Template not found. Please download pptx template to directory') -- GitLab