Esempio n. 1
0
def build_stats(child_videos, videos, images, out):
    """ Compute the stats for the given tree level """

    stats = {
        "det": 0,
        "pos": 0,
        "tp": 0,
        "fp": 0,
        "fn": 0,
        "dup_ev": 0,
        "dup_gt": 0,
        "ambs": 0,
    }
    nb = 0
    duration = Time()

    for cv in child_videos:
        dname = getText(cv)
        if videos.has_key(dname):
            if not args.no_levels_list:
                out <= IMG(src=images[dname], height=60)
                out <= SPAN(dname)
            for s in stats.keys():
                stats[s] += getattr(videos[dname]['evals'], s)
            duration += videos[dname]['stats']['Video duration'][0]
            nb += 1
        else:
            print "Missing results for: %s" % dname
            if not args.no_levels_list:
                out <= SPAN("** " + dname, style='font-style: italic')

        if not args.no_levels_list:
            out <= BR()

    if nb > 0:
        stats = statistics(Evaluation(**stats),
                           Video(duration=duration, start_timestamp=0))
        for s in stats.keys():
            v, f = stats[s]
            out <= SPAN(s + ": " + (f % v))
            out <= BR()
Esempio n. 2
0
def generate_html(path, datas, dirname='analysis', filename='summary.html'):
	""" Generate an HTML report """
	# Prepare datas
	datas = sorted(list(datas))

	if len(datas) == 0:
		print('No results to aggregate')
		exit(1)

	# Create HEAD and BODY
	head = HEAD(TITLE('Report'))
	body = BODY(H1('Report'))

	# Parameters section
	body <= H2('Parameters')

	# Add Command line arguments
	body <= H3('Command-line arguments')
	table = TABLE(border=1, style='border-collapse: collapse;')
	table <= TR(TH('Name') + TH('Value'), style='background: lightgray;')
	for arg in sorted(vars(args)):
		row = TR()
		row <= TD(B(arg))
		row <= TD(vars(args)[arg])
		table <= row
	body <= table

	# Add other informations
	body <= H3('Other informations')
	table = TABLE(border=1, style='border-collapse: collapse;')
	table <= TR(TH('Name') + TH('Value'), style='background: lightgray;')
	table <= TR(TD(B('Date')) + TD(strftime("%Y-%m-%d %H:%M:%S", localtime())))
	table <= TR(TD(B('Script Version')) + TD(vplib.__version__))
	table <= TR(TD(B('System info')) + TD(platform()))
	body <= table

	# Compute total
	tot = dict()
	first = datas[0]

	# Force which field is displayed
	if args.fields:
		field_names = args.fields.split(',')
	else:
		field_names = first[2]

	for k in vars(first[1]):
		for _, e, _ in datas:
			if not k in tot:
				tot[k] = 0
			tot[k] += vars(e)[k]
	vid = Time()

	for _, _, s in datas:
		if 'Video duration' in s:
			vid += s['Video duration'][0]
	total = statistics(Evaluation(**tot), Video(duration=vid,start_timestamp=0))

	# Results
	body <= H2('Results')
	table = TABLE(border=1, style='border-collapse: collapse;', id='result_table')
	row = TR(style='background: lightgray;')

	if args.vertical:
		# Results section (alternative code: vertical layout, can be used for printing or with diff command)
		# header
		row <= TH('Statistics')
		row <= TH('')
		for k in field_names:
			row <= TH(k)
		table <= row

		# Totals
		row = TH('Overall')
		row <= TD()
		for k in field_names:
			if k in total:
				v, f = total[k]
				if f == '%s' and str(v) == '-' * 20:
					row <= TD("")
				else:
					row <= TD(f % v)
		table <= row

		# Detail
		for col, _, s in datas:
			row = TR()
			row <= TH(A(B(col.split('_')[0]), href=os.path.join(col, dirname, 'report.html')))
			row <= TD(IMG(src=os.path.join(col, dirname, 'thumbnail.jpg'), width=60))
			for k in field_names:
				# row <= TD(B(k))
				v, f = s[k]
				if f == '%s' and str(v) == '-' * 20:
					row <= TD("")
				else:
					row <= TD(f % v)
			table <= row
	else:

		# Results section
		row <= TH('Statistics')
		row <= TH('Overall')
		for col in datas:
			row <= TH(A(B(col[0].split('_')[0]), href=os.path.join(col[0], dirname, 'report.html')))
		table <= row
		row = TR()
		row <= TD('')
		row <= TD('')
		for col in datas:
			row <= TD(IMG(src=os.path.join(col[0], dirname, 'thumbnail.jpg'),
						  width=120))
		table <= row

		for k in field_names:
			row = TR()
			row <= TD(B(k))
			# Total
			if k in total:
				v, f = total[k]
				if f == '%s' and str(v) == '-' * 20:
					row <= TD('')
				else:
					row <= TD(f % v)
			else:
				row <= TD('N/A')
			# Statistics of each video
			for _, _, s in datas:
				v, f = s[k]
				row <= TD(f % v)

			table <= row

	body <= table

	# Get file path
	fpath = os.path.join(path, filename)

	# Write the file
	with open(fpath, 'w') as f:
		f.write(str(HTML(head + body)))

	# Open report in browser
	if not args.no_browser:
		try:
			subprocess.call(['xdg-open', os.path.abspath(fpath)])
		except OSError:
			print('Please open a browser on: ' + path)
