Last active
August 29, 2015 14:05
-
-
Save eyenx/d385bde017b0c2dbbb92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Transformer | |
| -- Input Data: File with these example lines | |
| -- 2014-08-11T23:45:01;1407793501;214821;214821 | |
| -- 2014-08-11T23:50:01;1407793801;214887;214887 | |
| -- 2014-08-11T23:55:01;1407794101;214955;214955 | |
| -- | |
| -- Ouput Data: Array of Tuples of (Time2,Diff1,Diff2),(Time3,Diff2,Diff3) | |
| -- | |
| -- [(2014-08-11T23:50:01,300,66),(2014-08-11T23:55:01300,300,68)] | |
| -- | |
| import Data.List.Split (splitOn) | |
| import System.Environment | |
| -- filePath = "/tmp/dwn/data.csv" -- implemented as arg | |
| -- | |
| createTuple [] = ("",0,0) | |
| createTuple (x:y:z:_) = (x,read y :: Int,read z :: Int) | |
| arrayTuples c = [ createTuple x | x <- [ splitOn ";" x | x <- [ takeWhile (/='\r') x | x <- lines c ]]] | |
| aggrTuples [] = [] | |
| aggrTuples ((_,_,_):[]) = [] | |
| aggrTuples ((a1,b1,c1):(a2,b2,c2):r) = (a2, (b2 - b1), (c2-c1) ): (aggrTuples((a2,b2,c2):r)) | |
| -- do content <- readFile (String <- IO String) | |
| main = do | |
| [filePath] <- getArgs | |
| fileContent <- readFile filePath | |
| print $ aggrTuples $ arrayTuples fileContent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment