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
# 8  
Old 01-01-2019
Hey Ravinder,

Your fancy query is broken... even I I put xxxxx as the field in the query, I get the same wrong answer:

Code:
mysql> SELECT TIME_TO_SEC(TIMEDIFF(NOW(), FROM_UNIXTIME('xxxxx')))/(3600*24) AS 'join_time' FROM user WHERE userid =1;
+-----------+
| join_time |
+-----------+
|   34.9583 |
+-----------+
1 row in set, 2 warnings (0.00 sec)

Code:
mysql> SELECT TIME_TO_SEC(TIMEDIFF(NOW(), FROM_UNIXTIME('WHAT_THE_F')))/(3600*24) AS 'join_time' FROM user WHERE userid =1;
+-----------+
| join_time |
+-----------+
|   34.9583 |
+-----------+
1 row in set, 2 warnings (0.00 sec)

This is why I write SQL queries that a 12 year old can understand. LOL

Yours looks really clever, but is broken.

I kindly suggest you rewrite your query to perform the logic outside of the SQL query; but it is up to you. I will wait for your next attempt.

Thanks and good try!

PS: You might earn your Dev Ops Team Badge sooner than I thought .. Haha
# 9  
Old 01-01-2019
Anyway.. Ravinder,

I don't think you should try to convert the UNIXTIME to a DATE format.

Just take time() minus the joindate from the table (in UNIXTIME) and subtract them and divide by the number of days in seconds to get the number of days. No need to convert to DATE format.

Or whatever you like, but your query is broken... try again Smilie


PS: There is no field in the user table called "jointime" as in your original query. Please check your table definition. Hint:

Code:
mysql> select joindate from user where userid =1;
+-----------+
| joindate  |
+-----------+
| 968947200 |
+-----------+
1 row in set (0.00 sec)

# 10  
Old 01-01-2019
Hey Ravinder.

If I were you, I would do this query:

Code:
mysql> select joindate from user where userid =1;

Take that result subtracted from today in UNIXTIME and divide by the number of seconds in year.

That gives you the number of years a person has been a member.

You don't need that fancy MySQL query with all the date / time functions for such a trivial requirement.

As you are beginner in programming, keep it simple... well, I suggest you keep it simple all your life; it's easier to debug or change when you look at the code in 10 years..... keep it simple. Do not be seduced by fancy queries and logic which look cool.... like many programmers and tech people do.

Keep it simple so that a 10th grader can understand it.
# 11  
Old 01-01-2019
One more clue before I sleep ...

Code:
$modaluser['joindate']

You do not need a new SQL query for this badge Smilie
# 12  
Old 01-01-2019
Hey Ravinder,

I already fixed and rearranged your code and it is working now:

Code:
$time_join = time() - $modaluser['joindate'];
$years_a_member = $time_join / $year;

if ($time_inactive < $year) { 
    if ($years_a_member > 0 && $time_inactive < 1) { 
        $color['fajoin_time'] = 'orangered'; 
    } elseif ($years_a_member < 2 && $years_a_member  >= 1) { 
        $color['fajoin_time'] = 'darkorange'; 
    } elseif ($years_a_member < 3 && $years_a_member  >= 2) { 
        $color['fajoin_time'] = 'lightgray'; 
    } elseif ($years_a_member < 4 && $years_a_member  >= 3) { 
        $color['fajoin_time'] = 'limegreen'; 
    } elseif ($years_a_member < 5 && $years_a_member  >= 4) { 
        $color['fajoin_time'] = 'blue'; 
    } elseif ($years_a_member < 10 && $years_a_member >= 5) { 
        $color['fajoin_time'] = 'indigo'; 
    } elseif ($years_a_member >= 10) { 
        $color['fajoin_time'] = 'black'; 
    } else { 
        $color['fajoin_time'] = 'red'; 
    } 
} else { 
    $color['fajoin_time'] = 'red'; 
} 

$badgejs .= 'badge["fajoin_time"] = "' . $color['fajoin_time'] . '";';   
$badgejs .= 'badge["fajoin_timeval"] = "' . number_format($years_a_member) . '";';

jQuery:

Code:
$('.fa-clock').css("color",badge["fajoin_time"]);
$('.fa-clock').css("cursor","pointer").attr("title",  badge["fajoin_timeval"] + " Years Active at UNIX.COM");
$('.fa-clock').closest('div').find('.fa-circle').css("color",badge["fajoin_time"]);

This is a great badge you came up with. I really like it. Very useful too. Only 11 more to go for this phase of rapid prototype development!

