1 (edited by Razmooze 2005-11-22 01:45)

Topic: Activity Barometer 1.0.0

Doc:

##
##
##        Mod title:  Activity Barometer
##
##      Mod version:  1.0.1
##   Works on PunBB:  ?, 1.1.4
##     Release date:  2004-06-25
##           Author:  B. Rasmus (Scratty) Anthin.
##
##      Description:  Shows the "flux" of posts per hour
##                    or number of posts during a day or a week.
##
##   Affected files:  index.php
##                    <lang>_index.php
##
##       Affects DB:  No
##
##         Comments:  Skip parts 8-11 if you don't have the swedish language-
##                    mode
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##


#
#---------[ 1. OPEN ]----------------------------------------------------------
#

    index.php

#
#---------[ 2. FIND (line: 187) ]----------------------------------------------
#

    echo "\t\t\t\t\t\t".'<br>'.$lang_index['Currently serving'].' '.$num_users.' '.(($num_users <> 1) ? $lang_index['registered users'] : $lang_index['registered user']).' '.$lang_index['and'].' '.$num_guests.' '.(($num_guests <> 1) ? $lang_index['guests'] : $lang_index['guest']).'.';

#
#---------[ 3. AFTER ADD ]-----------------------------------------------------
#

// Activity Barometer mod
$result = $db->query("SELECT COUNT(*) FROM ".$db->prefix."posts WHERE posted > ".(time()-7*24*3600)) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
$posts_week = $db->result($result);
$result = $db->query("SELECT COUNT(*) FROM ".$db->prefix."posts WHERE posted > ".(time()-24*3600)) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
$posts_day = $db->result($result);
$posts_h = $posts_day/24;
if ($posts_h<1)
   if ($posts_day<1)
      echo "<BR>".$lang_index['total']." $posts_week ".$lang_index['number week'].".";
   else
      echo "<BR>".$lang_index['total']." $posts_day ".$lang_index['number day'].".";
else
   echo "<BR>".$lang_index['average']." ".number_format($posts_h,1)." ".$lang_index['number h'].".";

#
#---------[ 4. OPEN ]----------------------------------------------------------
#

    en_index.php

#
#---------[ 5. FIND (line: 27) ]-----------------------------------------------
#

'guests'                =>    'guests'    // plural

#
#---------[ 6. ALTER ]---------------------------------------------------------
#

'guests'                =>    'guests',       // plural

#
#---------[ 7. AFTER ADD ]-----------------------------------------------------
#

// Activity Barometer mod
'total'                         =>      'In total',
'number week'                   =>      'number of posts during this week',
'number day'                    =>      'number of posts during this day',
'average'                       =>      'On average',
'number h'                      =>      'posts per hour'


#
#---------[ 8. OPEN ]----------------------------------------------------------
#

    se_index.php

#
#---------[ 9. FIND (line: 27) ]-----------------------------------------------
#

'guests'                =>    'gäster'    // plural

#
#---------[ 10. ALTER ]--------------------------------------------------------
#

'guests'                =>    'gäster',    // plural

#
#---------[ 11. AFTER ADD ]----------------------------------------------------
#

// Activity Barometer mod
'total'                         =>      'Totalt',
'number week'                   =>      'antal inlägg under senaste veckan',
'number day'                    =>      'antal inlägg under senaste dygnet',
'average'                       =>      'I snitt',
'number h'                      =>      'inlägg per timme'

#
#---------[ 12. SAVE/UPLOAD ]--------------------------------------------------
#

/******************************************************/

Hey. Just got an idea... why not make an activity barometer, ie sort of a flux-meter of posts that makes a moving average over a week and normalizes over a day (or hour if there's a lot of visitors). Sort of:

[cite]
flux = sum(posts(t), t=t0-7...t0) / 7  [posts/day]
[/cite]

or

[cite]
flux = sum(posts(t), t=t0-7*24...t0) / (7*24) [posts/h]
[/cite]

with autoranging (I guess it won't be that hard to implement such a feature, just a if-else structure)
and it could be implemented with a graphical "thermometer" in the footer of the forum-page or somewhere discrete. Any thoughts on this?

Edit: Since PunRes.org forum is down, I don't know where else to post this. Sorry if I placed this is in the wrong forum.

Edit: Added install instructions at the top...

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

Re: Activity Barometer 1.0.0

Btw, is there a way of getting the number of posts during an interval of time?

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

Re: Activity Barometer 1.0.0

SELECT COUNT(*) FROM posts WHERE posted>SOMETIME

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Activity Barometer 1.0.0

You might consider me stupid. But what is the timeformat for "SOMETIME". I took a peak at the db tables and it seems the time format is some sort of serial date number (like matlab's now). This is just a guess. To tell the truth, I know virtually nothing about mysql besides some few commands/queries for creating and deleting tables and such...
Sorry for my ignorance sad

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

Re: Activity Barometer 1.0.0

It's a unix timestamp, e.g. the number of secods that have passed since 1970-01-01 00:00. It's the most common way of handling date and time in programming languages. It's what you get back from the PHP function time().

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Activity Barometer 1.0.0

Yes yes... now I remember... wink
I recollect I did a matlab function for that a long time ago big_smile
Ok... then I think I have some stuff to work with... Thx a bunch Rickard!!!

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

Re: Activity Barometer 1.0.0

The following should be put in the file index.php at line 189.
I'm currently working on making it language-dependent wink.

// Activity barometer mod (B. Rasmus Anthin)
$result = $db->query("SELECT COUNT(*) FROM ".$db->prefix."posts WHERE posted > ".(time()-7*24*3600)) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
$posts_week = $db->result($result);
$result = $db->query("SELECT COUNT(*) FROM ".$db->prefix."posts WHERE posted > ".(time()-30*24*3600)) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
$posts_day = $db->result($result);
$posts_h = $posts_day/24;
if ($posts_h<1)
   if ($posts_day<1)
      echo "<BR>Totalt $posts_week antal inlägg under senaste veckan.";
   else
      echo "<BR>Totalt $posts_day antal inlägg under senaste dygnet.";
else
   echo "<BR>I snitt ".number_format($posts_h,1)." inlägg per timme.";
No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

8 (edited by Razmooze 2004-06-25 20:35)

Re: Activity Barometer 1.0.0

Fixed it... install instructions will come shortly.

Edit: look at post on top.

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

9 (edited by Razmooze 2004-06-26 13:21)

Re: Activity Barometer 1.0.0

Just a brief question; do you prefer "... inlägg i timmen" or as it is now "... inlägg per timme"?

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

Re: Activity Barometer 1.0.0

Razmooze wrote:

Just a brief question; do you prefer "... inlägg i timmen" or as it is now "... inlägg per timme"?

I think "inlägg per timme" sounds better.

"Real programmers are those that can sleep in front of terminals ... with their eyes opened."

"Real programmers don't work from 9 to 5. If any real programmers are around at 9am it's because they were up all night."

Re: Activity Barometer 1.0.0

hmm... oki.. thx! big_smile

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.

12

Re: Activity Barometer 1.0.0

Razmooze wrote:

'number day'                    =>      'number of posts during this day',

Isn't it "number of posts during 24 hours" ?
because you search for posts who are less than 24 back in the past.
Or am I wrong. The same goes for number of "posts during this week":
Shouldn't it be "number of post on the last seven days"?

Re: Activity Barometer 1.0.0

Yes, you're absolutely right. Didn't think of it that way, but on the other hand it looks prettier without the numbers smile

No electrons were harmed in the creation of this post.
However, many were excited and some may have enjoyed the experience.