Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 93 lines (80 sloc) 5.116 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
import
{
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Vector as V
import GHC.Exts
import Network.URL
import Statistics.Quantile
import Statistics.Sample
}

{
data ResponseMetric = ResponseMetric {
                                       responseUrl :: URL, --The URL that generated the response
                                       timeInterval :: Integer, --The greatest time stamp in the interval
                                       responseMean :: Double, --The mean response time of interval
                                       responseMin :: Double, --The min response time of interval
                                       responseMax :: Double --The maximum response time of interval
                                       --percentile80th :: Double, --The 80th percentile of the cumulative intervals
                                       --percentile98th :: Double --The 98th percentile of the cumulative intervals
                                     } deriving (Show)
}

TYPE ResponseGroup = [Response]
TYPE ResponsesGroupedByTimeInterval = [ResponseGroup]
TYPE ResponseGroupsMappedByURL = MAP {URL} ResponsesGroupedByTimeInterval

ATTR ResponseGroupsMappedByURL [ || responseMetrics USE
                                 { (\a b -> a.resultingMetricList ++ b.resultingMetricList }
                                 { [] }
                                 : {[ResponseMetric]}
                               ]

SEM ResponseGroupsMappedByURL
 | Entry val.responseMetricAccumulator = []
         val.vectorAccumulator = V.empty
         val.responseGroupURL = @key
         lhs.responseMetrics = @val.resultingMetricList

ATTR ResponsesGroupedByTimeInterval [ vectorAccumulator : {V.Vector Double}
                                      responseGroupURL : {URL} |responseMetricAccumulator : {[ResponseMetric]} |
                                      resultingMetricList : {[ResponseMetric]}
                                    ]
    
SEM ResponsesGroupedByTimeInterval
  | Cons tl.responseMetricAccumulator = metric : @lhs.responseMetricAccumulator
                                           where metric = ResponseMetric @hd.responseGroupURL
                                                                         @hd.latestTimeStamp
                                                                         @hd.meanResponseTime
                                                                         @hd.minResponseTime
                                                                         @hd.maxResponseTime
                                                                        -- @hd.c80thPercentile
                                                                        -- @hd.c98thPercentile
       lhs.resultingMetricList = @tl.resultingMetricList
 | Nil lhs.resultingMetricList = @lhs.responseMetricAccumulator
                         

SEM ResponsesGroupedByTimeInterval -- Percentiles and mean calculation semantics
 | Cons --hd.c80thPercentile = _80thPercentile @loc.vector
        --hd.c98thPercentile = _98thPercentile @loc.vector
        hd.meanResponseTime = mean @hd.responseTimeVector
        tl.vectorAccumulator = @loc.vector
        loc.vector = @lhs.vectorAccumulator V.++ @hd.responseTimeVector

ATTR ResponseGroup [ | --c80thPercentile : Double
                          --c98thPercentile : Double
                          meanResponseTime : Double
                          responseGroupURL : URL -- Each response in the list has a common url
                        | latestTimeStamp USE { max } { error "empty list" } : Integer
                          minResponseTime USE { min } { error "empty list" } : Double
                          maxResponseTime USE { max } { error "empty list" } : Double
                          responseTimeVector USE {V.cons} { V.empty } : {V.Vector Double}
                       ]
  
SEM ResponseGroup
 | Cons lhs.minResponseTime = responseTime @hd
        lhs.maxResponseTime = responseTime @hd
        lhs.latestTimeStamp = timestamp @hd
        lhs.responseTimeVector = (V.singleton $ responseTime @hd)
{
_80thPercentile = weightedAvg 80 100
_98thPercentile = weightedAvg 98 100
  
mapResponsesToUrl :: [Response] -> M.Map URL [Response]
mapResponsesToUrl = foldr accumulateMap M.empty
  where
    accumulateMap response acc = M.insertWith' (++) (url response) [response] acc

groupResponseMapByTimeInterval :: Integer -> M.Map URL [Response] -> M.Map URL [[Response]]
groupResponseMapByTimeInterval interval = M.map (groupWith timestampGroupCriteria)
  where
    timestampGroupCriteria response = (timestamp response) `quot` interval
        
Something went wrong with that request. Please try again.