def create_inp_build_instructions(inpA, inpB, path, filename, comments=''): """ pass in two inp file paths and produce a spreadsheet showing the differences found in each of the INP sections. These differences should then be used whenever we need to rebuild this model from the baseline reference model. Note: this should be split into a func that creates a overall model "diff" that can then be written as a BI file or used programmatically """ allsections_a = funcs.complete_inp_headers(inpA) modela = swmmio.Model(inpA) modelb = swmmio.Model(inpB) #create build insructions folder if not os.path.exists(path): os.makedirs(path) filepath = os.path.join(path, filename) + '.txt' # xlpath = os.path.join(path, filename) + '.xlsx' # excelwriter = pd.ExcelWriter(xlpath) # vc_utils.create_change_info_sheet(excelwriter, modela, modelb) problem_sections = [ '[TITLE]', '[CURVES]', '[TIMESERIES]', '[RDII]', '[HYDROGRAPHS]' ] with open(filepath, 'w') as newf: #write meta data metadata = { #'Baseline Model':modela.inp.path, #'ID':filename, 'Parent Models': { 'Baseline': { inpA: vc_utils.modification_date(inpA) }, 'Alternatives': { inpB: vc_utils.modification_date(inpB) } }, 'Log': { filename: comments } } #print metadata vc_utils.write_meta_data(newf, metadata) for section in allsections_a['order']: if section not in problem_sections: #calculate the changes in the current section changes = INPDiff(modela, modelb, section) data = pd.concat( [changes.removed, changes.added, changes.altered]) #vc_utils.write_excel_inp_section(excelwriter, allsections_a, section, data) vc_utils.write_inp_section( newf, allsections_a, section, data, pad_top=False, na_fill='NaN') #na fill fixes SNOWPACK blanks spaces issue
def save(self, dir, filename): """ save the current BuildInstructions instance to file (human readable) """ if not os.path.exists(dir): os.makedirs(dir) filepath = os.path.join(dir, filename) with open (filepath, 'w') as f: vc_utils.write_meta_data(f, self.metadata) for section, change_obj in self.instructions.items(): section_df = pd.concat([change_obj.removed, change_obj.altered, change_obj.added]) vc_utils.write_inp_section(f, allheaders=None, sectionheader=section, section_data=section_df, pad_top=False, na_fill='NaN')
def create_inp_build_instructions(inpA, inpB, path, filename, comments=''): """ pass in two inp file paths and produce a spreadsheet showing the differences found in each of the INP sections. These differences should then be used whenever we need to rebuild this model from the baseline reference model. Note: this should be split into a func that creates a overall model "diff" that can then be written as a BI file or used programmatically """ allsections_a = funcs.complete_inp_headers(inpA) modela = swmmio.Model(inpA) modelb = swmmio.Model(inpB) #create build insructions folder if not os.path.exists(path): os.makedirs(path) filepath = os.path.join(path, filename) + '.txt' # xlpath = os.path.join(path, filename) + '.xlsx' # excelwriter = pd.ExcelWriter(xlpath) # vc_utils.create_change_info_sheet(excelwriter, modela, modelb) problem_sections = ['[TITLE]', '[CURVES]', '[TIMESERIES]', '[RDII]', '[HYDROGRAPHS]'] with open (filepath, 'w') as newf: #write meta data metadata = { #'Baseline Model':modela.inp.path, #'ID':filename, 'Parent Models':{ 'Baseline':{inpA:vc_utils.modification_date(inpA)}, 'Alternatives':{inpB:vc_utils.modification_date(inpB)} }, 'Log':{filename:comments} } #print metadata vc_utils.write_meta_data(newf, metadata) for section in allsections_a['order']: if section not in problem_sections: #calculate the changes in the current section changes = INPDiff(modela, modelb, section) data = pd.concat([changes.removed, changes.added, changes.altered]) #vc_utils.write_excel_inp_section(excelwriter, allsections_a, section, data) vc_utils.write_inp_section(newf, allsections_a, section, data, pad_top=False, na_fill='NaN') #na fill fixes SNOWPACK blanks spaces issue
def save(self, dir, filename): """ save the current BuildInstructions instance to file (human readable) """ if not os.path.exists(dir): os.makedirs(dir) filepath = os.path.join(dir, filename) with open(filepath, 'w') as f: vc_utils.write_meta_data(f, self.metadata) for section, change_obj in self.instructions.iteritems(): section_df = pd.concat( [change_obj.removed, change_obj.altered, change_obj.added]) vc_utils.write_inp_section(f, allheaders=None, sectionheader=section, section_data=section_df, pad_top=False, na_fill='NaN')