Notes with Ravinder on Badging System Development Part II

Tags
badges, badging system, css, development, forum development, html, jquery, new-badge-system-phaseii, php, system, underground, web programming

 
Thread Tools Search this Thread
# 36  
Old 2 Weeks Ago
Quote:
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?).

Thanks,
R. Singh
# 37  
Old 2 Weeks Ago
Here is the badge awarded by Mods for when the feel a member has shared a great project or story.

Image

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  
Old 2 Weeks Ago
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:

Code:
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:
RavinderSingh13 (2 Weeks Ago)
# 39  
Old 2 Weeks Ago
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:

Code:
<?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.
This User Gave Thanks to Neo For This Post:
RavinderSingh13 (2 Weeks Ago)
# 40  
Old 2 Weeks Ago
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.
# 41  
Old 2 Weeks Ago
Hmmm

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  
Old 2 Weeks Ago
This should be a good start:

Code:
<?php
$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);
}
else{
	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:

Code:
<?php
$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....

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Badging System: UNIX.COM Bug Hunter Badge (New) Neo What is on Your Mind? 0 1 Day Ago 08:29 AM
Status of Badging System - Beta 1 Neo What is on Your Mind? 4 6 Days Ago 11:07 PM
Ravinder Singh Just Earned His Green Web Dev Ops Badge Neo What is on Your Mind? 6 2 Weeks Ago 02:12 PM
Please Welcome Ravinder Singh to the Moderation Team Neo What is on Your Mind? 8 2 Weeks Ago 12:15 AM
New Badging System - Badges Prototype Beta 1 (Badges Only) Neo What is on Your Mind? 38 2 Weeks Ago 10:43 AM
SCO Development System for System V 3.2 R4.2 locovich SCO 3 02-21-2017 05:24 PM