Skip to content

Commit

Permalink
Don't need to version NumericSummary as it's included in ViewMarker
Browse files Browse the repository at this point in the history
  • Loading branch information
olorin committed Apr 5, 2016
1 parent b1bb58e commit 1ed6f0c
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions src/Warden/Serial/Json/Numeric.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@ import P

import Warden.Data.Numeric

data NumericSummaryVersion =
NumericSummaryV1
deriving (Eq, Show, Bounded, Enum)

currentNumericSummaryVersion :: NumericSummaryVersion
currentNumericSummaryVersion = maxBound

fromNumericSummaryVersion :: NumericSummaryVersion -> Value
fromNumericSummaryVersion NumericSummaryV1 = String "v1"

toNumericSummaryVersion :: Value -> Parser NumericSummaryVersion
toNumericSummaryVersion (String "v1") = pure NumericSummaryV1
toNumericSummaryVersion (String s) = fail . T.unpack $ "invalid NumericSummary version: " <> s
toNumericSummaryVersion x = typeMismatch "Warden.Serial.Json.Numeric.NumericSummaryVersion" x

fromNumericFieldSummary :: NumericFieldSummary -> Value
fromNumericFieldSummary NoNumericFieldSummary = object [
"type" .= String "no-numeric-field-summary"
Expand All @@ -59,12 +44,10 @@ toNumericFieldSummary x = typeMismatch "Warden.Data.Numeric.NumericFieldSummary"

fromNumericSummary :: NumericSummary -> Value
fromNumericSummary NoNumericSummary = object [
"version" .= fromNumericSummaryVersion currentNumericSummaryVersion
, "type" .= String "no-numeric-summary"
"type" .= String "no-numeric-summary"
]
fromNumericSummary (NumericSummary mn mx mean s md) = object [
"version" .= fromNumericSummaryVersion currentNumericSummaryVersion
, "type" .= String "numeric-summary"
"type" .= String "numeric-summary"
, "minimum" .= fromMinimum mn
, "maximum" .= fromMaximum mx
, "mean" .= fromMean mean
Expand All @@ -74,16 +57,15 @@ fromNumericSummary (NumericSummary mn mx mean s md) = object [

toNumericSummary :: Value -> Parser NumericSummary
toNumericSummary (Object o) =
(toNumericSummaryVersion =<< (o .: "version")) >>= \case
NumericSummaryV1 -> (o .: "type" :: Parser Text) >>= \case
"numeric-summary" -> NumericSummary
<$> (toMinimum =<< (o .: "minimum"))
<*> (toMaximum =<< (o .: "maximum"))
<*> (toMean =<< (o .: "mean"))
<*> (toStdDev =<< (o .: "stddev"))
<*> (toMedian =<< (o .: "median"))
"no-numeric-summary" -> pure NoNumericSummary
s -> fail . T.unpack $ "invalid NumericSummary type: " <> s
(o .: "type" :: Parser Text) >>= \case
"numeric-summary" -> NumericSummary
<$> (toMinimum =<< (o .: "minimum"))
<*> (toMaximum =<< (o .: "maximum"))
<*> (toMean =<< (o .: "mean"))
<*> (toStdDev =<< (o .: "stddev"))
<*> (toMedian =<< (o .: "median"))
"no-numeric-summary" -> pure NoNumericSummary
s -> fail . T.unpack $ "invalid NumericSummary type: " <> s
toNumericSummary x = typeMismatch "Warden.Data.Numeric.NumericSummary" x

fromMaximum :: Maximum -> Value
Expand Down

0 comments on commit 1ed6f0c

Please sign in to comment.