Doug Burke avatar Doug Burke committed d69cfc8

Minor internal clean up

Comments (0)

Files changed (1)

GetUserConnections.hs

 
 Usage:
 
-  ./getuserconnections <infile1> .. <infileN>
-  ./getuserconnections csv <infile1> .. <infileN>
-  ./getuserconnections json <infile1> .. <infileN>
-  ./getuserconnections sif <infile1> .. <infileN>
+  ./getuserconnections <endpoint>
+  ./getuserconnections csv <endpoint>
+  ./getuserconnections json <endpoint>
+  ./getuserconnections sif <endpoint>
 
 Aim:
 
            ]
 
 type UserMap = HM.HashMap UserId UserInfo
-type UserConn = (UserInfo, UserInfo, Int, Int)             
-  -- The last two arguments are the number of tweets (including retweets)
-  -- and the number of retweets
+
+data UserConn = 
+    UC
+    { ucFrom      :: UserInfo  -- ^ Account that wrote the tweets
+    , ucTo        :: UserInfo  -- ^ Account that was mentioned
+    , ucNTweets   :: Int       -- ^ Number of all tweets
+    , ucNRetweets :: Int       -- ^ Number of retweets
+    } deriving (Eq, Show)
 
 makeUserMap :: 
     M.Map UserId BasicUserInfo 
 -- could easily make this return Maybe UserConn instead but for now
 -- just let it error out
 toUserConn :: UserMap -> (UserId, UserId, Int, Int) -> UserConn
-toUserConn um (cid, pid, nt, nrt) = (toUserInfo um cid, toUserInfo um pid, nt, nrt)
+toUserConn um (cid, pid, nt, nrt) = UC (toUserInfo um cid) (toUserInfo um pid) nt nrt
 
 toUserInfo :: UserMap -> UserId -> UserInfo
 toUserInfo um uid =
 -}
 displayJSON :: ([UserConn], (UTCTime, UTCTime)) -> IO ()
 displayJSON (us, ts) = 
-  let uSet = foldl' (\s1 (ua, ub, _, _) -> S.insert ub (S.insert ua s1)) S.empty us
+  let uSet = foldl' (\s1 UC {..} -> S.insert ucTo (S.insert ucFrom s1)) S.empty us
       users = S.toList uSet
       uMap = zip users [0::Int ..]
   
       getUserIndex = fromJust . flip lookup uMap
-      mkLink (ua, ub, nt, nrt) = 
-        object [ "source"  .= getUserIndex ua
-               , "target"  .= getUserIndex ub
-               , "ntweets" .= nt
-               , "nretweets" .= nrt
+      mkLink UC {..} = 
+        object [ "source"  .= getUserIndex ucFrom
+               , "target"  .= getUserIndex ucTo
+               , "ntweets" .= ucNTweets
+               , "nretweets" .= ucNRetweets
                ]
         
       j = encode $ object 
 -}
 displayCSV :: ([UserConn], a) -> IO ()
 displayCSV = 
-  let asCSV (c, r, nt, _) = T.unpack (getCSVLabel c) ++ "," ++ T.unpack (getCSVLabel r) ++ ";" ++ show nt
+  let asCSV UC {..} = T.unpack (getCSVLabel ucFrom) ++ "," ++ T.unpack (getCSVLabel ucTo) ++ ";" ++ show ucNTweets
   in mapM_ (putStrLn . asCSV) . fst
   
 displaySIF :: ([UserConn], a) -> IO ()
 displaySIF = 
-  let asSIF (c, r, nt, _) = T.unpack (getCSVLabel c) ++ "\t" ++ show nt ++ "\t" ++ T.unpack (getCSVLabel r)
+  let asSIF UC {..} = T.unpack (getCSVLabel ucFrom) ++ "\t" ++ show ucNTweets ++ "\t" ++ T.unpack (getCSVLabel ucTo)
   in mapM_ (putStrLn . asSIF) . fst
   
 {-
 Just dump the output.
 -}
 displayDebug :: ([UserConn], a) -> IO ()
-displayDebug (us, _) = mapM_ print us
+displayDebug = mapM_ print . fst
 
 usage :: IO ()
 usage = do
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.