예제 #1
0
def df_to_html_table(df, color='white', df_img_col_indexs=[-1]):
    """df转化为html表格输出, 简单的columns为[txt, img]
    df : 数据源
    color : background
    df_img_col_indexs : list ,img字段的col索引, 一般放在最后几个字段, 因此里面的值只能是负值
    return: str html"""
    assert (np.max(df_img_col_indexs) < 0)
    page = pyh.PyH('report')
    mytab = page << pyh.table()
    for i in range(len(df)):
        mytr = mytab << pyh.tr(style="background-color:%s" % (color))
        v = df.iloc[i][:np.min(df_img_col_indexs)]
        if v.name == 0 and len(v.tolist()) == 1:
            v = v[0]
        s = str(v)
        if not agl.is_utf8(s):  #命令行时会碰到需要转码的情况
            try:
                s = s.decode('gb2312').encode('utf8')
            except:
                pass
        mytr << pyh.td('<pre>%s</pre>' % (s))
        for j in df_img_col_indexs:
            mytr << pyh.td('Row %i, column <img src="%s"/>' %
                           (i, os.path.basename(df.iloc[i][df.columns[j]])))
    return page.render()
 def _HTML_table_detail(num_table):
     t = pyh.table()
     for i in xrange(len(cfg.TIME)):
         tr = t << pyh.tr(style='border:1px solid;')
         tr << pyh.td(cfg.TIME[i])
         for j in range(len(cfg.DAY)):
             cid = num_table[i][j]
             if cid == -1:
                 tr << pyh.td(' ', style='border: 1px solid;')
             else:
                 c = self.id_to_course(cid)
                 info = "%s[%s]" % (c.name,c.teachers[0])
                 tr << pyh.td(info, style='border: 1px solid;')
     return t
예제 #3
0
    def table(self, form):
        mytable = self.__report << pyh.table()
        n_row = form.index.size
        n_col = form.columns.size
        mytable << pyh.tr()
        for i in range(n_col):
            mytable << pyh.th(str(form.columns[i]))

        for i in range(n_row):
            mytable << pyh.tr()
            for j in range(n_col):
                mytable << pyh.td(str(form.iloc[i, j]))
예제 #4
0
	def __writeHtmlTestResult(self):
		content_format="%-*s%-*s%*s%*s%*s"
		content_format2="%-*s%*s" # '-' means left just (right just by default) http://www.cnblogs.com/zero86/archive/2012/11/22/2783679.html
		content_format3="%-*s%*d"
		self.Total=self.testPool.getTotalCount()
		self.Pass=self.testPool.getPassCount()
		self.Fail=self.testPool.getFailCount()
		## create HTML content
		page = PyH('Test Result')
		page << h3('Overall Result:')
#		table0 = page << table(border='0',id='table_overall')
#		tmpRow = table0 << tr(id='line1')
#		tmpRow << td("Total:") <<td(str(self.Total))
#		tmpRow = table0 << tr(id='line2')
#		tmpRow << td("Pass:"******"Fail:") <<td(str(self.Fail))
#		tmpRow = table0 << tr(id='line4')
#		tmpRow << td("Not Run:") <<td(str(self.Total-self.Pass-self.Fail))
		page << p(content_format3 % (10, 'Total:' , 5, self.Total))
		page << p(content_format3 % (10, 'Pass:'******'Fail:' , 5, self.Fail))
		page << p(content_format3 % (10, 'Not Run:' , 5, self.Total-self.Pass-self.Fail))
		if self.Fail>0:
			page << h3('Failed Testcase:',style='color:red;')
			table1 = page << table(border='1',cellPadding='5',id='table_failedTest')
			headtr = table1 << tr(id='headline1')
			headtr << td('Test Name') << td('Failure Description') << td('Device')<< td('Start Time')<< td('End Time')

			for tc in self.testPool.queue:
				if tc.result == TestStatus.Fail:
					tmpRow = table1 << tr(id='line1')
					tmpRow << td(tc.name) <<td(tc.errormsg)<<td(tc.device)<<td(tc.start_time)<<td(tc.end_time)
#					page << content_format % (25, tc.name, 45, '\t'+tc.errormsg, 30, '\t'+tc.device, 20, '\t'+tc.start_time, 20, '\t'+tc.end_time)
#			page << H_LINE
		if self.Pass>0:
			page << h3('Passed Testcase:',style='color:green;')
			table2 = page << table(border='1',cellPadding='5',id='table_passedTest')
			headtr = table2 << tr(id='headline2')
			headtr << td('Test Name') << td('Test Description') << td('Device')<< td('Start Time')<< td('End Time')
#			page << content_format % (25, 'Test Name', 45, 'Test Description', 30, "\tDevice", 20, "\tStart Time", 20, "\tEnd Time")
#			page << H_LINE
			for tc in self.testPool.queue:
				if tc.result == TestStatus.Pass:
					tmpRow = table2 << tr(id='line2')
					tmpRow << td(tc.name) <<td(tc.desc)<<td(tc.device)<<td(tc.start_time)<<td(tc.end_time)
