def build(summary, year): #get spreadsheets #attempt to handle file name changes (go glob!) bookname = glob('Energy*')[0] elecBook = xlrd.open_workbook(bookname) elecSheet = elecBook.sheet_by_name('BldgEnergyCost') #attempt to handle file name changes bookname = glob('Gas*')[0] steamBook = xlrd.open_workbook(bookname) steamSheet = steamBook.sheet_by_name('SteamEnergyPerBldg') for code in BuildingNames: #get use rows of building in both spread sheets steam_use_row = findBuildingUseRow(steamSheet, BuildingNames[code]) elec_use_row = findBuildingUseRow(elecSheet, BuildingNames[code]) #get cost rows of building in both spread sheets steam_cost_row = findBuildingCostRow(steamSheet, BuildingNames[code]) elec_cost_row = findBuildingCostRow(elecSheet, BuildingNames[code]) for i in range(1, 13): #gets month col for electric mColumnElec = findMonthColumn(elecSheet, i, elecBook.datemode, year) #gets month col for steam mColumnSteam = findMonthColumn(steamSheet, i, steamBook.datemode, year) if code.startswith('r'): summary.ResElectricUse += getMeasurement(elecSheet, mColumnElec, elec_use_row) summary.ResSteamUse += getMeasurement(steamSheet, mColumnSteam, steam_use_row) summary.ResElectricCost += getMeasurement(elecSheet, mColumnElec, elec_cost_row) summary.ResSteamCost += getMeasurement(steamSheet, mColumnSteam, steam_cost_row) elif code.startswith('s'): summary.StuElectricUse += getMeasurement(elecSheet, mColumnElec, elec_use_row) summary.StuSteamUse += getMeasurement(steamSheet, mColumnSteam, steam_use_row) summary.StuElectricCost += getMeasurement(elecSheet, mColumnElec, elec_cost_row) summary.StuSteamCost += getMeasurement(steamSheet, mColumnSteam, steam_cost_row) elif code.startswith('a'): summary.AcaElectricUse += getMeasurement(elecSheet, mColumnElec, elec_use_row) summary.AcaSteamUse += getMeasurement(steamSheet, mColumnSteam, steam_use_row) summary.AcaElectricCost += getMeasurement(elecSheet, mColumnElec, elec_cost_row) summary.AcaSteamCost += getMeasurement(steamSheet, mColumnSteam, steam_cost_row) #convert kwh to btu: 1 kwh = 3,413 btu # 1 kwh = 0.003413 million btus summary.ResElectricUse = summary.ResElectricUse * 0.003413 summary.StuElectricUse = summary.StuElectricUse * 0.003413 summary.AcaElectricUse = summary.AcaElectricUse * 0.003413
def build(building, code, util, year): months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] #get book and worksheet for util if (util == 'electric'): #attempt to handle file name changes (go glob!) bookname = glob('Energy*')[0] book = xlrd.open_workbook(bookname) sheet = book.sheet_by_name('BldgEnergyCost') building.unit = 'kWh' if (util == 'steam'): #attempt to handle file name changes bookname = glob('Gas*')[0] book = xlrd.open_workbook(bookname) sheet = book.sheet_by_name('SteamEnergyPerBldg') building.unit = 'Mbtu' preyear = year - 1 curyear = year building.currYear = curyear building.prevYear = preyear building_row = None #TODO add function find building column? #gets building row building.name = BuildingNames[code] building_row = findBuildingUseRow(sheet, building.name) for i in range(0, 12): #gets month col for preyear mColumn = findMonthColumn(sheet, months[i], book.datemode, preyear) #set month data in utilpre of data to measurement building.months[i]['pre'] = getMeasurement(sheet, mColumn, building_row) #gets month col for curyear mColumn = findMonthColumn(sheet, months[i], book.datemode, curyear) #set month data in utilcur of data to measurement building.months[i]['post'] = getMeasurement(sheet, mColumn, building_row) if ((building.months[i]['post'] != 0) and (building.months[i]['pre'] != 0)): building.pretotal = building.pretotal + building.months[i]['pre'] building.posttotal = building.posttotal + building.months[i]['post'] #collect grand total from other buildings (DOES NOT INCLUDE SELECTED BUILDING) for key in BuildingNames: if (key != code): row = findBuildingUseRow(sheet, BuildingNames[key]) for i in range(0, 12): mColumn = findMonthColumn(sheet, months[i], book.datemode, preyear) building.preGrandTotal = building.preGrandTotal + getMeasurement(sheet, mColumn, row) mColumn = findMonthColumn(sheet, months[i], book.datemode, curyear) building.postGrandTotal = building.postGrandTotal + getMeasurement(sheet, mColumn, row)