Visit The New, Modern Unix Linux Community

Notes with Ravinder on Badging System Development Part II

Thread Tools Search this Thread
Top Forums Web Development Notes with Ravinder on Badging System Development Part II
# 36  
Originally Posted by Neo
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?).

R. Singh
# 37  
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 Smilie
# 38  

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 Smilie

I will implement this badge when I am back from my trip upcountry.
This User Gave Thanks to Neo For This Post:
# 39  
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:

$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!


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.
This User Gave Thanks to Neo For This Post:
# 40  

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.
# 41  

I think I may store the hash in the user's browser in localStorage and do the alert logic in Javascript and also provide the alert on / off toggle in JS.

Still thinking about this .
# 42  
This should be a good start:

$badges_serialized = json_encode ($color);
$hash = hash('ripemd160',$badges_serialized);
$gethash  = "SELECT badgeshash AS hash FROM user where userid =". $uid;
$userhash = $vbulletin->db->query_first($gethash);
if( $hash != $userhash['hash']){
	$updatehash = "UPDATE user SET badgeshash =". $hash . "WHERE userid =" . $uid;
	$status = $vbulletin->db->query_write($updatehash);
	setcookie("badgestatechange", true);
	setcookie("badgestatechange", false);

Or maybe modify to write a javascript and use js to write to localstorage.

Either way, this is the start of the alerting system when the state changes a users badges.

Later can write a function to parse the JSON and provide the exact info on what badge has changed; but will need to store the serialized badges and not just stash the hash.

Like this:

$badges_serialized = json_encode($color);
$hash = hash('ripemd160', $badges_serialized);
$gethash = "SELECT badgeshash AS hash FROM user where userid =" . $uid;
$userhash = $vbulletin->db->query_first($gethash);
if ($hash != $userhash['hash']) {
    $updatehash = "UPDATE user SET badgeshash =" . $hash . "WHERE userid =" . $uid;
    $status = $vbulletin->db->query_write($updatehash);
    $badgejs .= " localStorage.setItem('badgestatechange','true')"; 
} else {
    $badgejs .= " localStorage.setItem('badgestatechange','false')";

This first step is easy....

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #775
Difficulty: Medium
UML state machine is a significantly enhanced realization of the mathematical concept of a finite automaton in computer science applications.
True or False?

3 More Discussions You Might Find Interesting

1. What is on Your Mind?

Badging System: UNIX.COM Bug Hunter Badge (New)

I have moved the bug badge out of reserve and into the main stream. Basically, I will assign a color level like the others, based on who has made a good actionable bug report for UNIX.COM. "Good" means screenshots, links, and even details from web dev tools our the HTML source code. So far,... (0 Replies)
Discussion started by: Neo
0 Replies

2. What is on Your Mind?

Status of Badging System - Beta 1

Dear All, Here is the current status of the badging system: The Beta 1 phase of the new badging system is close to completion. 42 prototype badges have been "allocated" 6 prototype badge slots are held in reserve The "alert you have new badges" prototype is running and is currently... (4 Replies)
Discussion started by: Neo
4 Replies

3. What is on Your Mind?

New Badging System - Badges Prototype Beta 1 (Badges Only)

Today I mapped out the new badging system using FA icons, Beta 1 in no particular order except a 6 x 8 grid: The prototype HTML code for this layout: <style> .fa-badge-grid { font-size: 1.5em; } .row { ... (38 Replies)
Discussion started by: Neo
38 Replies

Featured Tech Videos