UMinho Haskell Libraries (1.0)ContentsIndex
Language.Sdf.Metrics.Halstead
Portability portable
Stability experimental
Maintainer Tiago Alves and Joost Visser
Contents
Representation
Function to calculate all metrics
Functions to separate Operators and Operands
Individual metric calculation functions
Auxiliary functions
Description
Halstead metrics for Sdf grammars, taken from: http://mdp.ivv.nasa.gov/halstead_metrics.html http://www.sei.cmu.edu/str/descriptions/halstead_body.html
Synopsis
data HalsteadMetrics = HalsteadMetrics {
u1 :: Int
u2 :: Int
n1 :: Int
n2 :: Int
pn :: Int
pN :: Int
pV :: Float
pD :: Float
pE :: Float
pL :: Float
pT :: Float
}
halsteadMetrics :: HalsteadMetrics -> GroupMetric
calcHalsteadMetrics :: SDF -> HalsteadMetrics
calcOperatorsAndOperands :: [Production] -> ([Int], [String])
sepOperatorsAndOperands :: Production -> [Either Int String]
sepOaOfromSymb :: Symbol -> [Either Int String]
sepOaOfromLstSymbs :: [Symbol] -> [Either Int String]
calcVolume :: Int -> Int -> Float
calcDifficulty :: Int -> Int -> Int -> Float
calcLevel :: Int -> Int -> Int -> Float
log2 :: Floating a => a -> a
Representation
data HalsteadMetrics
Data type to hold all metric results
Constructors
HalsteadMetrics
u1 :: IntNumber of Distinct Operators
u2 :: IntNumber of Distinct Operands
n1 :: IntTotal Number of Operators
n2 :: IntTotal Number of Operands
pn :: IntProgram Vocabulary (n = n1 + n2)
pN :: IntProgram Length (N = N1 + N2)
pV :: FloatProgram Volume (V = N * LOG2 n)
pD :: FloatProgram Difficulty (D = (n1/2) * (N2/n2))
pE :: FloatProgram Effort (E = D * V)
pL :: FloatProgram Level (L = (2/n1) * (n2/N2))
pT :: FloatProgramming Time (T = E/18)
halsteadMetrics :: HalsteadMetrics -> GroupMetric
Creates a uniform representation of the metrics converting the internal HalsteadMetrics record to a GroupMetric type which holds not only all the calculated metric values but also all information about the metrics: description and name.
Function to calculate all metrics
calcHalsteadMetrics :: SDF -> HalsteadMetrics
Calculates all Halstead metrics
Functions to separate Operators and Operands
calcOperatorsAndOperands :: [Production] -> ([Int], [String])
Calculates all operators and operands from a list of productions. Each operator will be represented by its key (an unique number) and for each operand its value (string) will be used.
sepOperatorsAndOperands :: Production -> [Either Int String]
Separate Operators and Operands from an SDF Production.
sepOaOfromSymb :: Symbol -> [Either Int String]
Separate Operators and Operands of an SDF Symbol by recursively transverse the Symbol data-type. For each operator returns its key (number) and for each operand returns its value.
sepOaOfromLstSymbs :: [Symbol] -> [Either Int String]
Separates the operators and operands from a list of symbols. This function counts the invisible concatenation operator and invokes the sepOaOfromSymb function to traverse the Symbol data type.
Individual metric calculation functions
calcVolume :: Int -> Int -> Float

Calculates the Halstead Program Volume Halstead Program Volume is calculated by the following formula:

 N * log2 nÊ

where

  • N = Program Length
  • n = Program Vocabulary
calcDifficulty :: Int -> Int -> Int -> Float

Calculates the Halstead Program Difficulty Halstead Program Difficulty is calculated by the following formula:

 (u1 / 2) * (n2 / u2) 

where

  • u1 = Number of Distinct Operators
  • u2 = Number of Distinct Operands
  • n2 = Total Number of Operands
calcLevel :: Int -> Int -> Int -> Float

Calculates the Halstead Program Level Halstead Program Level is calculated by the following formula:

 (2 / u1) * (u2 / n2)Ê

where

  • u1 = Number of Distinct Operators
  • u2 = Number of Distinct Operands
  • n2 = Total Number of Operands
Auxiliary functions
log2 :: Floating a => a -> a
Helper function that calculates the log2 of a floating point number
Produced by Haddock version 0.6