Thanks for trying on this (you were close!) . ... I look forward to your next badge!

What is the next, great, Ravinder Singh idea for a badge?
This User Gave Thanks to Neo For This Post:
# 13  
Old 01-01-2019
Quote:
Originally Posted by Neo
Hey Ravinder,
I already fixed and rearranged your code and it is working now:
Code:
$time_join = time() - $modaluser['joindate'];
$years_a_member = $time_join / $year;
if ($time_inactive < $year) { 
    if ($years_a_member > 0 && $time_inactive < 1) { 
        $color['fajoin_time'] = 'orangered'; 
    } elseif ($years_a_member < 2 && $years_a_member  >= 1) { 
        $color['fajoin_time'] = 'darkorange'; 
    } elseif ($years_a_member < 3 && $years_a_member  >= 2) { 
        $color['fajoin_time'] = 'lightgray'; 
    } elseif ($years_a_member < 4 && $years_a_member  >= 3) { 
        $color['fajoin_time'] = 'limegreen'; 
    } elseif ($years_a_member < 5 && $years_a_member  >= 4) { 
        $color['fajoin_time'] = 'blue'; 
    } elseif ($years_a_member < 10 && $years_a_member >= 5) { 
        $color['fajoin_time'] = 'indigo'; 
    } elseif ($years_a_member >= 10) { 
        $color['fajoin_time'] = 'black'; 
    } else { 
        $color['fajoin_time'] = 'red'; 
    } 
} else { 
    $color['fajoin_time'] = 'red'; 
} 

$badgejs .= 'badge["fajoin_time"] = "' . $color['fajoin_time'] . '";';   
$badgejs .= 'badge["fajoin_timeval"] = "' . number_format($years_a_member) . '";';

jQuery:

Code:
$('.fa-clock').css("color",badge["fajoin_time"]);
$('.fa-clock').css("cursor","pointer").attr("title",  badge["fajoin_timeval"] + " Years Active at UNIX.COM");
$('.fa-clock').closest('div').find('.fa-circle').css("color",badge["fajoin_time"]);

This is a great badge you came up with. I really like it. Very useful too. Only 11 more to go for this phase of rapid prototype development!
Thanks for trying on this (you were close!) . ... I look forward to your next badge!
What is the next, great, Ravinder Singh idea for a badge?
Thanks a TON Neo for fixing it. Thanks for appreciation on badge it boosted me up now. Will let you/all know once I get another thought of badge Smilie

Thanks,
R. Singh
# 14  
Old 01-02-2019
Hi Ravinder,

Please keep in mind that this also will work, is easier to read, and it a lot shorter:

Code:
$time_join = time() - $modaluser['joindate'];
$years_a_member = $time_join / $year;

if ($time_inactive < $year) { 
    if ($years_a_member >= 10) { 
        $color['fajoin_time'] = 'black'; 
    } 
    elseif ($years_a_member >= 5) { 
        $color['fajoin_time'] = 'indigo'; 
    }
    elseif ($years_a_member  >= 4) { 
        $color['fajoin_time'] = 'blue'; 
    }
    elseif ($years_a_member  >= 3) { 
        $color['fajoin_time'] = 'limegreen'; 
    }
    elseif ($years_a_member  >= 2) { 
        $color['fajoin_time'] = 'lightgray'; 
    }
    elseif ($years_a_member  >= 1) { 
        $color['fajoin_time'] = 'darkorange'; 
    } 
     else { 
        $color['fajoin_time'] = 'red'; 
    } 
} else { 
    $color['fajoin_time'] = 'red'; 
} 

$badgejs .= 'badge["fajoin_time"] = "' . $color['fajoin_time'] . '";';   
$badgejs .= 'badge["fajoin_timeval"] = "' . number_format($years_a_member) . '";';

At this point, I am thinking that soon we should move to a new phase of rapid prototype development if we cannot easily think of new badges. No need to waste time on the final 20% when when are 80% there, more-or-less.

So, if we do not have any ideas for additional badges now, we can just leave the as-is (reserved) and move on.

Or maybe you have some more badge ideas?

So far, it is only you and me with badge ideas, so no need to wait for other UG members to come up with badge logic Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

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: https://www.unix.com/members/1-albums215-picture991.png The prototype HTML code for this layout: <style> .fa-badge-grid { font-size: 1.5em; } .row { ... (38 Replies)
Discussion started by: Neo
38 Replies
Login or Register to Ask a Question