datarobot 1.0.0 → 1.0.1
raw patch · 3 files changed
+23/−8 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ DataRobot.PredictResponse: instance Data.Aeson.Types.FromJSON.FromJSON DataRobot.PredictResponse.ResponseData
+ DataRobot.PredictResponse: instance Data.Aeson.Types.ToJSON.ToJSON DataRobot.PredictResponse.PredictError
+ DataRobot.PredictResponse: instance Data.Aeson.Types.ToJSON.ToJSON DataRobot.PredictResponse.PredictResult
+ DataRobot.PredictResponse: instance Data.Aeson.Types.ToJSON.ToJSON DataRobot.PredictResponse.Prediction
+ DataRobot.PredictResponse: instance GHC.Classes.Eq DataRobot.PredictResponse.ResponseData
+ DataRobot.PredictResponse: instance GHC.Generics.Generic DataRobot.PredictResponse.PredictError
+ DataRobot.PredictResponse: instance GHC.Show.Show DataRobot.PredictResponse.ResponseData
Files
- datarobot.cabal +2/−2
- src/DataRobot/Features.hs +1/−1
- src/DataRobot/PredictResponse.hs +20/−5
datarobot.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: d659e0f40eb6ebe5c04a98ee4a259744bfffb63a3269437ce8661118f03926d4+-- hash: 952473bd73e967bd6225f0b1214d3649bf6b30e1abe118841ce2607df23a4b35 name: datarobot-version: 1.0.0+version: 1.0.1 synopsis: Client for DataRobot API description: Client for DataRobot API homepage: https://github.com/orbital/datarobot-haskell#readme
src/DataRobot/Features.hs view
@@ -32,7 +32,7 @@ featuresEndpoint :: URI -> ProjectID -> ModelID -> String featuresEndpoint base (ProjectID pid) (ModelID mid) =- endpoint base ["projects", cs pid, "models", cs mid, "features"]+ endpoint base ["projects", cs pid, "models", cs mid, "features/"]
src/DataRobot/PredictResponse.hs view
@@ -8,6 +8,7 @@ , parseResponse , predictionValue ) where+import Control.Applicative ((<|>)) import Control.Monad.Catch (Exception) import Data.Aeson (FromJSON(..), ToJSON, Value(..), decode, defaultOptions, genericParseJSON, withObject, (.:), eitherDecode) import Data.Aeson.Types (Options(..), typeMismatch)@@ -33,9 +34,10 @@ data PredictError = APIError Code Text | MissingPrediction- deriving (Typeable, Show)+ deriving (Typeable, Show, Generic) instance Exception PredictError+instance ToJSON PredictError -- Datarobot successful response@@ -55,7 +57,15 @@ instance FromJSON ResponseFailure where parseJSON = genericParseJSON underscorePrefixOptions +-- Datarobot response+data ResponseData+ = ResponseData (Either ResponseFailure ResponseSuccess)+ deriving (Eq, Show) +instance FromJSON ResponseData where+ parseJSON v = ResponseData <$>+ ((Right <$> parseJSON v) <|> (Left <$> parseJSON v))+ -- A single prediction value data PredictionValue = PredictionValue { label :: Text@@ -82,6 +92,7 @@ , _predictionValues :: Maybe [PredictionValue] } deriving (Eq, Show, Generic) +instance ToJSON Prediction instance FromJSON Prediction where parseJSON = genericParseJSON underscorePrefixOptions @@ -94,10 +105,12 @@ , predictionValues :: Maybe [PredictionValue] } deriving (Show, Eq, Generic) +instance ToJSON PredictResult --- Create a result for a successful response-responseSuccess :: Float -> ResponseSuccess -> Either PredictError PredictResult-responseSuccess et rs =++-- Create a result for a data robot response+handleResponse :: Float -> ResponseData -> Either PredictError PredictResult+handleResponse et (ResponseData (Right rs)) = maybe (Left MissingPrediction) Right $ do p <- headMay (_data rs) pure PredictResult@@ -105,6 +118,8 @@ , predictionValues = _predictionValues p , predictionTimeMs = et }+handleResponse _ (ResponseData (Left err)) =+ responseFailure $ _message err -- Create a result for a failed response responseFailure :: Text -> Either PredictError PredictResult@@ -114,7 +129,7 @@ -- This is needed because some of the data is delivered in the body and some is delivered via headers parseResponse :: Response ByteString -> Either PredictError PredictResult parseResponse r = do- either (responseFailure . cs) (responseSuccess tm) $ eitherDecode b+ either (responseFailure . cs) (handleResponse tm) $ eitherDecode b where b = r ^. responseBody et = r ^. responseHeader "X-DataRobot-Execution-Time"