Beispiel #1
0
 def route_audit(id=None):
     return render('audit.html',
                   title='audit',
                   settings=settings,
                   results=results,
                   id=id,
                   prev_id=prev_ids.get(id),
                   next_id=next_ids.get(id),
                   patched=patched,
                   mounts=mounts)
Beispiel #2
0
def cmd_summary(args):
    """Generate human & machine readable summary of results"""

    from autograde.cli.util import load_patched, render, list_results, merge_results, b64str, plot_fraud_matrix, \
        plot_score_distribution, summarize_results

    path = Path(args.result or Path.cwd()).expanduser().absolute()
    assert path.is_dir(), f'{path} is no regular directory'
    include_similarities = args.similarities

    results = list()
    sources = dict()
    filenames = []
    for path_ in list_results(path):
        logger.debug(f'read {path_}')
        filenames.append(path_.absolute())

        with mount_tar(path_) as tar, cd(tar):
            r = load_patched()
            results.append(r)

            with open('code.py', mode='rt') as f:
                sources[r.checksum] = f.read()

    # merge results
    results_df = merge_results(results)
    logger.debug('store raw.csv')
    results_df.to_csv(path.joinpath('raw.csv'), index=False)

    # summarize results
    summary_df = summarize_results(results, filenames, include_tasks=True)
    logger.debug('store summary.csv')
    summary_df.to_csv(path.joinpath('summary.csv'), index=False)

    if include_similarities:
        plots = dict(distribution=b64str(plot_score_distribution(summary_df)),
                     similarities=b64str(plot_fraud_matrix(sources)))
    else:
        plots = dict(score_distribution=b64str(
            plot_score_distribution(summary_df)),
                     similarities=b64str(plot_score_distribution(summary_df)))

    logger.info('render summary.html')
    with open(path.joinpath('summary.html'), mode='wt') as f:
        f.write(
            render('summary.html',
                   title='summary',
                   summary=summary_df,
                   plots=plots))

    return 0
Beispiel #3
0
def cmd_report(args):
    """Inject a human readable report (standalone HTML) into result archive(s)"""
    from autograde.cli.util import load_patched, render, list_results

    for path in list_results(args.result):
        logger.info(f'render report for {path}')
        with mount_tar(path, mode='a') as tar, cd(tar):
            results = load_patched()
            with open('report.html', mode='wt') as f:
                f.write(
                    render('report.html',
                           title='report',
                           id=results.checksum,
                           results={results.checksum: results},
                           summary=results.summary()))

    return
Beispiel #4
0
        def route_summary():
            summary_df = summarize_results(results.values())

            plot_distribution = parse_bool(
                request.args.get('distribution', 'f')) and 2 < len(summary_df)
            plot_similarities = parse_bool(
                request.args.get('similarities', 'f')) and 1 < len(summary_df)

            plots = dict(
                distribution=b64str(plot_score_distribution(summary_df))
                if plot_distribution else None,
                similarities=b64str(plot_fraud_matrix(sources))
                if plot_similarities else None)

            return render('summary.html',
                          title='summary',
                          summary=summary_df,
                          plots=plots)
Beispiel #5
0
 def handle_error(error):
     logger.warning(f'{type(error)}: {error}')
     error = error if isinstance(
         error, HTTPException) else InternalServerError()
     return render('error.html', title='Oooops',
                   error=error), error.code
Beispiel #6
0
 def route_source(id):
     return render('source_view.html',
                   title='source view',
                   source=sources.get(id, 'None'),
                   id=id)
Beispiel #7
0
 def route_report(id):
     return render('report.html',
                   title='report (preview)',
                   id=id,
                   results=results,
                   summary=results[id].summary())
Beispiel #8
0
            plot_distribution = parse_bool(
                request.args.get('distribution', 'f')) and 2 < len(summary_df)
            plot_similarities = parse_bool(
                request.args.get('similarities', 'f')) and 1 < len(summary_df)

            plots = dict(
                distribution=b64str(plot_score_distribution(summary_df))
                if plot_distribution else None,
                similarities=b64str(plot_fraud_matrix(sources))
                if plot_similarities else None)

            return render('summary.html',
                          title='summary',
                          summary=summary_df,
                          plots=plots)

        @app.route('/stop')
        def route_stop():
            if func := request.environ.get('werkzeug.server.shutdown'):
                logger.debug('shutdown werkzeug server')
                func()
            else:
                logger.debug('not running with werkzeug server')
                return redirect('/audit')

            return render('message.html',
                          title='stop server',
                          message='ciao kakao :)')

        app.run(host=args.bind, port=args.port)