Notes with Ravinder on Badging System Development Part II

One more badge prototype done:... "posts in the past month"

$one_month_ago = time() - $month; 
$monthquery = "SELECT COUNT(postid) AS postcount from post where userid=".$uid ." and dateline > " .$one_month_ago; 
$monthposts = $vbulletin->db->query_first($monthquery); 
if ($monthposts['postcount'] >= 30) { 
    $color['facomment'] = 'black'; 
}  
elseif ($monthposts['postcount'] >= 15) { 
    $color['facomment'] = 'indigo'; 
} elseif ($monthposts['postcount'] >= 5) { 
    $color['facomment'] = 'blue'; 
} elseif ($monthposts['postcount'] >= 1) { 
    $color['facomment'] = 'limegreen'; 
} else { 
    $color['facomment'] = 'lightgray'; 
} 

$badgejs .= 'badge["facomment"] = "' . $color['facomment'] . '";'; 
$badgejs .= 'badge["facommentval"] = "' . number_format($monthposts['postcount']) . '";'; 

jQuery:

$('.fa-comment').css("color",badge["facomment"]);
$('.fa-comment').css("cursor","pointer").attr("title",  badge["facommentval"] + " Posts in the Last Month");
$('.fa-comment').closest('div').find('.fa-circle').css("color",badge["facomment"]);

Another one bites the dust.... prototype badge "discussions started in the last month" ...

<?php
$monthtq = "SELECT COUNT(threadid) AS threadcount from thread where firstpostid=" . $uid . " and  dateline > " . $one_month_ago;
$monththreads = $vbulletin->db->query_first($monthtq);
if ($monththreads['threadcount'] >= 4) {
    $color['faterminal'] = 'black';
} elseif ($monththreads['threadcount'] >= 5) {
    $color['faterminal'] = 'indigo';
} elseif ($monththreads['threadcount'] >= 2) {
    $color['faterminal'] = 'blue';
} elseif ($monththreads['threadcount'] >= 1) {
    $color['faterminal'] = 'limegreen';
} else {
    $color['faterminal'] = 'lightgray';
}

$badgejs .= 'badge["faterminal"] = "' . $color['faterminal'] . '";';
$badgejs .= 'badge["faterminalval"] = "' . number_format($monththreads['threadcount']) . '";';

jQuery:

$('.fa-terminal').css("color",badge["faterminal"]);
$('.fa-terminal').css("cursor","pointer").attr("title",  badge["faterminalval"] + " Discussions Started in the Last Month");
$('.fa-terminal').closest('div').find('.fa-circle').css("color",badge["faterminal"]);

9 out of 48 protos left .. :slight_smile:

OK... prototype "thanks per month" badge is done:

$thanksmq = "SELECT SUM(post_thanks_amount) AS monthlythanks from post where userid=" . $uid . " and  dateline > " . $one_month_ago; 
$monththanks = $vbulletin->db->query_first($thanksmq); 
if ($monththanks['monthlythanks'] >= 10) { 
    $color['farocket'] = 'black'; 
} elseif ($monththanks['monthlythanks'] >= 5) { 
    $color['farocket'] = 'indigo'; 
} elseif ($monththanks['monthlythanks'] >= 2) { 
    $color['farocket'] = 'blue'; 
} elseif ($monththanks['monthlythanks'] >= 1) { 
    $color['farocket'] = 'limegreen'; 
} else { 
    $color['farocket'] = 'lightgray'; 
} 

$badgejs .= 'badge["farocket"] = "' . $color['farocket'] . '";'; 
$badgejs .= 'badge["farocketval"] = "' . number_format($monththanks['monthlythanks']) . '";';

jQuery:

$('.fa-rocket').css("color",badge["farocket"]);
$('.fa-rocket').css("cursor","pointer").attr("title",  badge["farocketval"] + " Thanks in the Last Month");
$('.fa-rocket').closest('div').find('.fa-circle').css("color",badge["farocket"])

I think that leaves 7 proto-badges to go ... :slight_smile:

Also, light press on mobile gives info on each badge:

Ravinder,

Please write the logic for the "current number of consecutive days active on the forums" ....

If you need a new MySQL table please specific the table definition and I will create it.

Thanks!

Thanks a TON Neo for coding all these badges,sorry I am not having proper access in office(only IE is there so not able to perform anything).

