display scrapped share of NKIT
2 files changed, 52 insertions(+), 19 deletions(-)

M src/Main.elm
M src/Stats.elm
M src/Main.elm +35 -9
@@ 105,7 105,7 @@ update msg model =
 
             else
                 update (NextSteps (n - 1)) <| Tuple.first <| update (NextStep model.finishRound) model
-                
+
         Step s ->
             case s of
                 S0 ->

          
@@ 120,9 120,18 @@ update msg model =
 
                 S2 ->
                     -- S2 does S3
-                    let f = conditionalScrap model.scrapLimit >> justDoneToDone >> wipToJustDone model.round in
-                    ( chain <| applyStep model.kitForNkit ( Just f,
-                                           Just f) model, Cmd.none )
+                    let
+                        f =
+                            conditionalScrap model.scrapLimit >> justDoneToDone >> wipToJustDone model.round
+                    in
+                    ( chain <|
+                        applyStep model.kitForNkit
+                            ( Just f
+                            , Just f
+                            )
+                            model
+                    , Cmd.none
+                    )
 
                 -- FIXME: updatewaiting moves justDone to Done, which it shouldn't
                 S3 ->

          
@@ 193,7 202,7 @@ update msg model =
                 defaultToCurrentModel <| Maybe.map (\y -> applyStep model.kitForNkit ( Just <| identifyScrap y, Just <| identifyScrap y ) <| { model | scrapLimit = Just y }) <| validIntInput 0 500 x
 
         SwapKITForNKIT ->
-            ( { model | kitForNkit = not model.kitForNkit}, Cmd.none )
+            ( { model | kitForNkit = not model.kitForNkit }, Cmd.none )
 
         SwapAutoPlay ->
             ( { model | autoPlay = not model.autoPlay }, Cmd.none )

          
@@ 362,6 371,24 @@ view model =
         scrapLimitInterface =
             interface2 (String.fromInt <| Maybe.withDefault 0 model.scrapLimit) (Maybe.Extra.isNothing model.scrapLimit) [ text "scrap after", text "rounds" ] ChangedScrapLimit (text "rounds")
 
+        scrapShare =
+            case model.scrapLimit of
+                Nothing ->
+                    Element.none
+
+                Just _ ->
+                    let
+                        all =
+                            getAll model.nkit
+
+                        scrapped =
+                            List.filter (.conditions >> .scrapped) all
+
+                        share =
+                            (\x -> x * 100) <| safeDiv (toFloat <| List.length scrapped) (toFloat <| List.length all)
+                    in
+                    column [ width fill, height fill, spacing 5 ] [ text <| String.fromFloat share ++ "% of jobs", text "in NKIT scrapped" ]
+
         batchButtons =
             let
                 bButton n =

          
@@ 439,16 466,16 @@ view model =
 
         playInterface =
             row [ spacing 10, padding 13, Font.size 12, width fill ]
-                [ column [width fill, height fill, spacing 7] [autoPlayer, kitForNkit]
+                [ column [ width fill, height fill, spacing 7 ] [ autoPlayer, kitForNkit ]
                 , reworkProbInterface
-                , scrapLimitInterface
+                , column [ width fill, height fill, spacing 5 ] [ scrapLimitInterface, scrapShare ]
 
                 --, stopThresholds
                 ]
 
         kitForNkit =
             row [ Font.size 12, spacing 10, width fill ]
-                [ column [ spacing 5, Border.width 1, padding 5 ] [ text "KIT4NKIT", swapKITForNKITButton]
+                [ column [ spacing 5, Border.width 1, padding 5 ] [ text "KIT4NKIT", swapKITForNKITButton ]
                 ]
 
         autoPlayer =

          
@@ 456,7 483,6 @@ view model =
                 [ column [ spacing 5, Border.width 1, padding 5 ] [ text "AutoPlay", autoPlayButton ]
                 ]
 
-
         --lower =
         --    row [ spacing 20, width fill, height fill ] [ viewField squareSizeUndone squareSizeDone model.nkit "NKIT", viewField squareSizeUndone squareSizeDone model.kit "KIT" ]
         netWidth =

          
M src/Stats.elm +17 -10
@@ 65,26 65,33 @@ countDones n f =
             getAll f
 
 
+safeDiv : Float -> Float -> Float
+safeDiv x y =
+    if y == 0 then
+        0
+
+    else
+        x / y
+
+
 createDataPoint : Round -> Field -> Field -> DoneData
 createDataPoint r kit nkit =
     let
         flowtimes =
             List.filterMap flowTime
 
-        safeDiv x y =
-            if y == 0 then
-                0
-
-            else
-                x / y
-
         reworkShare xs =
             safeDiv (100 * (toFloat <| List.length <| List.filter (\x -> x.conditions.rework /= NoRework) xs)) (toFloat <| List.length xs)
 
         interruptedShare field =
-            let totalNumber = List.length field.w0
-                interrupted = List.length <| List.filter (\x -> x.conditions.interruptedProcessing) field.w0
-             in (\x -> 100 * x) <| safeDiv (toFloat interrupted) (toFloat totalNumber)
+            let
+                totalNumber =
+                    List.length field.w0
+
+                interrupted =
+                    List.length <| List.filter (\x -> x.conditions.interruptedProcessing) field.w0
+            in
+            (\x -> 100 * x) <| safeDiv (toFloat interrupted) (toFloat totalNumber)
 
         flowtimeG n xs =
             safeDiv (100 * (toFloat <| List.length <| List.filter (\x -> x > n) xs)) (toFloat <| List.length xs)