zampolit (empty) → 0.1
raw patch · 4 files changed
+194/−0 lines, 4 filesdep +HSHdep +basedep +cmdargssetup-changed
Dependencies added: HSH, base, cmdargs, containers, directory, filepath, old-locale, parsec, time
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- Zampolit.hs +133/−0
- zampolit.cabal +29/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Brian Sniffen++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Brian Sniffen nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Zampolit.hs view
@@ -0,0 +1,133 @@+{-# Language DeriveDataTypeable #-}++module Main where++import HSH hiding (space)++import Text.Parsec+import Text.Parsec.Char+import Text.Parsec.String++import System.Console.CmdArgs+import System.FilePath (takeFileName)+import System.Directory (getCurrentDirectory)++import System.Locale+import System.IO+import Data.Time+import Data.Time.Format++import Data.Function+import Data.List+import Data.Map (Map,(!))+import qualified Data.Map as Map+import Data.Maybe++type Commit = String+type Author = String+type Date = UTCTime++data Cmd = Cmd {outfile :: FilePath,+ gameName :: String}+ deriving (Show,Data,Typeable)+ ++data CA = CA { commit :: Commit+ , date :: Date+ , author :: Author }++type Total = (Date,Author,Map Author Int)++foldNames "bts" = "brians"+foldNames a = a++parseCA :: Parser [CA]+parseCA = many1 $ do+ string "commit "+ c <- count 40 hexDigit+ newline+ string "Author: "+ a' <- many1 alphaNum+ let a = foldNames a'+ space+ between (char '<') (char '>') $ many (noneOf ">")+ newline+ string "Date: "+ d' <- many1 (noneOf "\n")+ let d = rTime d'+ newline+ return CA {commit = c, author = a, date = d}++rTime = readTime defaultTimeLocale "%a %b %e %T %Y %Z"+fTime = formatTime defaultTimeLocale "%s" -- "%m/%d/%y %I:%M:%S %P"++wc ca = do+ runIO $ "git checkout " ++ commit ca+ s <- run $ "find . -name \\*tex -print -o -name \\*txt -print" + -|- "xargs wc -w"+ -|- "tail -1" -|- "grep -o '[0-9]\\+'"+ return $ read s++runningTotals :: [Total] -> (Author,Date,Int) -> [Total]+runningTotals totals (author,date,wc) = (date,author,new):totals+ where+ new = Map.insertWith (+) author wc $ (\(a,b,c)->c) $ head totals++zeroTotals :: [Total]+zeroTotals = [(rTime "Tue Jun 1 00:00:00 2010 +0000","ekate",Map.empty)]++printHeader :: FilePath -> String -> [Author] -> IO ()+printHeader output title authors = + withFile (output ++ ".gnuplot") WriteMode (\h -> do+ hPutStrLn h "set xdata time"+ hPutStrLn h "set timefmt \"%s\""+ hPutStrLn h "set format x \"%m/%d\""+ hPutStrLn h "set terminal pdf size 10in,7.5in"+ hPutStrLn h $ "set output \"" ++ output ++ ".pdf\""+ hPutStrLn h "set xlabel \"date\""+ hPutStrLn h "set ylabel \"words\""+ hPutStrLn h $ "set title \"" ++ title ++ " word counts by author\""+ hPutStrLn h "set datafile missing \"?\""+ hPutStr h "plot "+ hPutStrLn h . intercalate ", " . map plotLine $ zip [2..] authors)+ where+ plotLine (n,a) = "'" ++ output ++ ".data' using 1:($" + ++ show n ++ ") title \"" ++ a ++ "\"" ++printRow :: Handle -> [Author] -> Total -> IO ()+printRow h authors (date,name,total) = do+ hPutStr h $ fTime date+ hPutStr h "\t"+ hPutStr h $ take before $ cycle "?\t"+ hPutStr h . show $ Map.findWithDefault 0 name total+ hPutStrLn h $ take after $ cycle "\t?"+ where+ i = fromJust $ elemIndex name authors+ before = 2*i+ after = 2*((length authors) - i)++main :: IO ()+main = do+ dir <- return . takeFileName =<< getCurrentDirectory+ let cmd = Cmd { outfile = def &= argPos 1 &= opt (dir ++ "-wc") &= typFile + , gameName = def &= argPos 0 &= opt dir &= typ "NAME"}+ &= program "zampolit"+ c <- cmdArgs cmd+ let title = gameName c+ output = outfile c+ cas <- run $ "git log" -|- "grep '^\\(commit\\|Auth\\|Date\\)'"+ case parse parseCA "" cas of + Left err -> print err+ Right cas -> do+ wcs <- mapM wc cas+ runIO $ "git checkout master"+ let totals = foldl runningTotals zeroTotals . reverse + . zip3 (map author cas) (map date cas) + . map (max 0) + $ zipWith (-) wcs (tail wcs ++ [head $ reverse wcs])+ (_,_,mp) = head totals+ authors = sortBy (\x y -> compare (mp ! y) (mp ! x)) $ Map.keys mp+ printHeader output title authors+ withFile (output ++ ".data") WriteMode (\h ->+ mapM_ (printRow h authors) $ reverse totals)+ runIO $ "gnuplot " ++ output ++ ".gnuplot"
+ zampolit.cabal view
@@ -0,0 +1,29 @@+Name: zampolit+Version: 0.1+Synopsis: A tool for checking how much work is done on group projects.+Description: Zampolit is a tool for checking how much work each contributor to a project is doing. It produces pretty graphs of word count per author. This is helpful when collaborating on projects that are mostly text, and do not necessarily break lines reliably or often.+License: BSD3+License-file: LICENSE+Author: Brian Sniffen+Maintainer: bts@alum.mit.edu+Homepage: https://github.com/briansniffen/zampolit+Copyright: Copyright (c) 2011 Brian Sniffen+Category: Text+Build-type: Simple+-- Extra-source-files: +Cabal-version: >=1.2+++Executable zampolit+ -- .hs or .lhs file containing the Main module.+ Main-is: Zampolit.hs+ + -- Packages needed in order to build this package.+ Build-depends: base<5,parsec,cmdargs,time,containers,old-locale,directory,filepath,HSH+ + -- Modules not exported by this package.+ -- Other-modules: + + -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+ -- Build-tools: +