Add unique IP count to thread stats.

This commit is contained in:
ccd0 2014-11-09 12:48:45 -08:00
parent b09fadb744
commit f1dbda4b13
2 changed files with 16 additions and 9 deletions

View File

@ -2,25 +2,26 @@ ThreadStats =
init: -> init: ->
return if g.VIEW isnt 'thread' or !Conf['Thread Stats'] return if g.VIEW isnt 'thread' or !Conf['Thread Stats']
countHTML = <%= html('<span id="post-count">?</span> / <span id="file-count">?</span>') %> countHTML = <%= html('<span id="post-count">?</span> / <span id="file-count">?</span> / <span id="ip-count">?</span>') %>
countHTML = <%= html('&{countHTML} / <span id="page-count">?</span>') %> if Conf['Page Count in Stats'] countHTML = <%= html('&{countHTML} / <span id="page-count">?</span>') %> if Conf['Page Count in Stats']
if Conf['Updater and Stats in Header'] if Conf['Updater and Stats in Header']
@dialog = sc = $.el 'span', @dialog = sc = $.el 'span',
id: 'thread-stats' id: 'thread-stats'
title: 'Post Count / File Count' + (if Conf["Page Count in Stats"] then " / Page Count" else "") title: 'Post Count / File Count / IP Count' + (if Conf["Page Count in Stats"] then " / Page Count" else "")
$.extend sc, countHTML $.extend sc, countHTML
$.ready -> $.ready ->
Header.addShortcut sc Header.addShortcut sc
else else
@dialog = sc = UI.dialog 'thread-stats', 'bottom: 0px; right: 0px;', @dialog = sc = UI.dialog 'thread-stats', 'bottom: 0px; right: 0px;',
<%= html('<div class="move" title="Post Count / File Count${Conf["Page Count in Stats"] ? " / Page Count" : ""}">&{countHTML}</div>') %> <%= html('<div class="move" title="Post Count / File Count / IP Count${Conf["Page Count in Stats"] ? " / Page Count" : ""}">&{countHTML}</div>') %>
$.ready => $.ready =>
$.add d.body, sc $.add d.body, sc
@postCountEl = $ '#post-count', sc @postCountEl = $ '#post-count', sc
@fileCountEl = $ '#file-count', sc @fileCountEl = $ '#file-count', sc
@pageCountEl = $ '#page-count', sc @ipCountEl = $ '#ip-count', sc
@pageCountEl = $ '#page-count', sc
Thread.callbacks.push Thread.callbacks.push
name: 'Thread Stats' name: 'Thread Stats'
@ -33,25 +34,30 @@ ThreadStats =
postCount++ postCount++
fileCount++ if post.file fileCount++ if post.file
ThreadStats.lastPost = post.info.date if Conf["Page Count in Stats"] ThreadStats.lastPost = post.info.date if Conf["Page Count in Stats"]
for script in $$ 'script[type="text/javascript"]:not([src])', d.head
if m = script.textContent.match /\bvar unique_ips = (\d+);/
ipCount = +m[1]
break
ThreadStats.thread = @ ThreadStats.thread = @
ThreadStats.fetchPage() ThreadStats.fetchPage()
ThreadStats.update postCount, fileCount ThreadStats.update postCount, fileCount, ipCount
$.on d, 'ThreadUpdate', ThreadStats.onUpdate $.on d, 'ThreadUpdate', ThreadStats.onUpdate
onUpdate: (e) -> onUpdate: (e) ->
return if e.detail[404] return if e.detail[404]
{postCount, fileCount, newPosts} = e.detail {postCount, fileCount, ipCount, newPosts} = e.detail
ThreadStats.update postCount, fileCount ThreadStats.update postCount, fileCount, ipCount
return unless Conf["Page Count in Stats"] return unless Conf["Page Count in Stats"]
if newPosts.length if newPosts.length
ThreadStats.lastPost = g.posts[newPosts[newPosts.length - 1]].info.date ThreadStats.lastPost = g.posts[newPosts[newPosts.length - 1]].info.date
if ThreadStats.lastPost > ThreadStats.lastPageUpdate and ThreadStats.pageCountEl?.textContent isnt '1' if ThreadStats.lastPost > ThreadStats.lastPageUpdate and ThreadStats.pageCountEl?.textContent isnt '1'
ThreadStats.fetchPage() ThreadStats.fetchPage()
update: (postCount, fileCount) -> update: (postCount, fileCount, ipCount) ->
{thread, postCountEl, fileCountEl} = ThreadStats {thread, postCountEl, fileCountEl, ipCountEl} = ThreadStats
postCountEl.textContent = postCount postCountEl.textContent = postCount
fileCountEl.textContent = fileCount fileCountEl.textContent = fileCount
ipCountEl.textContent = if ipCount? then ipCount else '?'
(if thread.postLimit and !thread.isSticky then $.addClass else $.rmClass) postCountEl, 'warning' (if thread.postLimit and !thread.isSticky then $.addClass else $.rmClass) postCountEl, 'warning'
(if thread.fileLimit and !thread.isSticky then $.addClass else $.rmClass) fileCountEl, 'warning' (if thread.fileLimit and !thread.isSticky then $.addClass else $.rmClass) fileCountEl, 'warning'

View File

@ -339,3 +339,4 @@ ThreadUpdater =
newPosts: posts.map (post) -> post.fullID newPosts: posts.map (post) -> post.fullID
postCount: OP.replies + 1 postCount: OP.replies + 1
fileCount: OP.images + (!!ThreadUpdater.thread.OP.file and !ThreadUpdater.thread.OP.file.isDead) fileCount: OP.images + (!!ThreadUpdater.thread.OP.file and !ThreadUpdater.thread.OP.file.isDead)
ipCount: OP.unique_ips