<commit_before>{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-|
    Module      :  Numeric.AERN.RmToRn.Plot.FnView.WatchData
    Description :  dynamically respond to a change in the function data
    Copyright   :  (c) <NAME>
    License     :  BSD3

    Maintainer  :  <EMAIL>
    Stability   :  experimental
    Portability :  portable
    
    Internal module for FnView.
    Dynamically respond to a change in the function data. 
-}
module Numeric.AERN.RmToRn.Plot.FnView.WatchData
--(
--)
where

import Numeric.AERN.RmToRn.Plot.FnView.FnData
import Numeric.AERN.RmToRn.Plot.FnView.State
import Numeric.AERN.RmToRn.Plot.FnView.Layout

import Numeric.AERN.RmToRn.Plot.Params

import Numeric.AERN.RmToRn.Domain
import Numeric.AERN.RmToRn.Evaluation

import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut
--import Numeric.AERN.RealArithmetic.RefinementOrderRounding.OpsImplicitEffort

import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn

import qualified Numeric.AERN.RefinementOrder as RefOrd
--import Numeric.AERN.RefinementOrder.OpsImplicitEffort

import qualified Graphics.UI.Gtk as Gtk
import Graphics.UI.Gtk (AttrOp((:=)))

import qualified Control.Concurrent as Concurrent
import Control.Concurrent.STM -- as STM
import Data.IORef

dataWatchThread ::
    (ArithInOut.RoundedReal (Domain f),
     HasEvalOps f (Domain f),
     RefOrd.PartialComparison (Domain f),
     Show (Domain f))
    =>
    f ->
    ArithInOut.RoundedRealEffortIndicator (Domain f) ->
    EvalOpsEffortIndicator f (Domain f) ->
    Widgets ->
    IORef FnViewDynWidgets ->
    (TVar (FnData f),
     TVar (FnMetaData f)) ->
    (TVar (FnViewState f)) ->
    IO ()
dataWatchThread 
        (sampleF :: f)
        effReal effEval 
        widgets dynWidgetsRef fndataTVs@(fndataTV, fnmetaTV) stateTV =
    do
    fnmeta <- atomically $ readTVar fnmetaTV
    dataWatchLoop fnmeta
    where
    dataWatchLoop fnmetaOld =
        do
--        putStrLn "dataWatchLoop: start"
        ((dataChange, fndatas@(_, fnmeta)), state) <- waitForChange fnmetaOld<commit_msg>FnView now correctly shows values on startup<commit_after>{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-|
    Module      :  Numeric.AERN.RmToRn.Plot.FnView.WatchData
    Description :  dynamically respond to a change in the function data
    Copyright   :  (c) <NAME>
    License     :  BSD3

    Maintainer  :  <EMAIL>
    Stability   :  experimental
    Portability :  portable
    
    Internal module for FnView.
    Dynamically respond to a change in the function data. 
-}
module Numeric.AERN.RmToRn.Plot.FnView.WatchData
--(
--)
where

import Numeric.AERN.RmToRn.Plot.FnView.FnData
import Numeric.AERN.RmToRn.Plot.FnView.State
import Numeric.AERN.RmToRn.Plot.FnView.Layout

import Numeric.AERN.RmToRn.Plot.Params

import Numeric.AERN.RmToRn.Domain
import Numeric.AERN.RmToRn.Evaluation

import qualified Numeric.AERN.RealArithmetic.RefinementOrderRounding as ArithInOut
--import Numeric.AERN.RealArithmetic.RefinementOrderRounding.OpsImplicitEffort

import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn

import qualified Numeric.AERN.RefinementOrder as RefOrd
--import Numeric.AERN.RefinementOrder.OpsImplicitEffort

import qualified Graphics.UI.Gtk as Gtk
import Graphics.UI.Gtk (AttrOp((:=)))

import qualified Control.Concurrent as Concurrent
import Control.Concurrent.STM -- as STM
import Data.IORef

dataWatchThread ::
    (ArithInOut.RoundedReal (Domain f),
     HasEvalOps f (Domain f),
     RefOrd.PartialComparison (Domain f),
     Show (Domain f))
    =>
    f ->
    ArithInOut.RoundedRealEffortIndicator (Domain f) ->
    EvalOpsEffortIndicator f (Domain f) ->
    Widgets ->
    IORef FnViewDynWidgets ->
    (TVar (FnData f),
     TVar (FnMetaData f)) ->
    (TVar (FnViewState f)) ->
    IO ()
dataWatchThread 
        (sampleF :: f)
        effReal effEval 
        widgets dynWidgetsRef fndataTVs@(fndataTV, fnmetaTV) stateTV =
    do
    (fndatas@(_, fnmeta), state) <- atomically $ readAll3TVars fndataTVs stateTV
    -- initial update:
    action DataChangeMeta fndatas state
    -- enter watch loop:
    dataWatchLoop fnmeta
    where
    dataWatchLoop fnmetaOld =
        do
--        putStrLn "dataWatchLoop: start"
        ((dataChange, fndatas@(_, fnmeta)), state) <- waitForChange fnmetaOld
{'fraction_non_alphanumeric': 0.09485565443889733, 'fraction_numerical': 0.0006511829824180595, 'mean_word_length': 3.443587270973963, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2558702', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1594, 'n_words': 347}