Find file
Fetching contributors…
Cannot retrieve contributors at this time
118 lines (83 sloc) 3.5 KB
{-# LANGUAGE OverloadedStrings #-}
module Y2016.M12.D09.Solution where
import Control.Arrow ((&&&))
import Data.Aeson
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Function (on)
import Data.List (sortBy)
import Data.Maybe (fromJust)
-- below imports available from 1HaskellADay git repository
import Control.Logic.Frege (adjoin)
import Control.Presentation (laxmi)
import Data.Twitter
-- import Graph.JSON.Cypher.Read.Tweets
So, there was this tweet:
RC Guerrilla @RCGuerrilla 29m29 minutes ago
#FF #Catholic @OnePeterFive @SteveSkojec @VaticanCricket @vatican_en @CrisisMag
@geophf @hanmariams @EyeOfTheTiber @theghissilent #Follow
Leading to the following response:
Math problem
Who is the most exclusive tweep below?
Who is the most profligate in their follow-backs?
What is the mean follow-back ratio?
So, including RCGuerrilla, tease out the follower/friend information from
each tweep and answer the above questions.
instance FromJSON User where
parseJSON (Object o) =
Tweep <$> o .: "screen_name" <*> o .: "name"
<*> o .: "location" <*> o .: "followers_count"
<*> o .: "friends_count" <*> o .: "profile_image_url"
readTweeps :: FilePath -> IO [User]
readTweeps = fmap (fromJust . decode) . BL.readFile
friendFollowerRatio :: User -> Rational
friendFollowerRatio =
uncurry (/) . adjoin fromIntegral . (following &&& followers)
The JSON for the tweeps I got from my twitter-app: twittercritter by running
the command:
geophf:twitter geophf$
php info.php screen_name "RCGuerrilla,geophf,OnePeterFire,SteveSkojec,
EyeOfTheTiber,theghissilent" > ff-count.json
and placed it in this directory as ff-count.json. Have fun!
*Y2016.M12.D09.Solution> readTweeps "Y2016/M12/D09/ff-count.json" ~> ffs
*Y2016.M12.D09.Solution> length ffs ~> 9 ... YAY!
n.b.: ' ... YAY!' is not part of the return value
*Y2016.M12.D09.Solution> friendFollowerRatio (head ffs) ~> 973 % 1013
yup, yup, yup.
So, we sort on the ratio to answer the first two questions:
*Y2016.M12.D09.Solution> let ans = map (screen &&& friendFollowerRatio) ffs
*Y2016.M12.D09.Solution> sortBy (compare `on` snd) ans ~>
[("vatican_en",83 % 12114),("EyeOfTheTiber",93 % 7283),
("CrisisMag",413 % 12303),("theghissilent",50 % 1279),
("VaticanCricket",77 % 542),("hanmariams",655 % 2428),
("SteveSkojec",447 % 1405),("geophf",137 % 173),("RCGuerrilla",973 % 1013)]
So, vatican_en is the least follow-backer and RCGuerrilla is the most.
The mean follow-back ratio is:
*Y2016.M12.D09.Solution Data.List Data.Function> sum (map snd it) / 9 ~>
32172262422529344404132517287 % 112460315642822738295206175420
*Y2016.M12.D09.Solution> laxmi 2 it ~> "0.28"
in human-readable form... so, let's see each follow-back ratio:
*Y2016.M12.D09.Solution> map (screen &&& laxmi 2 . friendFollowerRatio) ffs ~>
and, after storing (see sortBy espression, above):
*Y2016.M12.D09.Solution> mapM_ (\(a,b) -> putStrLn (a ++ (',':b))) it
What are other measures of 'impact of YOUR twitter brand'? Retention?
Number of likes numbers of tweets receive?