<commit_before>/*
 *    Copyright 2017 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.trevjonez.kontrast.report

import kotlinx.html.ScriptType
import kotlinx.html.Tag
import kotlinx.html.a
import kotlinx.html.body
import kotlinx.html.div
import kotlinx.html.h1
import kotlinx.html.h2
import kotlinx.html.h3
import kotlinx.html.head
import kotlinx.html.header
import kotlinx.html.html
import kotlinx.html.img
import kotlinx.html.link
import kotlinx.html.meta
import kotlinx.html.nav
import kotlinx.html.script
import kotlinx.html.section
import kotlinx.html.span
import kotlinx.html.stream.appendHTML
import kotlinx.html.style
import kotlinx.html.title
import org.gradle.api.tasks.testing.TestResult
import java.io.File

class ReportIndexHtml(val outputDir: File, val variantName: String, val deviceAlias: String, val testCases: List<TestCaseData>) : ReportFile {
    override fun write() {
        require(outputDir.exists()) { "Invalid output dir, must be pre-existing. ${outputDir.absolutePath}" }

        File(outputDir, "index.html").apply {
            if (exists()) delete()
            if (!createNewFile()) throw IllegalStateException("Unable to create new report index.html")
            writer().use {
                it.appendln("<!DOCTYPE html>")
                it.appendHTML().html {
                    attributes.put("class", "mdc-typography")
                    head {
                        meta { charset = "utf-8" }
                        meta { name = "viewport"; content = "width=device-width,initial-scale=1" }
                        title("Kontrast Report: $variantName")
                        link {
                            rel = "stylesheet"
                            href = "css/material-components-web.min.css"
                        }
                        link {
                            rel = "stylesheet"
                            href = "css/kontrast.css"
                        }
                    }
                    body {
                        style = "background-color: #f5f5f5;"
                        header("mdc-toolbar mdc-toolbar--fixed mdc-toolbar--waterfall") {
                            autoInit("MDCToolbar")
                            div("mdc-toolbar__row toolbar-row") {
                                section("mdc-toolbar__section mdc-toolbar__section--align-start") {
                                    span("mdc-toolbar__title") { text("Kontrast Test Report: $variantName - $deviceAlias") }
                                }
                                section("mdc-toolbar__section mdc-toolbar__section--align-end") {
                                    nav("mdc-tab-bar") {
                                        autoInit("MDCTabBar")
                                        span(classes = "mdc-tab mdc-tab--active AllTab") { text("All: ${testCases.size}") }

                                        val passedCount = testCases.filter { it.status == TestResult.ResultType.SUCCESS }.size
                                        span(classes = "mdc-tab PassedTab") { text("Passed: $passedCount") }

                                        val failedCount = testCases.filter { it.status == TestResult.ResultType.FAILURE }.size
                                        span(classes = "mdc-tab FailedTab") { text("Failed: $failedCount") }

                                        val skippedCount = testCases.filter { it.status == TestResult.ResultType.FAILURE }.size
                                        span(classes = "mdc-tab SkippedTab") { text("Skipped: $skippedCount") }<commit_msg>count the correct type for the html report skipped tab<commit_after>/*
 *    Copyright 2017 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.trevjonez.kontrast.report

import kotlinx.html.ScriptType
import kotlinx.html.Tag
import kotlinx.html.a
import kotlinx.html.body
import kotlinx.html.div
import kotlinx.html.h1
import kotlinx.html.h2
import kotlinx.html.h3
import kotlinx.html.head
import kotlinx.html.header
import kotlinx.html.html
import kotlinx.html.img
import kotlinx.html.link
import kotlinx.html.meta
import kotlinx.html.nav
import kotlinx.html.script
import kotlinx.html.section
import kotlinx.html.span
import kotlinx.html.stream.appendHTML
import kotlinx.html.style
import kotlinx.html.title
import org.gradle.api.tasks.testing.TestResult
import java.io.File

class ReportIndexHtml(val outputDir: File, val variantName: String, val deviceAlias: String, val testCases: List<TestCaseData>) : ReportFile {
    override fun write() {
        require(outputDir.exists()) { "Invalid output dir, must be pre-existing. ${outputDir.absolutePath}" }

        File(outputDir, "index.html").apply {
            if (exists()) delete()
            if (!createNewFile()) throw IllegalStateException("Unable to create new report index.html")
            writer().use {
                it.appendln("<!DOCTYPE html>")
                it.appendHTML().html {
                    attributes.put("class", "mdc-typography")
                    head {
                        meta { charset = "utf-8" }
                        meta { name = "viewport"; content = "width=device-width,initial-scale=1" }
                        title("Kontrast Report: $variantName")
                        link {
                            rel = "stylesheet"
                            href = "css/material-components-web.min.css"
                        }
                        link {
                            rel = "stylesheet"
                            href = "css/kontrast.css"
                        }
                    }
                    body {
                        style = "background-color: #f5f5f5;"
                        header("mdc-toolbar mdc-toolbar--fixed mdc-toolbar--waterfall") {
                            autoInit("MDCToolbar")
                            div("mdc-toolbar__row toolbar-row") {
                                section("mdc-toolbar__section mdc-toolbar__section--align-start") {
                                    span("mdc-toolbar__title") { text("Kontrast Test Report: $variantName - $deviceAlias") }
                                }
                                section("mdc-toolbar__section mdc-toolbar__section--align-end") {
                                    nav("mdc-tab-bar") {
                                        autoInit("MDCTabBar")
                                        span(classes = "mdc-tab mdc-tab--active AllTab") { text("All: ${testCases.size}") }

                                        val passedCount = testCases.filter { it.status == TestResult.ResultType.SUCCESS }.size
                                        span(classes = "mdc-tab PassedTab") { text("Passed: $passedCount") }

                                        val failedCount = testCases.filter { it.status == TestResult.ResultType.FAILURE }.size
                                        span(classes = "mdc-tab FailedTab") { text("Failed: $failedCount") }

                                        val skippedCount = testCases.filter { it.status == TestResult.ResultType.SKIPPED }.size
                                        span(classes = "mdc-tab SkippedTab") { text("Skipped: $skippedCount") }
{'fraction_non_alphanumeric': 0.09657657657657658, 'fraction_numerical': 0.0038438438438438438, 'mean_word_length': 1.6600638977635782, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6648958', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2120, 'n_words': 525}