Esempio n. 3
0
def generate_html(path, datas, dirname='analysis', filename='summary.html'):
    """ Generate an HTML report """
    # Prepare datas
    datas = sorted(list(datas))

    if len(datas) == 0:
        print('No results to aggregate')
        exit(1)

    # Create HEAD and BODY
    head = HEAD(TITLE('Report'))
    body = BODY(H1('Report'))

    # Parameters section
    body <= H2('Parameters')

    # Add Command line arguments
    body <= H3('Command-line arguments')
    table = TABLE(border=1, style='border-collapse: collapse;')
    table <= TR(TH('Name') + TH('Value'), style='background: lightgray;')
    for arg in sorted(vars(args)):
        row = TR()
        row <= TD(B(arg))
        row <= TD(vars(args)[arg])
        table <= row
    body <= table

    # Add other informations
    body <= H3('Other informations')
    table = TABLE(border=1, style='border-collapse: collapse;')
    table <= TR(TH('Name') + TH('Value'), style='background: lightgray;')
    table <= TR(TD(B('Date')) + TD(strftime("%Y-%m-%d %H:%M:%S", localtime())))
    table <= TR(TD(B('Script Version')) + TD(vplib.__version__))
    table <= TR(TD(B('System info')) + TD(platform()))
    body <= table

    # Compute total
    tot = dict()
    first = datas[0]

    # Force which field is displayed
    if args.fields:
        field_names = args.fields.split(',')
    else:
        field_names = first[2]

    for k in vars(first[1]):
        for _, e, _ in datas:
            if not k in tot:
                tot[k] = 0
            tot[k] += vars(e)[k]
    vid = Time()

    for _, _, s in datas:
        if 'Video duration' in s:
            vid += s['Video duration'][0]
    total = statistics(Evaluation(**tot), Video(duration=vid,
                                                start_timestamp=0))

    # Results
    body <= H2('Results')
    table = TABLE(border=1,
                  style='border-collapse: collapse;',
                  id='result_table')
    row = TR(style='background: lightgray;')

    if args.vertical:
        # Results section (alternative code: vertical layout, can be used for printing or with diff command)
        # header
        row <= TH('Statistics')
        row <= TH('')
        for k in field_names:
            row <= TH(k)
        table <= row

        # Totals
        row = TH('Overall')
        row <= TD()
        for k in field_names:
            if k in total:
                v, f = total[k]
                if f == '%s' and str(v) == '-' * 20:
                    row <= TD("")
                else:
                    row <= TD(f % v)
        table <= row

        # Detail
        for col, _, s in datas:
            row = TR()
            row <= TH(
                A(B(col.split('_')[0]),
                  href=os.path.join(col, dirname, 'report.html')))
            row <= TD(
                IMG(src=os.path.join(col, dirname, 'thumbnail.jpg'), width=60))
            for k in field_names:
                # row <= TD(B(k))
                v, f = s[k]
                if f == '%s' and str(v) == '-' * 20:
                    row <= TD("")
                else:
                    row <= TD(f % v)
            table <= row
    else:

        # Results section
        row <= TH('Statistics')
        row <= TH('Overall')
        for col in datas:
            row <= TH(
                A(B(col[0].split('_')[0]),
                  href=os.path.join(col[0], dirname, 'report.html')))
        table <= row
        row = TR()
        row <= TD('')
        row <= TD('')
        for col in datas:
            row <= TD(
                IMG(src=os.path.join(col[0], dirname, 'thumbnail.jpg'),
                    width=120))
        table <= row

        for k in field_names:
            row = TR()
            row <= TD(B(k))
            # Total
            if k in total:
                v, f = total[k]
                if f == '%s' and str(v) == '-' * 20:
                    row <= TD('')
                else:
                    row <= TD(f % v)
            else:
                row <= TD('N/A')
            # Statistics of each video
            for _, _, s in datas:
                v, f = s[k]
                row <= TD(f % v)

            table <= row

    body <= table

    # Get file path
    fpath = os.path.join(path, filename)

    # Write the file
    with open(fpath, 'w') as f:
        f.write(str(HTML(head + body)))

    # Open report in browser
    if not args.no_browser:
        try:
            subprocess.call(['xdg-open', os.path.abspath(fpath)])
        except OSError:
            print('Please open a browser on: ' + path)