def compare_echo_file(echo_file1,echo_file2): d = Diff() p = Parser() scalar = {} header = {} tables1 = p.parseModel(echo_file1) tables2 = p.parseModel(echo_file2) tbl_list1 = list_tables(tables1) tbl_list2 = list_tables(tables2) ex_arr_tbls = chk_num_tbls(tbl_list1,tbl_list2) tbl_names = str_to_arr(ex_arr_tbls[0]) for i in range(len(tbl_names)): print tbl_names[i] table1 = tables1.getTableNamed(tbl_names[i]) table2 = tables2.getTableNamed(tbl_names[i]) if (tbl_names[i]=='ENVVAR'): d.modifier1, d.modifier2 = get_modifier(table1,table2) try: d.modifier1 d.modifier2 except: d.modifier1="nan" d.modifier2="nan" change_tbl = compare_table(table1,table2,d.modifier1,d.modifier2) scalar[tbl_names[i]] = change_tbl header[tbl_names[i]] = table1.getHeaders() d.tbl_a = ex_arr_tbls[1] d.tbl_b = ex_arr_tbls[2] d.diff = scalar d.header = header #scalar: {'OPRULE_EXPRESSION': ([1, 2, 3], [], [[0],[0]]) return d
def parse_template_file(template_file): from gov.ca.dsm2.input.parser import Parser p = Parser() tables = p.parseModel(template_file) #load scalars into a map scalar_table = tables.getTableNamed("SCALAR") scalar_values = scalar_table.getValues() nscalars = scalar_values.size() scalars = {} for i in range(nscalars): name = scalar_table.getValue(i, "NAME") value = scalar_table.getValue(i, "VALUE") scalars[name] = value # load pathname mapping into a map pathname_mapping_table = tables.getTableNamed("PATHNAME_MAPPING") pmap_values = pathname_mapping_table.getValues() nvalues = pmap_values.size() pathname_maps=[] for i in range(nvalues): var_name = pathname_mapping_table.getValue(i, "VARIABLE") path_map = PathnameMap(var_name) path_map.report_type = pathname_mapping_table.getValue(i, "REPORT_TYPE") path_map.path1 = pathname_mapping_table.getValue(i, "PATH1") path_map.path2 = pathname_mapping_table.getValue(i, "PATH2") path_map.var_category = pathname_mapping_table.getValue(i, "VAR_CATEGORY") if path_map.path2 == None or len(path_map.path2)==0: path_map.path2 = path_map.path1 pathname_maps.append(path_map) timewindows = [] timewindow_table = tables.getTableNamed("TIME_PERIODS") tw_values = timewindow_table.getValues(); return scalars, pathname_maps, tw_values
def parse_template_file(template_file): from gov.ca.dsm2.input.parser import Parser p = Parser() tables = p.parseModel(template_file) global_table = tables.getTableNamed("GLOBAL_CONTROL") global_values = global_table.getValues() nglobals = global_values.size() globals = {} for i in range(nglobals): name = global_table.getValue(i, "CONTROLLER").encode('ascii') value = global_table.getValue(i, "MODE").encode('ascii') globals[name] = value scalar_table = tables.getTableNamed("SCALAR") scalar_values = scalar_table.getValues() nscalars = scalar_values.size() scalars = {} for i in range(nscalars): name = scalar_table.getValue(i, "NAME").encode('ascii') value = scalar_table.getValue(i, "VALUE").encode('ascii').replace( '"', '') scalars[name] = value var_table = tables.getTableNamed("VARIABLE") var_values = var_table.getValues() output_table = tables.getTableNamed("OUTPUT") output_values = output_table.getValues() ov = [] for name in output_values: ov.append(name[0].encode('ascii').replace('"', '')) output_values = ov timewindow_table = tables.getTableNamed("TIME_PERIODS") tw_values = timewindow_table.getValues() return globals, scalars, var_values, output_values, tw_values
def parse_template_file(template_file): from gov.ca.dsm2.input.parser import Parser p = Parser() tables = p.parseModel(template_file) global_table = tables.getTableNamed("GLOBAL_CONTROL") global_values = global_table.getValues() nglobals = global_values.size() globals = {} for i in range(nglobals): name = global_table.getValue(i,"CONTROLLER").encode('ascii') value = global_table.getValue(i,"MODE").encode('ascii') globals[name] = value scalar_table = tables.getTableNamed("SCALAR") scalar_values = scalar_table.getValues() nscalars = scalar_values.size() scalars = {} for i in range(nscalars): name = scalar_table.getValue(i, "NAME").encode('ascii') value = scalar_table.getValue(i, "VALUE").encode('ascii').replace('"','') scalars[name] = value var_table = tables.getTableNamed("VARIABLE") var_values = var_table.getValues() output_table = tables.getTableNamed("OUTPUT") output_values = output_table.getValues() ov = [] for name in output_values: ov.append(name[0].encode('ascii').replace('"','')) output_values = ov timewindow_table = tables.getTableNamed("TIME_PERIODS") tw_values = timewindow_table.getValues(); return globals, scalars, var_values, output_values, tw_values
def updateXCVals(GridfileIn, XCfileOut, coeffDict): p = Parser() count = 0 # coeffDict should be all elevation corrections or all # width corrections, not both; find out which one if coeffDict.keys()[0].find('ELEV') >= 0: XELEV = True XTOPW = False param = 'ELEV' else: XELEV = False XTOPW = True param = 'WIDTH' tables = p.parseModel(GridfileIn) DSM2Model = tables.toDSM2Model() Channels = DSM2Model.getChannels() for chan in Channels.getChannels(): for xs in chan.getXsections(): if float(xs.getDistance()) < 1.0: fmtStr = "%03d" else: fmtStr = "%04d" PCF = param + "%03d" % (int(xs.getChannelId())) + ':' + fmtStr % ( int(xs.getDistance() * 1000.)) coeff = coeffDict.get(PCF) if not coeff: print 'Could not find coeff for param', param, 'chan', xs.getChannelId( ), 'dist', xs.getDistance() continue runningArea = 0.0 elev = 0.0 TopWidth = 0.0 for lyr in xs.getLayers(): count += 1 area = lyr.getArea() prevElev = elev elev = lyr.getElevation() prevTW = TopWidth TopWidth = lyr.getTopWidth() WetPerim = lyr.getWettedPerimeter() if XELEV: elev = round(elev * coeff, 2) lyr.setElevation(elev) if area == 0.0: continue if XTOPW: TopWidth = round(TopWidth * coeff, 2) lyr.setTopWidth(TopWidth) runningArea += (elev - prevElev) * 0.5 * (TopWidth + prevTW) lyr.setArea(round(runningArea, 1)) lyr.setWettedPerimeter(round(WetPerim * coeff, 2)) fid = open(XCfileOut, 'w') tables.fromDSM2Model(DSM2Model) fid.write( tables.getTableNamed( 'XSECT_LAYER').toStringRepresentation().expandtabs(4)) fid.close() return count
def updateXCVals(GridfileIn, XCfileOut, coeffDict): ''' ''' p = Parser() count = 0 # coeffDict should be all elevation corrections or all # width corrections, not both; find out which one if coeffDict.keys()[0].find('ELEV') >= 0: XELEV = True XTOPW = False param = 'ELEV' else: XELEV = False XTOPW = True param = 'WIDTH' tables = p.parseModel(GridfileIn) DSM2Model = tables.toDSM2Model() Channels = DSM2Model.getChannels() for chan in Channels.getChannels(): PCF = param + "%03d" % (int(chan.getId())) try: coeff = coeffDict.get(PCF) except: raise 'Could not find coeff for param ' + PCF for xs in chan.getXsections(): runningArea = 0.0 Elev = 0.0 TopWidth = 0.0 for lyr in xs.getLayers(): count += 1 Area = lyr.getArea() prevElev = Elev Elev = lyr.getElevation() prevTW = TopWidth TopWidth = lyr.getTopWidth() WetPerim = lyr.getWettedPerimeter() if XELEV: Elev = round(Elev * coeff, 2) lyr.setElevation(Elev) if Area == 0.0: continue if XTOPW: TopWidth = round(TopWidth * coeff, 2) lyr.setTopWidth(TopWidth) runningArea += (Elev - prevElev) * 0.5 * (TopWidth + prevTW) lyr.setArea(round(runningArea, 1)) lyr.setWettedPerimeter(round(WetPerim * coeff, 2)) fid = open(XCfileOut, 'w') tables.fromDSM2Model(DSM2Model) fid.write( tables.getTableNamed('CHANNEL').toStringRepresentation().expandtabs(4)) fid.write( tables.getTableNamed( 'XSECT_LAYER').toStringRepresentation().expandtabs(4)) fid.close() return count
def updateXCVals(GridfileIn, XCfileOut, coeffDict): p = Parser() count = 0 # coeffDict should be all elevation corrections or all # width corrections, not both; find out which one if coeffDict.keys()[0].find("ELEV") >= 0: XELEV = True XTOPW = False param = "ELEV" else: XELEV = False XTOPW = True param = "WIDTH" tables = p.parseModel(GridfileIn) DSM2Model = tables.toDSM2Model() Channels = DSM2Model.getChannels() for chan in Channels.getChannels(): for xs in chan.getXsections(): if float(xs.getDistance()) < 1.0: fmtStr = "%03d" else: fmtStr = "%04d" PCF = param + "%03d" % (int(xs.getChannelId())) + ":" + fmtStr % (int(xs.getDistance() * 1000.0)) coeff = coeffDict.get(PCF) if not coeff: print "Could not find coeff for param", param, "chan", xs.getChannelId(), "dist", xs.getDistance() continue runningArea = 0.0 elev = 0.0 TopWidth = 0.0 for lyr in xs.getLayers(): count += 1 area = lyr.getArea() prevElev = elev elev = lyr.getElevation() prevTW = TopWidth TopWidth = lyr.getTopWidth() WetPerim = lyr.getWettedPerimeter() if XELEV: elev = round(elev * coeff, 2) lyr.setElevation(elev) if area == 0.0: continue if XTOPW: TopWidth = round(TopWidth * coeff, 2) lyr.setTopWidth(TopWidth) runningArea += (elev - prevElev) * 0.5 * (TopWidth + prevTW) lyr.setArea(round(runningArea, 1)) lyr.setWettedPerimeter(round(WetPerim * coeff, 2)) fid = open(XCfileOut, "w") tables.fromDSM2Model(DSM2Model) fid.write(tables.getTableNamed("XSECT_LAYER").toStringRepresentation().expandtabs(4)) fid.close() return count
def updateXCVals(GridfileIn, XCfileOut, coeffDict): """ """ p = Parser() count = 0 # coeffDict should be all elevation corrections or all # width corrections, not both; find out which one if coeffDict.keys()[0].find("ELEV") >= 0: XELEV = True XTOPW = False param = "ELEV" else: XELEV = False XTOPW = True param = "WIDTH" tables = p.parseModel(GridfileIn) DSM2Model = tables.toDSM2Model() Channels = DSM2Model.getChannels() for chan in Channels.getChannels(): PCF = param + "%03d" % (int(chan.getId())) try: coeff = coeffDict.get(PCF) except: raise "Could not find coeff for param " + PCF for xs in chan.getXsections(): runningArea = 0.0 Elev = 0.0 TopWidth = 0.0 for lyr in xs.getLayers(): count += 1 Area = lyr.getArea() prevElev = Elev Elev = lyr.getElevation() prevTW = TopWidth TopWidth = lyr.getTopWidth() WetPerim = lyr.getWettedPerimeter() if XELEV: Elev = round(Elev * coeff, 2) lyr.setElevation(Elev) if Area == 0.0: continue if XTOPW: TopWidth = round(TopWidth * coeff, 2) lyr.setTopWidth(TopWidth) runningArea += (Elev - prevElev) * 0.5 * (TopWidth + prevTW) lyr.setArea(round(runningArea, 1)) lyr.setWettedPerimeter(round(WetPerim * coeff, 2)) fid = open(XCfileOut, "w") tables.fromDSM2Model(DSM2Model) fid.write(tables.getTableNamed("CHANNEL").toStringRepresentation().expandtabs(4)) fid.write(tables.getTableNamed("XSECT_LAYER").toStringRepresentation().expandtabs(4)) fid.close() return count
def parse_template_file(template_file): p = Parser() tables = p.parseModel(template_file) #load scalars into a map scalar_table = tables.getTableNamed("SCALAR") scalar_values = scalar_table.getValues() nscalars = scalar_values.size() scalars = {} for i in range(nscalars): name = scalar_table.getValue(i, "NAME").encode('ascii') value = scalar_table.getValue(i, "VALUE").encode('ascii') scalars[name] = value return scalars
def setUp(self): echo_file1 = 'D:/workspace/vista-vdiff/scripts/compare_inp/hydro_echo_SC_ELT_MidRange.inp' echo_file2 = 'D:/workspace/vista-vdiff/scripts/compare_inp/hydro_echo_SC_ELT_SLR15_ROA25.inp' p = Parser() tables1 = p.parseModel(echo_file1) tables2 = p.parseModel(echo_file2) table1 = tables1.getTableNamed('RESERVOIR_CONNECTION') table2 = tables2.getTableNamed('RESERVOIR_CONNECTION') a1 = GetModel(table1) a2 = GetModel(table2) self.a1key = a1.get_keys() self.block1 = a1.get_block_by_key(str(self.a1key[0])) self.block2 = a2.get_block_by_key(str(self.a1key[0])) res = CompareBlocks(self.block1, self.block2) self.chk = res.chk_len_block()
def setUp(self): echo_file1 = 'D:/workspace/vista-vdiff/scripts/compare_inp/hydro_echo_SC_ELT_MidRange.inp' echo_file2 = 'D:/workspace/vista-vdiff/scripts/compare_inp/hydro_echo_SC_ELT_SLR15_ROA25.inp' p = Parser() tables1 = p.parseModel(echo_file1) tables2 = p.parseModel(echo_file2) table1 = tables1.getTableNamed('RESERVOIR_CONNECTION') table2 = tables2.getTableNamed('RESERVOIR_CONNECTION') a1 = GetModel(table1) a2 = GetModel(table2) self.a1key = a1.get_keys() self.block1=a1.get_block_by_key(str(self.a1key[0])) self.block2=a2.get_block_by_key(str(self.a1key[0])) res=CompareBlocks(self.block1,self.block2) self.chk = res.chk_len_block()
def write_summary_table(echo_file1,echo_file2,fh,d): p = Parser() tables1 = p.parseModel(echo_file1) tables2 = p.parseModel(echo_file2) keys = d.diff.keys() keys.sort() head1=get_pathandname(echo_file1)[0]+"<br><k>"+get_pathandname(echo_file1)[1]+"</k>" head2=get_pathandname(echo_file2)[0]+"<br><k>"+get_pathandname(echo_file2)[1]+"</k>" print >> fh, "<h2><center>DSM2 Input Comparison Report</center></h2>" print >> fh, """<table class="summary" align=center><tr><th>Table Name</th> <th>Extra record in <br>%s</th><th>Extra record in <br>%s</th> <th>Modified records</th></tr>""" %(head1,head2) for i in range(len(keys)): a = d.diff[keys[i]] if a[3] == 0: print >> fh, "<tr><td><a href='#h%s'>%s</a></td>"%(i,keys[i]) if len(a[0])>0: print >> fh, '<td class="red"><center>%d</center></td>'%(len(a[0])) else: print >> fh, '<td><center>%d</center></td>'%(len(a[0])) if len(a[1])>0: print >> fh, '<td class="red"><center>%d</center></td>'%(len(a[1])) else: print >> fh, '<td><center>%d</center></td>'%(len(a[1])) if len(a[2][0])>0: print >> fh, '<td class="red"><center>%d</center></td></tr>'%(len(a[2][0])) else: print >> fh, '<td><center>%d</center></td></tr>'%(len(a[2][0])) else: print >> fh, """<tr><td><a href='#h%s'>%s</a></td>"""%(i,keys[i]) if a[0]>0: print >> fh, '<td class="red"><center>%d</center></td>'%(a[0]) else: print >> fh, '<td><center>%d</center></td>'%(a[0]) if a[1]>0: print >> fh, '<td class="red"><center>%d</center></td>'%(a[1]) else: print >> fh, '<td><center>%d</center></td>'%(a[1]) if a[2]>0: print >> fh, '<td class="red"><center>%d</center></td></tr>'%(a[2]) else: print >> fh, '<td><center>%d</center></td></tr>'%(a[2]) print >> fh, "</table><br>" print >> fh, '<center><span>Color Styles: </span><span style="background-color:#F6CCDA" title="extra record in study 1">   Extra record in Study 1 </span> ' print >> fh, '<span style="background-color:#DAF4F0" title="extra record in study 2">   Extra record in Study 2 </span> ' print >> fh, '<span style="background-color:#FFFACD" title="modification made for tables with NON-UNIQUE lookup name at the first column">   Modified block </span> ' print >> fh, '<span style="background-color:yellow;color:red" title="modification made for tables with UNIQUE lookup name at the first column"> Difference </span></center><br>'
def get_output_html(template_file): from gov.ca.dsm2.input.parser import Parser p = Parser() tables = p.parseModel(template_file) scalar_table = tables.getTableNamed("SCALAR") scalar_values = scalar_table.getValues() nscalars = scalar_values.size() for i in range(nscalars): name = scalar_table.getValue(i, "NAME").encode('ascii') value = scalar_table.getValue(i, "VALUE").encode('ascii').replace('"','') if name=='OUTDIR': outdir = value if name=='OUTFILE': outfile = value if outdir!="" and outfile!="": return outdir, outfile else: logging.debug("Output directory and output html file are not specified!!") return None
def get_output_html(template_file): from gov.ca.dsm2.input.parser import Parser p = Parser() tables = p.parseModel(template_file) scalar_table = tables.getTableNamed("SCALAR") scalar_values = scalar_table.getValues() nscalars = scalar_values.size() for i in range(nscalars): name = scalar_table.getValue(i, "NAME").encode('ascii') value = scalar_table.getValue(i, "VALUE").encode('ascii').replace( '"', '') if name == 'OUTDIR': outdir = value if name == 'OUTFILE': outfile = value if outdir != "" and outfile != "": return outdir, outfile else: logging.debug( "Output directory and output html file are not specified!!") return None
from gov.ca.dsm2.input.parser import Parser if __name__=='__main__': base_dir="z:/calibration/" setup_file='setup.inp' p=Parser() inputTables=p.parseModel(base_dir+setup_file) table = inputTables.getTableNamed("CHANNEL_GROUPS"); nrows=len(table.getValues()) groups={} for i in range(nrows): gname=table.getValue(i,"GROUP_NAME") groups[gname]=gname print groups
from gov.ca.dsm2.input.parser import Parser if __name__ == '__main__': base_dir = "z:/calibration/" setup_file = 'setup.inp' p = Parser() inputTables = p.parseModel(base_dir + setup_file) table = inputTables.getTableNamed("CHANNEL_GROUPS") nrows = len(table.getValues()) groups = {} for i in range(nrows): gname = table.getValue(i, "GROUP_NAME") groups[gname] = gname print groups
MANN = False DISP = False XELEV = False XTOPW = False LENGTH = True # node input parameters DICU = False # reservoir input parameters RESDEPTH = False infile = 'd:/delta/models/studies/2000-Calibration/historical/output/hydro_echo_hist-calib2000.inp' DICUdir = 'd:/delta/models/timeseries/' outdir = 'd:/delta/models/studies/2010-Calibration/SensitivityTests/PerturbedInputFiles/' outfilenm = 'PerturbedInp' p = Parser() tables = p.parseModel(infile) if MANN or DISP or XELEV or XTOPW or LENGTH: if MANN: PTBID = 'MANN' elif DISP: PTBID = 'DISP' elif LENGTH: PTBID = 'LEN' elif XELEV: PTBID = 'XELEV' elif XTOPW: PTBID = 'XTOPW' PTBID += '-ALL' # fid_EnvLabel is the study label/name fid_EnvLabel = open(outdir + 'ALL', 'w') fid_EnvLabel.write('ENVVAR\n') fid_EnvLabel.write('NAME\tVALUE\n'.expandtabs()) fid_EnvLabel.write(('PTB\t' + PTBID).expandtabs()) fid_EnvLabel.write('\nEND\n') fid_EnvLabel.close()
def parseAndAddInput(file, tables): p = Parser() from java.io import FileInputStream fis = FileInputStream(file) p.parseAndAddToModel(tables, fis)
def parseInput(file): p = Parser() return p.parseModel(file)
if RESDEPTH: PTB = 'Depth_Res' if DICU: if QDIV: PTB = 'DICU-QDIV_Nd' if QRET: PTB = 'DICU-QRET_Nd' if ECRET: PTB = 'DICU-ECRET_Nd' infile = 'd:/delta/models/studies/2000-Calibration/historical/output/hydro_echo_hist-calib2000.inp' DICUdir = 'd:/delta/models/timeseries/' outdir = 'd:/delta/models/studies/2010-Calibration/SensitivityTests/PtbInFiles-' + PTB + '/' outfilenm = 'PerturbedInp' if os.path.exists(outdir): shutil.rmtree(outdir) os.mkdir(outdir) p = Parser() tables = p.parseModel(infile) for fn in glob.glob(outdir + '???'): try: os.remove(fn) except: pass if MANN or DISP or XELEV or XTOPW or LENGTH: channels = tables.toChannels() for chan in channels.getChannels(): chan3 = "%03d" % int(chan.getId()) if MANN: # mannings N... PTBID = PTB + chan3 Val = chan.getMannings() newVal = int(10000. * (Val * (1. + pctChange / 100.)) + 0.5) / 10000.
def write_diff_table(echo_file1,echo_file2,fh,d): p = Parser() tables1 = p.parseModel(echo_file1) tables2 = p.parseModel(echo_file2) keys = d.diff.keys() keys.sort() for i in range(len(keys)): a = d.diff[keys[i]] h = d.header[keys[i]] num_headers = len(h)*2+1 print >> fh, """<table width="200px" id="h%s" class="sample"><tr><th colspan=%s align=left> <img src="js/open.JPG" name="img_%s" onClick="hideDiv('%s');"> %s</th></tr></table>""" %(i,num_headers,i,i,keys[i]) print >> fh, "<table id='%s' width='1200px' class='sample'>"%(i) print >> fh, """<tr><td class='header' colspan=%s><center>%s</center></td><td class='header'></td><td class='header' colspan=%s><center>%s</center></td></tr> """%(len(h),get_pathandname(echo_file1)[1],len(h),get_pathandname(echo_file2)[1]) print >> fh, "<tr>" for c in h: print >> fh, "<td class='header'>"+c.encode('ascii')+"</td>" if a[3] == 0: # unique key out_arr = retrieve_select_data(tables1.getTableNamed(keys[i]),tables2.getTableNamed(keys[i]),d.diff[keys[i]],d) full_arr = retrieve_full_data(tables1.getTableNamed(keys[i]),tables2.getTableNamed(keys[i]),d.diff[keys[i]],d) #write diff table print >> fh, """<td rowspan=%s width="5px" class='header'></td>"""%(len(out_arr)+1) for c in h: print >> fh, "<td class='header'>"+c.encode('ascii')+"</td>" print >> fh, "</tr>" for j in range(len(out_arr)): print >> fh, "<tr>" maxlen = max(len(out_arr[j][0]),len(out_arr[j][1])) if len(out_arr[j][0])>0 and len(out_arr[j][1])>0: for k in range(maxlen): print >> fh, "<td>"+out_arr[j][0][k]+"</td>" for k in range(maxlen): print >> fh, "<td>"+out_arr[j][1][k]+"</td>" if len(out_arr[j][0])>0 and len(out_arr[j][1])==0: for k in range(maxlen): print >> fh, "<td class='add1'>"+out_arr[j][0][k]+"</td>" for k in range(maxlen): print >> fh,"<td></td>" if len(out_arr[j][0])==0 and len(out_arr[j][1])>0: for k in range(maxlen): print >> fh, "<td></td>" for k in range(maxlen): print >> fh, "<td class='add2'>"+out_arr[j][1][k]+"</td>" print >> fh, "</tr>" print >> fh, """</table>""" #write full table print >> fh, "<table id='f%s' width='1200px' class='sample' style='display:none'><tr>"%(i) for c in h: print >> fh, "<td class='header'>"+c.encode('ascii')+"</td>" print >> fh, """<td rowspan=%s width="5px" class='header'></td>"""%(len(full_arr)+1) for c in h: print >> fh, "<td class='header'>"+c.encode('ascii')+"</td>" print >> fh, "</tr>" for j in range(len(full_arr)): print >> fh, "<tr>" maxlen = max(len(full_arr[j][0]),len(full_arr[j][1])) if len(full_arr[j][0])>0 and len(full_arr[j][1])>0: #modified for k in range(maxlen): print >> fh, "<td>"+full_arr[j][0][k]+"</td>" for k in range(maxlen): print >> fh, "<td>"+full_arr[j][1][k]+"</td>" if len(full_arr[j][0])>0 and len(full_arr[j][1])==0: #addition in senario 1 for k in range(maxlen): print >> fh, "<td class='add1'>"+full_arr[j][0][k]+"</td>" for k in range(maxlen): print >> fh,"<td></td>" if len(full_arr[j][0])==0 and len(full_arr[j][1])>0: #addition in senario 2 for k in range(maxlen): print >> fh, "<td></td>" for k in range(maxlen): print >> fh, "<td class='add2'>"+full_arr[j][1][k]+"</td>" print >> fh, "</tr>" print >> fh, """</table>""" print >> fh, "<br>" else: #non-unique key a = d.diff[keys[i]] #comp = CompareTables(tables1.getTableNamed(keys[i]),tables2.getTableNamed(keys[i]),d.modifier1,d.modifier2) #content_diff = comp.get_str_diff() #content_all = comp.get_str_all() #write diff table print >> fh, """<td rowspan=%s width="5px" class='header'></td>"""%(a[5]+1) for c in h: print >> fh, "<td class='header'>"+c.encode('ascii')+"</td>" print >> fh, "</tr>" print >> fh, a[4][0]+"</table>" #write full table print >> fh, "<table id='f%s' width='1200px' class='sample' style='display:none'><tr>"%(i) for c in h: print >> fh, "<td class='header'>"+c.encode('ascii')+"</td>" if a[6]<7000: print >> fh, """<td rowspan=%s width="5px" class='header'></td>"""%(a[6]+1) else: print >> fh, """<td rowspan=%s width="5px" class='header'></td>"""%(a[7]+1) for c in h: print >> fh, "<td class='header'>"+c.encode('ascii')+"</td>" print >> fh, "</tr>" print >> fh, a[4][1]+ "</table>" print >> fh, "<br>"