Jump to content

How to create progress bar to show calories left for user to burn to reach their goal


mal14

Recommended Posts

So I changed the each $target to $target_calories.

 

These are the calories the user has burned:

Calories Burned: 876

Calories Burned: 530

 

And this is the total:

Calories burned to date : 4218

 

So I think the sum calculation may be wrong?

Link to comment
Share on other sites

I get that

 

I've just tried that

 

So the bar comes up and when I enter an activity to find out how many calories are burned(530) and save it to the database...

Calories burned to date : 
Target calories :

 

^^this comes up and the bar stays blank

 

I get that if the userid in the session data has no data in the tables

 

 

So I changed the each $target to $target_calories.

 

These are the calories the user has burned:

Calories Burned: 876

Calories Burned: 530

 

And this is the total:

Calories burned to date : 4218

 

So I think the sum calculation may be wrong?

Looks like there are 3 goal records for the user. I assumed 1.

 

If there are several, how are they to be processed?

Link to comment
Share on other sites

Here's a replacemnt progress_bar function

function progress_bar($width, $height, $calories, $target)
{
    $bar = "<svg width='$width' height='$height' view_box='0 0 $width $height'>\n
            <rect x='0' y='0' width='$width' height='$height' fill='#CCC' />\n";
    // calc width of bar for calories already burned
    if ($target==0) {
            $target = 1;
    }
    if ($calories > 0) {
        $cal_width = $calories * $width / $target;
        $bar .= "<rect x='0' y='0' width='$cal_width' height='$height' stroke='#ccc' fill='#3C3' />\n";
    }
    else {
        $bar .= "<text x='5' y='16' font-size='9pt'>No data for user</text>\n";
    }
    $bar .= "</svg>\n";
    return $bar;
}

Link to comment
Share on other sites

Looks like there are 3 goal records for the user. I assumed 1.

 

If there are several, how are they to be processed?

I would like the latest goal set to be the one the user tracks their calories burned against, considering that their previous goal had been met already.

Link to comment
Share on other sites

 

Here's a replacemnt progress_bar function

function progress_bar($width, $height, $calories, $target)
{
    $bar = "<svg width='$width' height='$height' view_box='0 0 $width $height'>\n
            <rect x='0' y='0' width='$width' height='$height' fill='#CCC' />\n";
    // calc width of bar for calories already burned
    if ($target==0) {
            $target = 1;
    }
    if ($calories > 0) {
        $cal_width = $calories * $width / $target;
        $bar .= "<rect x='0' y='0' width='$cal_width' height='$height' stroke='#ccc' fill='#3C3' />\n";
    }
    else {
        $bar .= "<text x='5' y='16' font-size='9pt'>No data for user</text>\n";
    }
    $bar .= "</svg>\n";
    return $bar;
}

The bar now works!

 

This comes up...

 

Calories burned to date : 4218

Target calories : 154000

Edited by mal14
Link to comment
Share on other sites

I would like the latest goal set to be the one the user tracks their calories burned against, considering that their previous goal had been met already.

So there could be old tracklog records for a user that were targetted against a previous goal.

At present, the calories burned in these would also be included against the latest goal.

Link to comment
Share on other sites

You would have to assign log records to a specific goal. So you would store the id of a goal record in each log record.

+-----------+
| user      |
+-----------+
| userid    |--+
| name      |  |
| etc       |  |
+-----------+  |
               |
               |        +----------+
               |        |  goal    |
               |        +----------+
               |        | goalid   |---+
               +-------<| userid   |   |
                        | weighloss|   |
                        | units    |   |
                        | whenby   |   |
                        | etc      |   |
                        +----------+   |
                                       |
                                       |        +-------------+
                                       |        | tracklog    |
                                       |        +-------------+
                                       |        |  userid     |
                                       +-------<|  goalid     |
                                                |  calories   |
                                                |  etc        |
                                                +-------------+
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.