#					page << content_format % (25, tc.name, 45, tc.desc, 30, '\t'+tc.device,20, '\t'+tc.start_time, 20, '\t'+tc.end_time)

		## Test time
		mydiv2 = page << div(id='myDiv2')
		mydiv2 << h4('Test build:')+ p(CLIENT_VERSION_PREFIX+str(self.buildnum))
		mydiv2 << h4('Test start:')+ p(self.start_time)
		mydiv2 << h4('Test stop: ')+ p(self.end_time)

		## host info
		mydiv2 << h4('Test Server:  ')+ p(TestServer().getHostname())
#		page << h4(content_format2 % (11, 'Test start:', 30, self.start_time), cl='left')
#		page << h4(content_format2 % (11, 'Test stop: ', 30, self.end_time), cl='left')
#		page << h4(content_format2 % (11, 'Build:', 30, CLIENT_VERSION_PREFIX+str(self.buildnum)), cl='left')
		## Test device
		mydiv2 << h4('Test Devices:')
		count=0
		table_device = mydiv2 << table(cellSpacing='1', cellPadding='5', border='1',borderColor='#666666', id='table_device')
		table_device.attributes['cellSpacing'] = 1

		headtr = table_device << tr(id='headline5')
		headtr << td('No.') << td('Make') << td('Model') << td('Android Version') << td('ID')
		for device in self.devicePool.queue:
			count+=1
			tmpRow = table_device << tr(id='line1')
			tmpRow << td(str(count)) <<td(device.make)<<td(device.model)<<td(device.androidVersion)<<td(device.deviceId)
#			page << h5(content_format2 % (11, 'Device'+str(count)+":\t", 50, \
#			device.make+' '+device.model+' '+device.androidVersion+' ' + device.deviceId))
		## write file
		page.printOut(file=self.suiteName+'.html')
예제 #5
0
def create_save_miss_html(sheet_name, Silver_url_list, purl_bak_string='Purley-FPGA'):
    if sheet_name == 'Save-Miss':
        page = PyH('excel结果html表格数据')
        page << h1(sheet_name + ' result')
        cell_data_list = get_report_data(sheet_name, purl_bak_string=purl_bak_string)
        # print cell_data_list

        mytab = table(border="1", cellspacing="1px")
        for i in range(len(cell_data_list)):
            mytr = mytab << tr()
            for j in range(len(Silver_url_list) + 3):
                if j == 0:
                    mytr << td(cell_data_list[i][j], style="width:60px")
                else:
                    mytr << td(cell_data_list[i][j])
        page << mytab

    elif sheet_name in ('ExistingSi', 'NewSi'):
        page = PyH('excel结果html表格数据')
        page << h1(sheet_name + ' result')
        cell_data_list = get_report_data(sheet_name, purl_bak_string=purl_bak_string)
        mytab = table(border="1", cellspacing="1px")

        for k in range(len(cell_data_list)):
            cell_data_list[k] = cell_data_list[k][2:]

        for i in range(len(cell_data_list)):
            mytr = mytab << tr()
            for j in range(len(cell_data_list[0])):
                if j == 1:
                    mytr << td(cell_data_list[i][j], style="width:150px")
                else:
                    mytr << td(cell_data_list[i][j])
        page << mytab

    else:
        page = PyH('excel结果html表格数据')
        page << h1(sheet_name + ' result')
        cell_data_list = get_report_data(sheet_name, purl_bak_string=purl_bak_string)
        mytab = table(border="1", cellspacing="1px")

        cell_data_list[0][2] = ''
        for i in range(len(cell_data_list)):
            mytr = mytab << tr()
            for j in range(len(cell_data_list[0])):
                if i == 0 and j == 0:
                    mytr << td(cell_data_list[i][j], style="background-color:#D2691E;width:60px")
                elif i == 0 and j == 1:
                    mytr << td(cell_data_list[i][j], style="font-size:30px;color:#00008B;background-color:#FFDEAD;width:50px")
                elif i == 0 and j == 2:
                    mytr << td(cell_data_list[i][j], style="background-color:#FFDEAD;width:50px")
                elif i == 0 and j == 3:
                    mytr << td(cell_data_list[i][j], style="background-color:#FFDEAD;width:120px")
                elif i == 1 and j != 0:
                    mytr << td(cell_data_list[i][j], style="font-weight:bold")
                elif j == 0 and cell_data_list[i][j] == True:
                    mytr << td(cell_data_list[i][j], style="background-color:#FFB6C1;color:#800000")
                elif (j == 0 and cell_data_list[i][j] == False) or (i == 1 and j == 0):
                    mytr << td(cell_data_list[i][j])
                else:
                    mytr << td(cell_data_list[i][j], style="background-color:#FFDEAD")
        page << mytab

    if not os.path.exists(os.getcwd() + os.sep + 'html_result'):
        os.makedirs(os.getcwd() + os.sep + 'html_result')

    page.printOut(os.getcwd() + os.sep + 'html_result' + os.sep + sheet_name + '_html_data.html')