Skip to content

Commit

Permalink
Render in CSV using cassava
Browse files Browse the repository at this point in the history
  • Loading branch information
fujimura committed Apr 19, 2024
1 parent 07742bd commit eddcc37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions git-freq.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ common dependencies
, text
, parsers
, trifecta
, cassava

executable git-freq
import: dependencies, default
Expand Down
10 changes: 6 additions & 4 deletions src/Git/Freq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
module Git.Freq where

import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Csv as Csv
import Data.List (sortBy)

Check warning on line 10 in src/Git/Freq.hs

View workflow job for this annotation

GitHub Actions / Build on GHC latest

The import of ‘Data.List’ is redundant

Check warning on line 10 in src/Git/Freq.hs

View workflow job for this annotation

GitHub Actions / Run test on GHC latest

The import of ‘Data.List’ is redundant
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Text.Trifecta.Parser as Parser
import qualified Text.Trifecta.Result as Parser

Expand Down Expand Up @@ -65,7 +65,9 @@ swap old new m = case Map.lookup old m of
render :: Result -> IO ()
render r = do
let r' = map f $ Map.toList r
mapM_ print r'
mapM_ render' r'
where
f :: (FileName, [Delta]) -> (FileName, Int, Int, Int)
f (fileName, ds) = (fileName, sum $ map added ds, sum $ map deleted ds, length ds)
f (fileName, ds) = (fileName, sum $ map added ds, sum $ map deleted ds, length ds)
render' :: (FileName, Int, Int, Int) -> IO ()
render' x = LBS.putStr $ Csv.encode [x]

0 comments on commit eddcc37

Please sign in to comment.