1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-23 12:52:31 +03:00

Make code that shows visitors a bit better

This commit is contained in:
Artyom 2017-07-10 01:08:55 +03:00
parent 2998f9def8
commit 5956158a73
No known key found for this signature in database
GPG Key ID: B8E35A33FF522710

View File

@ -269,22 +269,21 @@ renderStats globalState acts = do
th_ "Unique visitors"
tbody_ $ do
let rawVisits :: [(Url, Maybe IP)]
rawVisits = [(r, actionIP d) |
(_, d) <- acts',
Just (ExternalReferrer r) <- [actionReferrer d]]
rawVisits = [(r, actionIP d)
| d <- map snd acts'
, Just (ExternalReferrer r) <- [actionReferrer d]]
let sortRefs :: [(Url, Maybe IP)] -> [(ReferrerView, [Maybe IP])]
sortRefs = map (fst.head &&& map snd)
. groupBy ((==) `on` fst)
. sortBy (comparing fst)
. groupWith fst
. map (over _1 toReferrerView)
let visits :: [(ReferrerView, (Int, Int))]
visits = map (over _2 (length &&& length.ordNub))
. sortRefs $ rawVisits
(sortRefs rawVisits)
for_ (reverse $ sortWith (fst.snd) visits) $ \(r, (n, u)) -> do
tr_ $ do
td_ (toHtml $ show r)
td_ (toHtml (show n))
td_ (toHtml (show u))
td_ (toHtml (show r)) -- referrer
td_ (toHtml (show n)) -- visitors
td_ (toHtml (show u)) -- unique visitors
table_ $ do
thead_ $ tr_ $ do
th_ "Action"