<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Relatório de Modelos</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 40px; }
        table { width: 100%; border-collapse: collapse; margin-bottom: 40px; }
        th, td { border: 1px solid #ccc; padding: 8px; text-align: center; }
        th { background-color: #f2f2f2; }
        h2 { margin-top: 40px; }
        h1 { border-bottom: 2px solid #000; padding-bottom: 10px; }
    </style>
</head>
<body>
    <h1>Relatório de Modelos</h1>

    {% for report in reports_by_score %}
        <h2>Score Target: {{ report.score_target }}</h2>

        <h3>Estatísticas dos Modelos</h3>
        <table>
            <tr>
                <th>Model Name</th>
                <th>Mean</th>
                <th>Std</th>
                <th>Median</th>
                <th>Min</th>
                <th>Max</th>
                <th>Mode</th>
            </tr>
            {% for model in report.score_described %}
            <tr>
                <td>{{ model.model_name }}</td>
                <td>{{ '%.4f' | format(model.mean) }}</td>
                <td>{{ '%.4f' | format(model.std) }}</td>
                <td>{{ '%.4f' | format(model.median) }}</td>
                <td>{{ '%.4f' | format(model.minimum) }}</td>
                <td>{{ '%.4f' | format(model.maximum) }}</td>
                <td>{{ '%.4f' | format(model.mode) }}</td>
            </tr>
            {% endfor %}
        </table>

        <h3>Pipeline de Testes A/B</h3>
        <ul>
            {% for etapa in report.ab_tests.pipeline_track %}
            <li>{{ etapa }}</li>
            {% endfor %}
        </ul>

        {% if "check_normality_with_shapiro" in report.ab_tests.pipeline_track %}
            <h3>Shapiro-Wilk</h3>
            <table>
                <tr>
                    <th>Contexto</th>
                    <th>Stat</th>
                    <th>p-value</th>
                    <th>Normal?</th>
                </tr>
                {% for test in report.ab_tests.shapirowilk %}
                <tr>
                    {% if test.stat is none and test.p_value is none%}
                        <td>{{ test.context }}</td>
                        <td> NaN </td>
                        <td> NaN </td>
                        <td>{{ 'Sim' if test.is_normal else 'Não' }}</td>
                    {% else %}
                        <td>{{ test.context }}</td>
                        <td>{{ '%.4f' | format(test.stat) }}</td>
                        <td>{{ '%.4e' | format(test.p_value) }}</td>
                        <td>{{ 'Sim' if test.is_normal else 'Não' }}</td>
                    {% endif %}
                </tr>
                {% endfor %}
            </table>
        {% endif %}
        
        {% if "check_homocedasticity_with_levene" in report.ab_tests.pipeline_track %}
            <h3>Levene</h3>
            {% if report.ab_tests.levene.stat is none and report.ab_tests.levene.p_value is none%}
                <p>Stat: NaN |
                    p-value: NaN |
                    Homocedástico: {{ 'Sim' if report.ab_tests.levene.is_homoscedastic else 'Não' }}</p>
            {% else %}
                <p>Stat: {{ '%.2f' | format(report.ab_tests.levene.stat) }} |
                p-value: {{ '%.4e' | format(report.ab_tests.levene.p_value) }} |
                Homocedástico: {{ 'Sim' if report.ab_tests.levene.is_homoscedastic else 'Não' }}</p>
            {% endif %}
        {% endif %}

        {% if "perform_bartlett" in report.ab_tests.pipeline_track %}
            <h3>Bartlett</h3>
            {% if report.ab_tests.bartlett.stat is none and report.ab_tests.bartlett.p_value is none%}
                <p>Stat: NaN |
                p-value: NaN |
                Homocedástico: {{ 'Sim' if report.ab_tests.bartlett.is_homoscedastic else 'Não' }}</p>
            {% else %}
                <p>Stat: {{ '%.2f' | format(report.ab_tests.bartlett.stat) }} |
                p-value: {{ '%.4e' | format(report.ab_tests.bartlett.p_value) }} |
                Homocedástico: {{ 'Sim' if report.ab_tests.bartlett.is_homoscedastic else 'Não' }}</p>
            {% endif %}
        {% endif %}

        {% if "perform_kurskalwallis" in report.ab_tests.pipeline_track %}
            <h3>Kruskal-Wallis</h3>
            {% if report.ab_tests.kurskalwallis.stat is none or report.ab_tests.kurskalwallis.p_value is none%}
                <p>Stat: NaN |
                p-value: NaN |
                Significativo: {{ 'Sim' if report.ab_tests.kurskalwallis.is_significant else 'Não' }}</p>
            {% else %}
                <p>Stat: {{ '%.2f' | format(report.ab_tests.kurskalwallis.stat) }} |
                p-value: {{ '%.4e' | format(report.ab_tests.kurskalwallis.p_value) }} |
                Significativo: {{ 'Sim' if report.ab_tests.kurskalwallis.is_significant else 'Não' }}</p>
            {% endif %}
        {% endif %}

        {% if "perform_mannwhitney" in report.ab_tests.pipeline_track %}
            <h3>Mann-Whitney</h3>
            <table>
                <tr>
                    <th>Comparação</th>
                    <th>Stat</th>
                    <th>p-value</th>
                    <th>Significativo?</th>
                </tr>
                {% for test in report.ab_tests.mannwhitney %}
                <tr>
                    <td>{{ test.context }}</td>
                    <td>{{ '%.2f' | format(test.stat) }}</td>
                    <td>{{ '%.4e' | format(test.p_value) }}</td>
                    <td>{{ 'Sim' if test.is_significant else 'Não' }}</td>
                </tr>
                {% endfor %}
            </table>
        {% endif %}

    {% endfor %}

    <h2>Conclusões de Significância</h2>
    <ul>
        {% for message in message_about_significancy %}
        <li>{{ message }}</li>
        {% endfor %}
    </ul>

    <h2>Melhor Modelo</h2>
    <ul>
        {% for better_model in better_model_by_score %}
        <li>{{ better_model }}</li>
        {% endfor %}
    </ul>
</body>
</html>