For writing logic for consecutive days one,is it ok if I first present logic rather than code(as I know php which I learnt from you in last few days, I know I could write logic for it. Please do give me an hour or so I will write it here.

EDIT: Also request you to edit string so that it will be clear that people received THANKS from others, may be as follows. Ahhh if I would have access in office today I would have tried to write 1 of them.

$('.fa-rocket').css("cursor","pointer").attr("title",  badge["farocketval"] + " Thanks received in the Last Month");

Thanks,
R. Singh

1 Like

No. Hurry.

Take your time. Glad you like the three new badges... :slight_smile:

OK... Ravinder... updated the rocket:

$('.fa-rocket').css("cursor","pointer").attr("title",  badge["farocketval"] + " Thanks Received in the Last Month");
1 Like

Hey Neo,

Following will be my approach in order to get consecutive days BADGE's creation.

Step 1st: Create a field named daily_login_count in user TABLE(mysql).
Step 2nd: Now whenever user logs in to forum then check condition if (TODAY's date-1)==lastvisit(fied value) then add 1 in daily_login_count.(I know this method should be invoked when user is clicking on LOGIN button and able to successfully login :slight_smile: )
Step 3rd:
i- Now check if value of daily_login_count>=1 && daily_login_count<14 then BADGE color should be orangered.
ii- Check if value of daily_login_count>=14 && daily_login_count<30 then BADGE color should be darkorange.
iii- Check if value of daily_login_count>=30 && daily_login_count<60 then BADGE color should be lightgray.
iv- Check if value of daily_login_count>=60 && daily_login_count<90 then BADGE color should be limegreen.
v- Check if value of daily_login_count>=90 && daily_login_count<120 then BADGE color should be blue.
vi- Check if value of daily_login_count>=120 && daily_login_count<150 then BADGE color should be indigo.
vii- Check if value of daily_login_count>=150 && daily_login_count<180 then BADGE color should be black.

Step 4th: In case condition 2nd is NOT TRUE means user is logging after some days then make daily_login_count=1 and change BADGE color to red.

Thanks,
R. Singh

Well, we don't need to invoke on login, because sometimes a user will not logout for days or weeks.

We can invoke when user views any page, but I guess the best is "showthread" because anyone who is looking at a thread, is "active"...

Regarding your badging logic, I thought you were going to write badge logic for consecutive days active, no?

Your logic seems to only count days, consecutive days or not....

Is that want you want? Just counting days? Not consecutive days?

No, I have taken care of consecutive days, if condition 2nd is NOT TRUE means (today's date - 1) != lastlogin) then it again sets daily_login_count to 1 rather than adding 1 to its count, hence taken care of consecutive thing.

Now coming to logging out logic(I have a question here), whenever we see Who is Online page then after 29 mins I see people will not be seen isn't it they are logged out now from forum(sorry till now I thought this only that user's sessions have 30 mins expiring time)?

Thanks,
R. Singh

WOL based on session activity is not the same as logging in and out; otherwise, every time you when to have tea or go for dinner and come back to your computer you would have to login again.

Obviously, you don't have to login every time you go away from an hour. At least for me, I rarely login to the forums, even when I wake up in the morning and turn on my Mac Pro; my login is still valid when I visit the forums.

It is not an issue, there are many ways to invoke a script, we do not need to invoke on login, like I said.

I will run the script on "showthread" page, so you need to take that into account and check that you only increment the day++ count IFF it has not already been incremented for that day.

You can do that in many ways.... but you cannot do it solely based on login.

Update:

41 of 48 prototype badges done, or 85%.

Ravinder is working on the logic for a "consecutive days or forum activity" badge, which sounds cool, so that would be number 42 I guess, which will leave 6 "Reserved" badges left to do.

If one of those "Reserved" badges is allocated for the the mod system of member ranking; then that means:

41 Badges Done
1 Badge Under Development (Ravinder)
1 Badge for Mod Scoring / Points (Reserved)

This is real progress in a relatively short time.

If anyone has an idea for a badge, please post!

Thanks.

Thanks Neo for letting us know the status. 1 more badge name came into my mind just now so posting it here. How about a badge for sharing experience on any projects/any story(may be WAR stories forum things). It could be awarded by MODs/Admins to person who shared nice experiences in that forum?(It is not a system generated one).

Kindly do let me know your thoughts on same, till then I am thinking more badges. Let me know if you like it.

EDIT: Ok, got 1 more in just now, how about if a person newly joins if get a THANKS within a week of joining forums we could give him/her "enthusiast" BADGE etc, how about this one?

Thanks,
R. Singh

1 Like

I like your idea about a Mod issues badge to anyone who has posted some outstanding project or story. That badge can be nominated by a Mod and discussed in the Mod forum and when we approve it; I can add that user's userid to the array and it's done, easy.

Regarding, making a badge based on "getting a thanks within a week", the problem for that badge is that few people will achieve it and so that badge will remain "lightgray" forever for some number greater than 99% of the forum members and after a week passes, they will never have a chance to get that badge; so I think I'll pass on that one.. but that's for the idea!

Sure,how about these 2 now:

1- Whoever gets HIGHEST THANKS in a month gets BADGE,(applicable only for TOP 5 or so and visible only for TOP 5 people NOT seen by any other people). May be we could add HIGHEST THANKS badges for 1 week, 1 month and 1 year. Then after a year competition starts again?
.
2- Whoever joins forum and within a week gets at least 1 THANKS BUT only he gets that badge others will NOT be able to see that(I mean enable this badge only for that person who achieves it bu this way others will NOT regret that they didn't get this BADGE and new members will be encouraged too?).

Thanks,
R. Singh

Here is the badge awarded by Mods for when the feel a member has shared a great project or story.

Regarding your other two ideas, I need to think about them... But off the top of my head, we have enough badges related to thanks and do not need more "thanks" badges :slight_smile:

Ravinder,

I think it quite easy to do the "sequential days active" badge. This simple logic came to me in my sleep. We simply use a query like this:

mysql> SELECT UNIX_TIMESTAMP()/(60*60*24);
+-----------------------------+
| UNIX_TIMESTAMP()/(60*60*24) |
+-----------------------------+
|                  17900.1528 |
+-----------------------------+
1 row in set (0.00 sec)

to give us the number of days since the beginning of unixtime.

We store this value, rounded down in a new lastdayactive field in the user table;

Then we insert a 1 in the in the daysinsequence field in the same table.

Then we compare UNIX_TIMESTAMP()/(60*60*24) with lastdayactive and if this is one day greater (and less than two) than before, we update lastdayactive and increment daysinsequence .

If UNIX_TIMESTAMP()/(60*60*24) - lastdayactive is greater than 1 day we update lastdayactive and reset daysinsequence to 1.

It's quite simple, I think.

Hence, you get a D on this one (for implementation logic, sorry for that) because it is very simple to do but you could not do it after many days ... but an A for a great idea :slight_smile:

I will implement this badge when I am back from my trip upcountry.

1 Like

Note, I'm jumping on a plane in a few hours, so I don't have time to check this properly, but I'm thinking:

<?php
$day = 60 * 60 * 24;
$dayago = time() - $day;
$incrementseq = "UPDATE user SET lastdayactive = (UNIX_TIMESTAMP()/(60*60*24)), daysinsequence =  daysinsequence +1 WHERE userid =" . $uid;
$selectday = "SELECT lastdayactive AS lastactive FROM user WHERE userid =" . $uid;
$resetday = "UPDATE user SET lastdayactive = (UNIX_TIMESTAMP()/(60*60*24)), daysinsequence =  1 WHERE userid =" . $uid;

$day = $vbulletin->db->query_first($selectday);

if ($day['lastactive'] > $dayago && $day['lastactive'] <= $dayago * 2) {
    $status = $vbulletin->db->query_write($incrementseq);
} elseif ($day['lastactive'] > $dayago * 2) {
    $status = $vbulletin->db->query_write($resetday);
}

$getseq = "SELECT daysinsequence AS daysactive FROM user WHERE userid =" . $uid;
$days = $vbulletin->db->query_first($getseq);
if ($days['daysactive'] > 14) {
    $color['fahistory'] == 'black';
} elseif ($days['daysactive'] > 7) {
    $color['fahistory'] == 'indigo';
} elseif ($days['daysactive'] > 3) {
    $color['fahistory'] == 'blue';
} elseif ($days['daysactive'] > 1) {
    $color['fahistory'] == 'limegreen';
} else {
    $color['fahistory'] == 'lightgray';
}
$badgejs .= 'badge["fahistory"] = "' . $color['fahistory'] . '";';
$badgejs .= 'badge["fahistoryval"] = "' . number_format($days['daysactive']) . '";';

Please take a look and let me know what you think Ravinder!

Thanks

PS: I have not debugged that code above yet and realize that we need to add logic to not query the DB after we reset; because we already have the value (1) so no reason to do the extra query, etc.

1 Like

Alerts:

OK I have come up with an easy way to implement alerts when the badge beta is done.

Will take the array of badge colors and convert that array to a JSON string and then take the cryptographic hash of that string and store that string in the user table.

Then it is easy to check when a new threshold badge has been reached without tracking values that change often.

Then when the state changes .. will issue a simple dismissable Bootstrap alert which states the user has a new badge but not the actual badge (in first beta) and will have a link to the badge page.

Later will add the actual details of the status changes to the alert message.