DataIndex (empty) → 0.1.0
raw patch · 12 files changed
+331/−0 lines, 12 filesdep +DataIndexdep +basedep +criterionsetup-changed
Dependencies added: DataIndex, base, criterion, tasty, tasty-hspec
Files
- CHANGELOG.md +7/−0
- DataIndex.cabal +74/−0
- LICENSE.md +21/−0
- README.md +2/−0
- Setup.hs +7/−0
- benchmark/Main.hs +6/−0
- executable/Main.hs +45/−0
- library/Data/Index.hs +18/−0
- package.yaml +56/−0
- stack.yaml +66/−0
- test-suite/Main.hs +9/−0
- test-suite/Spec_addTime.hs +20/−0
+ CHANGELOG.md view
@@ -0,0 +1,7 @@+# Change log + +DataIndex uses [Semantic Versioning][]. +The change log is available through the [releases on GitHub][]. + +[Semantic Versioning]: http://semver.org/spec/v2.0.0.html +[releases on GitHub]: https://github.com/yuhangwang/DataIndex/releases
+ DataIndex.cabal view
@@ -0,0 +1,74 @@+-- This file has been generated from package.yaml by hpack version 0.14.0. +-- +-- see: https://github.com/sol/hpack + +name: DataIndex +version: 0.1.0 +synopsis: A package for adding index column to data files +description: DataIndex can add index column to data files +category: Data +homepage: https://github.com/yuhangwang/DataIndex#readme +bug-reports: https://github.com/yuhangwang/DataIndex/issues +maintainer: Yuhang(Steven) Wang +license: MIT +license-file: LICENSE.md +build-type: Simple +cabal-version: >= 1.10 + +extra-source-files: + CHANGELOG.md + LICENSE.md + package.yaml + README.md + stack.yaml + +source-repository head + type: git + location: https://github.com/yuhangwang/DataIndex + +library + hs-source-dirs: + library + ghc-options: -Wall + build-depends: + base + exposed-modules: + Data.Index + default-language: Haskell2010 + +executable DataIndex + main-is: Main.hs + hs-source-dirs: + executable + ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N + build-depends: + base >= 4 && < 5 + , DataIndex + default-language: Haskell2010 + +test-suite DataIndex-test-suite + type: exitcode-stdio-1.0 + main-is: Main.hs + hs-source-dirs: + test-suite + ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N + build-depends: + base + , DataIndex + , tasty + , tasty-hspec + other-modules: + Spec_addTime + default-language: Haskell2010 + +benchmark DataIndex-benchmarks + type: exitcode-stdio-1.0 + main-is: Main.hs + hs-source-dirs: + benchmark + ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N + build-depends: + base + , DataIndex + , criterion + default-language: Haskell2010
+ LICENSE.md view
@@ -0,0 +1,21 @@+MIT License + +Copyright (c) 2016 Steven(Yuhang) Wang + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.
+ README.md view
@@ -0,0 +1,2 @@+# DataIndex +A Haskell package for adding index columns to data files
+ Setup.hs view
@@ -0,0 +1,7 @@+-- This script is used to build and install your package. Typically you don't +-- need to change it. The Cabal documentation has more information about this +-- file: <https://www.haskell.org/cabal/users-guide/installing-packages.html>. +import qualified Distribution.Simple + +main :: IO () +main = Distribution.Simple.defaultMain
+ benchmark/Main.hs view
@@ -0,0 +1,6 @@+-- You can benchmark your code quickly and effectively with Criterion. See its +-- website for help: <http://www.serpentine.com/criterion/>. +import Criterion.Main + +main :: IO () +main = defaultMain [bench "const" (whnf const ())]
+ executable/Main.hs view
@@ -0,0 +1,45 @@+import Data.Index +import System.Environment +import System.Exit +import Data.List + +main :: IO () +main = do + args <- getArgs + exe args + +usage :: String +usage = "USAGE: DataIndex output.data input.dat" + +exe :: [String] -> IO () +exe [] = do + putStrLn usage + exitFailure + +exe [_] = do + putStrLn usage + exitFailure +exe [_,_] = do + putStrLn usage + exitFailure + +exe (output:input:time_unit:_) = do + content <- readFile input + let dat = loadData content + let unit = read time_unit :: Float + save output (addTime dat unit) + +loadData :: String -> [[Float]] +loadData content = fmap ((fmap read) . words) (lines content) + +array2str :: Show a => [[a]] -> String +array2str [] = "" +array2str array = aux array [] + where + aux :: Show a => [[a]] -> [String] -> String + aux [] accum = intercalate "\n" (reverse accum) + aux (x:xs) accum = aux xs ((unwords (map show x)):accum) + +save :: Show a => String -> [[a]] -> IO () +save output_file dat = do + writeFile output_file (array2str dat)
+ library/Data/Index.hs view
@@ -0,0 +1,18 @@+-- | Data.Index is a package for adding index column to data files +module Data.Index + ( hello + , addTime) where + +-- | say hello +hello :: String +hello = "Hello Data.Index!" + +-- | Add an time column +-- usage: addTime <data array> <time unit> +addTime :: Num a => [[a]] -> a -> [[a]] +addTime array time_unit = aux array time_unit [] + where + aux :: Num a => [[a]] -> a -> [[a]] -> [[a]] + aux [] _ accum = reverse accum + aux (x:xs) unit accum = aux xs unit ((i:x):accum) + where i = unit * (fromIntegral ((length accum) + 1))
+ package.yaml view
@@ -0,0 +1,56 @@+benchmarks: + DataIndex-benchmarks: + dependencies: + - base + - DataIndex + - criterion + ghc-options: + - -rtsopts + - -threaded + - -with-rtsopts=-N + main: Main.hs + source-dirs: benchmark +category: Data +description: DataIndex can add index column to data files +executables: + DataIndex: + dependencies: + - base >= 4 && < 5 + - DataIndex + ghc-options: + - -rtsopts + - -threaded + - -with-rtsopts=-N + main: Main.hs + source-dirs: executable +extra-source-files: +- CHANGELOG.md +- LICENSE.md +- package.yaml +- README.md +- stack.yaml +ghc-options: -Wall +github: yuhangwang/DataIndex +library: + dependencies: + - base + source-dirs: library +license: MIT +license-file: LICENSE.md +maintainer: Yuhang(Steven) Wang +name: DataIndex +synopsis: A package for adding index column to data files +tests: + DataIndex-test-suite: + dependencies: + - base + - DataIndex + - tasty + - tasty-hspec + ghc-options: + - -rtsopts + - -threaded + - -with-rtsopts=-N + main: Main.hs + source-dirs: test-suite +version: '0.1.0'
+ stack.yaml view
@@ -0,0 +1,66 @@+# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# http://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# resolver: ghcjs-0.1.0_ghc-7.10.2 +# resolver: +# name: custom-snapshot +# location: "./custom-snapshot.yaml" +resolver: lts-7.2 + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# - location: +# git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# extra-dep: true +# subdirs: +# - auto-update +# - wai +# +# A package marked 'extra-dep: true' will only be built if demanded by a +# non-dependency (i.e. a user package), and its test suites and benchmarks +# will not be run. This is useful for tweaking upstream packages. +packages: +- '.' +# Dependency packages to be pulled from upstream that are not in the resolver +# (e.g., acme-missiles-0.3) +extra-deps: [] + +# Override default flag values for local packages and extra-deps +flags: {} + +# Extra package databases containing global packages +extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=1.1" +# +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor
+ test-suite/Main.hs view
@@ -0,0 +1,9 @@+import qualified Test.Tasty +import Test.Tasty.Hspec +import Spec_addTime + +main :: IO () +main = do + test <- testSpec "addTime" test_addTime + Test.Tasty.defaultMain test +
+ test-suite/Spec_addTime.hs view
@@ -0,0 +1,20 @@+module Spec_addTime (test_addTime) where +import Data.Index +import Test.Tasty.Hspec + +test_addTime :: Spec +test_addTime = parallel $ do + it "addTime [] 1. should return []" $ do + (addTime [] (1.0::Double)) `shouldBe` [] + + it "addTime [[1],[2]] 1 should return [[1,1],[2,2]]" $ do + (addTime [[1],[2]] (1::Int)) `shouldBe` [[1,1],[2,2]] + + it "addTime [[1,10],[2,20]] 1 should return [[1,1,10],[2,2,20]]" $ do + (addTime [[1,10],[2,20]] (1::Int)) `shouldBe` [[1,1,10],[2,2,20]] + + it "addTime [[1],[2]] 2 should return [[2,1],[4,2]]" $ do + (addTime [[1],[2]] (2::Int)) `shouldBe` [[2,1],[4,2]] + + it "addTime [[1.0],[2.0]] 1 should return [[1.0,1.0],[2.0,2.0]]" $ do + (addTime [[1.0],[2.0]] (1.0::Float)) `shouldBe` [[1.0,1.0],[2.0,2.0]]