Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitsutoshi Aoe committed Apr 16, 2014
2 parents 0a3d07d + 10b7f31 commit a5509f0
Show file tree
Hide file tree
Showing 15 changed files with 798 additions and 193 deletions.
1 change: 1 addition & 0 deletions .ghci
@@ -0,0 +1 @@
:set -optP-include -optPdist/build/autogen/cabal_macros.h
25 changes: 17 additions & 8 deletions .travis.yml
Expand Up @@ -7,6 +7,7 @@
# release of a major GHC version. Setting HPVER implictly sets
# GHCVER. Omit lines with versions you don't need/want testing for.
env:
- GHCVER=7.8.2
- GHCVER=7.8.1
- GHCVER=7.6.3
- GHCVER=7.6.2
Expand All @@ -17,6 +18,10 @@ env:
- HPVER=2012.4.0.0
- HPVER=2012.2.0.0

matrix:
allow_failures:
- env: HPVER=2012.2.0.0

# Note: the distinction between `before_install` and `install` is not
# important.
before_install:
Expand Down Expand Up @@ -49,41 +54,45 @@ before_install:
- sudo add-apt-repository -y ppa:hvr/ghc
- sudo apt-get update
- sudo apt-get install cabal-install-1.18 ghc-$GHCVER
- export PATH=/opt/ghc/$GHCVER/bin:$PATH
- export PATH=/opt/ghc/$GHCVER/bin:~/.cabal/bin:$PATH
- wget http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb
- sudo dpkg -i influxdb_latest_amd64.deb

install:
- cabal-1.18 update
- cabal-1.18 install --only-dependencies --enable-tests --enable-benchmarks
- cabal-1.18 install --only-dependencies --enable-tests --enable-benchmarks -j
- cabal-1.18 install hpc-coveralls -j --avoid-reinstalls

# Here starts the actual work to be performed for the package under
# test; any command which exits with a non-zero exit code causes the
# build to fail.
script:
# -v2 provides useful information for debugging
- cabal-1.18 configure -fexamples --enable-tests --enable-benchmarks -v2
- cabal-1.18 configure -fexamples --enable-tests --enable-benchmarks --enable-library-coverage

# this builds all libraries and executables
# (including tests/benchmarks)
- cabal-1.18 build
- cabal-1.18 build -j

- cabal-1.18 test
- cabal-1.18 check
- run-cabal-test --cabal-name=cabal-1.18 --show-details=always
- cabal-1.18 run influx-random-points -- 10 10
- cabal-1.18 check

# tests that a source-distribution can be generated
- cabal-1.18 sdist

# check that the generated source-distribution can be built & installed
- export SRC_TGZ=$(cabal-1.18 info . | awk '{print $2 ".tar.gz";exit}') ;
cd dist/;
(cd dist/;
if [ -f "$SRC_TGZ" ]; then
cabal-1.18 install "$SRC_TGZ";
else
echo "expected '$SRC_TGZ' not found";
exit 1;
fi
fi)

after_script:
- hpc-coveralls test-suite

notifications:
webhooks:
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,16 @@
## v0.2.0 - 2014-04-16

* Add more `FromValue` instances
* Add `(.:?)` and `(.!=)`
* Add `deriveSeriesData` and some variants
* Add left folds for `Stream` type

## v0.1.0.1 - 2014-04-07

* Support for older aeson
* Textual paramters in some functions for convenience
* A lot of bug fixes

## v0.0.0 - 2014-04-03

