<commit_before>module Analyzer 
  ( printRecommendationFromAnalysis,
    analyze) where

import Defs.Structures
import Defs.Common
import Defs.AST

import Recommend

import Data.List
import Control.Arrow
import Control.Monad.State

-- | Data structure analysis info type
data DSInfo =   DSI { getDSIVarName :: Name,    -- ^ Variable holding the data structure
                    isStatic :: Bool,           -- ^ Is the variable static or dynamic
                    getUses :: [DSUse]          -- ^ Data structure use cases
                    } deriving (Show, Eq)

-- | Data structure use case type
data DSUse =    DSU { getDSUOpName :: OperationName,-- ^ Operation used
                    isHeavilyUsed :: Bool,          -- ^ Is it heavily used
                    isUserDependent :: Bool         -- ^ Is it dependent on some external input (user, network, random, signals, etc.)
                    } deriving (Show, Eq)

-- | List of pairs: variable name, use case
type AnalyzerOutput = [(Name, DSUse)]

-- | State monad with 'Context' state returning 'AnalyzerOutput'
type Analyzer = State [Name] AnalyzerOutput

-- | Analyzer context containing variable names with data structures
type Context = [Name]

setHeavyUsage (DSU opname _ ud) = DSU opname True ud
setUserDependance (DSU opname hu _) = DSU opname hu True

-- | Pretty printer for the analyzer effects
printRecommendationFromAnalysis :: [DSInfo] -> IO()
printRecommendationFromAnalysis = mapM_ printDSI 

-- | Pretty print single 'DSInfo' 
printDSI dsi = do
    putStr "The recommended structure for "
    redColor
    putStr $ getDSIVarName dsi
    resetColor 
    putStrLn " is:"
    cyanColor
    recommendedDS >>= print
    resetColor where
        recommendedDS = do 
            let opns = map getDSUOpName $ getUses dsi
            recommendDS opns

-- | Run the analyzer
analyze :: [Term] -> [DSInfo]
analyze = generateDSI . generateDSU 
<commit_msg>missing types for a function, crashing docu<commit_after>module Analyzer 
  ( printRecommendationFromAnalysis,
    analyze) where

import Defs.Structures
import Defs.Common
import Defs.AST

import Recommend

import Data.List
import Control.Arrow
import Control.Monad.State

-- | Data structure analysis info type
data DSInfo =   DSI { getDSIVarName :: Name,    -- ^ Variable holding the data structure
                    isStatic :: Bool,           -- ^ Is the variable static or dynamic
                    getUses :: [DSUse]          -- ^ Data structure use cases
                    } deriving (Show, Eq)

-- | Data structure use case type
data DSUse =    DSU { getDSUOpName :: OperationName,-- ^ Operation used
                    isHeavilyUsed :: Bool,          -- ^ Is it heavily used
                    isUserDependent :: Bool         -- ^ Is it dependent on some external input (user, network, random, signals, etc.)
                    } deriving (Show, Eq)

-- | List of pairs: variable name, use case
type AnalyzerOutput = [(Name, DSUse)]

-- | State monad with 'Context' state returning 'AnalyzerOutput'
type Analyzer = State [Name] AnalyzerOutput

-- | Analyzer context containing variable names with data structures
type Context = [Name]

setHeavyUsage (DSU opname _ ud) = DSU opname True ud
setUserDependance (DSU opname hu _) = DSU opname hu True

-- | Pretty printer for the analyzer effects
printRecommendationFromAnalysis :: [DSInfo] -> IO()
printRecommendationFromAnalysis = mapM_ printDSI 

-- | Pretty print single 'DSInfo' 
printDSI :: DSInfo -> IO()
printDSI dsi = do
    putStr "The recommended structure for "
    redColor
    putStr $ getDSIVarName dsi
    resetColor 
    putStrLn " is:"
    cyanColor
    recommendedDS >>= print
    resetColor where
        recommendedDS = do 
            let opns = map getDSUOpName $ getUses dsi
            recommendDS opns

-- | Run the analyzer
analyze :: [Term] -> [DSInfo]
analyze = generateDSI . generateDSU 

{'fraction_non_alphanumeric': 0.07857691323265933, 'fraction_numerical': 0.0, 'mean_word_length': 2.5495004541326067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '7093773', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1077, 'n_words': 391}