{-|
Module : ProgramLevelAnalysis
Description : Facade to the MetaModel aggregation functions
Copyright : Copyright (C) 2019 S. Kamps
License : -- This file is distributed under the terms of the Apache License 2.0.
For more information, see the file "LICENSE", which is included in the distribution.
Stability : experimental
-}
module ProgramLevelAnalysis
(calculateGiniCoefficient
,calculateCG
,calculateIvd
,calculateAverage
,calculateMedian
,calculateDistribution
,calculatePopulation
)
where
import qualified Data.Set as Set
import CsvData
import MetaHS.EDSL
import qualified MetaHS.DataModel.MetaModel as MetaModel
import MetaHS.Extensions.MacroLevelAggregation.GiniCoefficient
import MetaHS.Extensions.MacroLevelAggregation.Distribution
import MetaHS.Extensions.MacroLevelAggregation.Population
import MetaHS.Extensions.MacroLevelAggregation.Average
import MetaHS.Extensions.MacroLevelAggregation.Median
import MetaHS.Extensions.MacroLevelAggregation.IdealValueDeviation
import Settings (MetricType(LOC, LCOM, CBO))
-- | Calculate the Gini-coefficient of the metric values associated with the supplied metric Relation key
calculateGiniCoefficient :: String -- ^ The identifier associated with this analysis.
-> RelationKey -- ^ The MetaModel Relation Key (E.g., LCOM).
-> MetaModel.MetaModel -- ^ The MetaModel Containing the associated key.
-> MetricInfo -- ^ The result of aggregating metric values of supplied key
calculateGiniCoefficient id key mm = generateMetricInfo id key $ giniCoefficient key mm
-- | Calculate the complement of the Gini-coefficient of the metric values associated with the supplied metric Relation key
calculateCG :: String -- ^ The identifier associated with this analysis.
-> RelationKey -- ^ The MetaModel Relation Key (E.g., LCOM).
-> MetaModel.MetaModel -- ^ The MetaModel Containing the associated key.
-> MetricInfo -- ^ The result of aggregating metric values of supplied key
calculateCG id key mm = generateMetricInfo id key $ 1 - (giniCoefficient key mm)
-- | Calculate the Ideal Value Deviation of the metric values associated with the supplied metric Relation key
-- | Note, the idealValueDeviation's arguments are determined empirically
calculateIvd :: String -- ^ The identifier associated with this analysis.
-> MetricType -- ^ The MetaModel Relation Key (E.g., LCOM) expressed as MetricType
-> MetaModel.MetaModel -- ^ The MetaModel Containing the associated key.
-> MetricInfo -- ^ The result of aggregating metric values of supplied key
calculateIvd id key@LOC mm = generateMetricInfo id (show key) $ idealValueDeviation (show key) mm (-15) 69 265
calculateIvd id key@CBO mm = generateMetricInfo id (show key) $ idealValueDeviation (show key) mm 0 6 16
calculateIvd id key@LCOM mm = generateMetricInfo id (show key) $ idealValueDeviation (show key) mm 0 1 11
-- | Calculate the average of the metric values associated with the supplied metric Relation key
calculateAverage :: String -- ^ The identifier associated with this analysis.
-> RelationKey -- ^ The MetaModel Relation Key (E.g., LCOM).
-> MetaModel.MetaModel -- ^ The MetaModel Containing the associated key.
-> MetricInfo -- ^ The result of aggregating metric values of supplied key
calculateAverage id key mm = generateMetricInfo id key $ average key mm
-- | Calculate the median of the metric values associated with the supplied metric Relation key
calculateMedian :: String -- ^ The identifier associated with this analysis.
-> RelationKey -- ^ The MetaModel Relation Key (E.g., LCOM).
-> MetaModel.MetaModel -- ^ The MetaModel Containing the associated key.
-> MetricInfo -- ^ The result of aggregating metric values of supplied key
calculateMedian id key mm = generateMetricInfo id key $ median key mm
-- | Calculate the distribution of the metric values associated with the supplied metric Relation key
calculateDistribution :: String -- ^ The identifier associated with this analysis.
-> RelationKey -- ^ The MetaModel Relation Key (E.g., LCOM).
-> MetaModel.MetaModel -- ^ The MetaModel Containing the associated key.
-> Set.Set (Int, Int) -- ^ The set containing tuple(s) (MetricValue,Frequency)
calculateDistribution id = distribution
-- | Calculate the population of the metric values associated with the supplied metric Relation key
calculatePopulation :: String -- ^ The identifier associated with this analysis.
-> RelationKey -- ^ The MetaModel Relation Key (E.g., LCOM).
-> MetaModel.MetaModel -- ^ The MetaModel Containing the associated key.
-> [Int] -- ^ The list containing MetricValues
calculatePopulation id = population
-- | helper function
generateMetricInfo :: String
-> RelationKey
-> Double
-> MetricInfo
generateMetricInfo i k v =
MetricInfo {
identifier = i
,relationKey = k
,value = v
}