#!/usr/bin/env python3

#
# Development Order #8:
#
# This file is called when perfSonar goes to print the result, which
# has been returned from the tool.
#
# To test this file, a result is needed. A sample one has been provided
# in this directory. Use the following syntax:
# cat example-result.json | ./result-format text/plain
# cat example-result.json | ./result-format text/html
#

import pscheduler

from validate import result_is_valid
from validate import MAX_SCHEMA


TEMPLATE = '''
{% if _mime_type == 'text/plain' %}

Duration ......... {{ result.time }}
Sent ............. {{ siformat(result.bytessent) }}B
Throughput ....... {{ siformat(result.throughput) }}b/sec

{% elif _mime_type == 'text/html' %}

<table>
<tr><td>Time</td><td>{{ time }}</td></tr>
<tr><td>Sent</td><td>{{ siformat(result.bytessent) }}B</td></tr>
<tr><td>Sent</td><td>{{ siformat(result.throughput) }}b/sec</td></tr>
</table>
{% else %}

{{ error('Unsupported MIME type "' + _mime_type + '"') }}

{% endif %}
'''

pscheduler.result_format_method(TEMPLATE, max_schema=MAX_SCHEMA, validator=result_is_valid)