* Initial release
3 changes: 2 additions & 1 deletion README.md
@@ -1,6 +1,7 @@
Haskell client library for InfluxDB
==========
[![Build Status](https://travis-ci.org/maoe/influxdb-haskell.svg?branch=master)](https://travis-ci.org/maoe/influxdb-haskell)
[![Build Status](https://travis-ci.org/maoe/influxdb-haskell.svg?branch=develop)](https://travis-ci.org/maoe/influxdb-haskell?branch=develop)
[![Coverage Status](https://coveralls.io/repos/maoe/influxdb-haskell/badge.png?branch=develop)](https://coveralls.io/r/maoe/influxdb-haskell?branch=develop)
[![Gitter chat](https://badges.gitter.im/maoe/influxdb-haskell.png)](https://gitter.im/maoe/influxdb-haskell)

Contact information
Expand Down
80 changes: 42 additions & 38 deletions examples/random-points.hs
Expand Up @@ -3,7 +3,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Applicative
import Control.Exception as E
import Control.Monad
Expand All @@ -13,13 +13,14 @@ import Data.Time.Clock.POSIX
import System.Environment
import System.IO
import qualified Data.Text as T
import qualified Data.Vector as V

import System.Random.MWC (Variate(..))
import qualified Network.HTTP.Client as HC
import qualified System.Random.MWC as MWC

import Database.InfluxDB
import Database.InfluxDB.TH
import qualified Database.InfluxDB.Stream as S

oneWeekInSeconds :: Int
oneWeekInSeconds = 7*24*60*60
Expand All @@ -28,72 +29,74 @@ main :: IO ()
main = do
[read -> (numPoints :: Int), read -> (batches :: Int)] <- getArgs
hSetBuffering stdout NoBuffering
config <- newConfig
HC.withManager managerSettings $ \manager -> do
dropDatabase config manager (Database "ctx" Nothing)
config <- newConfig manager

let db = "ctx"
dropDatabase config db
`E.catch`
-- Ignore exceptions here
\(_ :: HC.HttpException) -> return ()
db <- createDatabase config manager "ctx"
createDatabase config "ctx"
gen <- MWC.create
flip fix batches $ \outerLoop !m -> when (m > 0) $ do
postWithPrecision config manager db SecondsPrecision $ withSeries "ct1" $
postWithPrecision config db SecondsPrecision $ withSeries "ct1" $
flip fix numPoints $ \innerLoop !n -> when (n > 0) $ do
!timestamp <- liftIO $ (-)
<$> getPOSIXTime
<*> (fromIntegral <$> uniformR (0, oneWeekInSeconds) gen)
!value <- liftIO $ uniform gen
writePoints $ Point value timestamp
writePoints $ Point value (Time timestamp)
innerLoop $ n - 1
outerLoop $ m - 1

result <- query config manager db "select count(value) from ct1;"
result <- query config db "select count(value) from ct1;"
case result of
[] -> putStrLn "Empty series"
series:_ -> do
print $ seriesColumns series
print $ seriesPoints series
-- Streaming output
queryChunked config manager db "select * from ct1;" $ \stream0 ->
flip fix stream0 $ \loop stream -> case stream of
Done -> return ()
Yield series next -> do
case fromSeriesData series of
Left reason -> hPutStrLn stderr reason
Right points -> mapM_ print (points :: [Point])
putStrLn "--"
stream' <- next
loop stream'

newConfig :: IO Config
newConfig = do
queryChunked config db "select * from ct1;" $ S.fold step ()
where
step _ series = do
case fromSeriesData series of
Left reason -> hPutStrLn stderr reason
Right points -> mapM_ print (points :: [Point])
putStrLn "--"

newConfig :: HC.Manager -> IO Config
newConfig manager = do
pool <- newServerPool localServer [] -- no backup servers
return Config
{ configCreds = rootCreds
, configServerPool = pool
, configHttpManager = manager
}

managerSettings :: HC.ManagerSettings
managerSettings = HC.defaultManagerSettings
{ HC.managerResponseTimeout = Just $ 60*(10 :: Int)^(6 :: Int)
}

data Point = Point !Name !POSIXTime deriving Show
data Point = Point
{ pointValue :: !Name
, pointTime :: !Time
} deriving Show

instance ToSeriesData Point where
toSeriesColumns _ = V.fromList ["value", "time"]
toSeriesPoints (Point value time) = V.fromList
[ toValue value
, epochInSeconds time
]
newtype Time = Time POSIXTime
deriving Show

instance FromSeriesData Point where
parseSeriesData = withValues $ \values -> Point
<$> values .: "value"
<*> values .: "time"
instance ToValue Time where
toValue (Time epoch) = toValue $ epochInSeconds epoch
where
epochInSeconds :: POSIXTime -> Value
epochInSeconds = Int . floor

epochInSeconds :: POSIXTime -> Value
epochInSeconds = Int . floor
instance FromValue Time where
parseValue (Int n) = return $ Time $ fromIntegral n
parseValue (Float d) = return $ Time $ realToFrac d
parseValue v = typeMismatch "Int or Float" v

data Name
= Foo
Expand Down Expand Up @@ -126,7 +129,8 @@ instance Variate Name where
name <- uniformR (fromEnum lower, fromEnum upper) g
return $! toEnum name

instance FromValue POSIXTime where
parseValue (Int n) = return $ fromIntegral n
parseValue (Float d) = return $ realToFrac d
parseValue v = typeMismatch "Int or Float" v
-- Instance deriving

deriveSeriesData defaultOptions
{ fieldLabelModifier = stripPrefixLower "point" }
''Point
29 changes: 25 additions & 4 deletions influxdb.cabal
@@ -1,5 +1,5 @@
name: influxdb
version: 0.0.0
version: 0.2.0
synopsis: Haskell client library for InfluxDB
description: Haskell client library for InfluxDB
homepage: https://github.com/maoe/influxdb-haskell
Expand All @@ -13,7 +13,9 @@ build-type: Simple
cabal-version: >= 1.10

flag examples
description: Build examples
default: False
manual: True

library
exposed-modules:
Expand All @@ -26,12 +28,13 @@ library
-- Database.InfluxDB.Query
Database.InfluxDB.Stream
Database.InfluxDB.Types
Database.InfluxDB.TH
other-modules:
Database.InfluxDB.Types.Internal
ghc-options: -Wall
build-depends:
base >= 4 && < 4.8
, aeson >= 0.7
, aeson >= 0.6.1.0
, attoparsec
, bytestring
, containers
Expand All @@ -44,12 +47,31 @@ library
, retry
, scientific
, tagged
, template-haskell
, text
, time
, vector
hs-source-dirs: src
default-language: Haskell2010

test-suite test-suite
type: exitcode-stdio-1.0
main-is: test-suite.hs
build-depends:
base
, http-client
, HUnit
, influxdb
, mtl
, tasty
, tasty-hunit
, tasty-quickcheck
, tasty-th
, text
, vector
hs-source-dirs: tests
default-language: Haskell2010

executable influx-random-points
if flag(examples)
buildable: True
Expand All @@ -67,7 +89,6 @@ executable influx-random-points
, mwc-random
, text
, time
, vector
default-language: Haskell2010

source-repository head
Expand All @@ -77,5 +98,5 @@ source-repository head

source-repository this
type: git
tag: v0.0.0
tag: v0.2.0
location: https://github.com/maoe/influxdb-haskell.git
2 changes: 1 addition & 1 deletion src/Database/InfluxDB.hs
Expand Up @@ -14,7 +14,7 @@ module Database.InfluxDB
, FromSeriesData(..), fromSeriesData
, FromValue(..), fromValue

, withValues, (.:)
, withValues, (.:), (.:?), (.!=)
, typeMismatch

-- * HTTP API
Expand Down

0 comments on commit a5509f0

Please sign in to comment.