<commit_before>module Benchmark.Runner.InProgress exposing (Class, styles, view)

import Benchmark.Reporting as Reporting exposing (Report(..))
import Benchmark.Runner.Text as Text
import Benchmark.Status as Status exposing (Status)
import Color
import Element exposing (..)
import Element.Attributes exposing (..)
import Json.Encode as Encode
import Style exposing (..)
import Style.Color as Color
import Style.Font as Font
import Style.Shadow as Shadow
import Style.Sheet as Sheet


view : Report -> Element Class variation msg
view report =
    report
        |> progressBars []
        |> (::) (Text.hero TextClass "Benchmarks Running")
        |> column Unstyled []


progressBars : List String -> Report -> List (Element Class variation msg)
progressBars reversedParents report =
    case report of
        Single name status ->
            [ progressBar (List.reverse reversedParents) name status ]

        Series name statuses ->
            [ text "TODO" ]

        Group name reports ->
            reports
                |> List.map (progressBars (name :: reversedParents))
                |> List.concat


progressBar : List String -> String -> Status -> Element Class variation msg
progressBar parents name status =
    column Unstyled
        [ paddingTop 5 ]
        [ Text.path TextClass parents
        , row Box
            [ paddingXY 10 5, width (px 500) ]
            [ text name ]
            |> within
                [ if Status.progress status > 0 then
                    row Progress
                        [ paddingTop 5
                        , paddingBottom 5
                        , paddingLeft 10
                        , clip
                        , width
                            (status
                                |> Status.progress
                                |> (*) 100
                                |> percent
                            )

                        -- display as a progressbar for a11y
                        , attribute "role" "progressbar"
                        , attribute "aria-valuenow"
                            (status
                                |> Status.progress
                                |> (*) 100
                                |> floor
                                |> toString
                            )
                        , attribute "aria-valuemin" "0"
                        , attribute "aria-valuemax" "100"
                        ]
                        [ el Unstyled [ width (px 500) ] (text name) ]
                  else
                    empty
                ]
        ]



-- STYLES


type Class
    = Unstyled
    | Path
    | Box
    | Progress
    | TextClass Text.Class<commit_msg>:art: refactor<commit_after>module Benchmark.Runner.InProgress exposing (Class, styles, view)

import Benchmark.Reporting as Reporting exposing (Report(..))
import Benchmark.Runner.Text as Text
import Benchmark.Status as Status exposing (Status)
import Color
import Element exposing (..)
import Element.Attributes exposing (..)
import Json.Encode as Encode
import Style exposing (..)
import Style.Color as Color
import Style.Font as Font
import Style.Shadow as Shadow
import Style.Sheet as Sheet


view : Report -> Element Class variation msg
view report =
    report
        |> progressBars []
        |> (::) (Text.hero TextClass "Benchmarks Running")
        |> column Unstyled []


progressBars : List String -> Report -> List (Element Class variation msg)
progressBars reversedParents report =
    case report of
        Single name status ->
            [ progressBar (List.reverse reversedParents) name status ]

        Series name statuses ->
            [ text "TODO" ]

        Group name reports ->
            reports
                |> List.map (progressBars (name :: reversedParents))
                |> List.concat


progressBar : List String -> String -> Status -> Element Class variation msg
progressBar parents name status =
    column Unstyled
        [ paddingTop 5 ]
        [ Text.path TextClass parents
        , row Box
            [ paddingXY 10 5, width (px 500) ]
            [ caption name status ]
            |> within [ filledPortion name status ]
        ]


caption : String -> Status -> Element Class variation msg
caption name status =
    el Unstyled
        [ width (px 500) ]
        (text name)


filledPortion : String -> Status -> Element Class variation msg
filledPortion name status =
    if Status.progress status > 0 then
        el Progress
            [ paddingTop 5
            , paddingBottom 5
            , paddingLeft 10
            , clip
            , width
                (status
                    |> Status.progress
                    |> (*) 100
                    |> percent
                )

            -- display as a progressbar for a11y
            , attribute "role" "progressbar"
            , attribute "aria-valuenow"
                (status
                    |> Status.progress
                    |> (*) 100
                    |> floor
                    |> toString
                )
            , attribute "aria-valuemin" "0"
            , attribute "aria-valuemax" "100"
            ]
            (caption name status)
    else
        empty



-- STYLES


type Class
    = Unstyled
    | Path
    | Box
    | Progress
    | TextClass Text.Class
{'fraction_non_alphanumeric': 0.07554225878833208, 'fraction_numerical': 0.010097232610321616, 'mean_word_length': 1.3847525635309852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348125', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1215, 'n_words': 419}