Example #1
0
function get_weekly_volume_graph()
{
    global $wpdb;
    global $userdata;
    get_currentuserinfo();
    $beg_date = new Date();
    $end_date = new Date();
    $wk = array(0, 0, 0, 0);
    $label = array(0, 0, 0, 0);
    $filename = array("filename" => "/var/www/vanhlebarsoftware/wp-content/plugins/fitnesslog/graphs/wklygraph.png");
    // Get current weeks and prior three weeks volume numbers.
    $day_of_wk = $beg_date->getDayOfWeek();
    $beg_date->addDays(-($day_of_wk - 1));
    $end_date->copy($beg_date);
    $end_date->addDays(6);
    for ($i = 0; $i < 4; $i++) {
        $query = "SELECT user_id, SUM(seconds) AS seconds FROM " . $wpdb->prefix . "flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userdata->ID . " GROUP BY user_id";
        $result = $wpdb->get_results($query, ARRAY_A);
        if ($result) {
            foreach ($result as $row) {
                $wk[$i] = convert_seconds_minutes($row["seconds"]);
            }
        } else {
            $wk[$i] = 0;
        }
        // Add any strength training that we have done to the total.
        $query = "SELECT user_id, SUM(seconds) AS seconds FROM " . $wpdb->prefix . "flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userdata->ID . " GROUP BY user_id";
        $result = $wpdb->get_results($query, ARRAY_A);
        if ($result) {
            foreach ($result as $row) {
                $wk[$i] = $wk[$i] + convert_seconds_minutes($row["seconds"]);
            }
        }
        // Create the labels.
        $label[$i] = $end_date->format("%m/%d");
        // Move the dates back by one week.
        $beg_date->addDays(-7);
        $end_date->addDays(-7);
    }
    //Setup the graph.
    $Graph =& Image_Graph::factory('graph', array(175, 175), true);
    $Plotarea =& $Graph->addNew('plotarea');
    $Dataset =& Image_Graph::factory('dataset');
    $Dataset->addPoint($label[3], $wk[3]);
    $Dataset->addPoint($label[2], $wk[2]);
    $Dataset->addPoint($label[1], $wk[1]);
    $Dataset->addPoint($label[0], $wk[0]);
    $Plot =& $Plotarea->addNew('bar', &$Dataset);
    $Plot->setFillColor('green');
    $YAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $YAxis->setTitle('Minutes', 'vertical');
    $XAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    //	$XAxis->setFontAngle( "vertical" );
    $XAxis->setTitle("Week", array('angle' => 0));
    //Output the finished graph to the graphs directory.
    $result = $Graph->done($filename);
    if ($result) {
        var_dump("error creating graph!");
    }
}
Example #2
0
function runpace($time, $distance)
{
    //$time_sec = convert_time_seconds( $time );
    // Return run pace
    return round(convert_seconds_minutes($time) / $distance, 2);
}
Example #3
0
function get_prior_year($template, $userID, $connection)
{
    $calc = new Date_Calc();
    $beg_date = new Date();
    $end_date = new Date();
    $beg_date->addYears(-1);
    // Get current month dates.
    $beg_date->setDayMonthYear(1, 1, $beg_date->getYear());
    $end_date->setDayMonthYear(31, 12, $beg_date->getYear());
    $query = "SELECT SUM(seconds) AS seconds, SUM(distance) AS distance, sbr_type FROM flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='a' GROUP BY sbr_type";
    $result = @mysql_query($query, $connection);
    $template->setCurrentBlock("PRIORYR");
    $template->setVariable("MONTHNAME", $beg_date->format("%Y"));
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_array($result)) {
            switch ($row["sbr_type"]) {
                case 's':
                    $template->setVariable("SWIMDUR", round(convert_seconds_minutes($row["seconds"]), 2) . "min");
                    $template->setVariable("SWIMDIST", $row["distance"] . " yds");
                    break;
                case 'b':
                    $template->setVariable("BIKEDUR", round(convert_seconds_minutes($row["seconds"]), 2) . "  min");
                    $template->setVariable("BIKEDIST", $row["distance"] . "  mi");
                    break;
                case 'r':
                    $template->setVariable("RUNDUR", round(convert_seconds_minutes($row["seconds"]), 2) . " min");
                    $template->setVariable("RUNDIST", $row["distance"] . " mi");
                    break;
            }
        }
    }
    /* Get the strength minutes */
    $query = "SELECT SUM(seconds) AS seconds FROM flstrength WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND user_id=" . $userID . " AND plan_type='a'";
    $results = @mysql_query($query, $connection);
    if ($results) {
        while ($row = mysql_fetch_array($results)) {
            $template->setVariable("STRDUR", round(convert_seconds_minutes($row["seconds"]), 2) . " min");
        }
    }
    $template->parseCurrentBlock();
}
Example #4
0
function loadAnnualVolbyType($userID, $date, $template)
{
    $Volume = array();
    $swim_vol = array();
    $bike_vol = array();
    $run_vol = array();
    $beg_date = new Date();
    $end_date = new Date();
    $filename = array("filename" => "/var/www/vanhlebarsoftware/fitlog/graphs/annualvolgraph.jpg");
    // Get the earliest and latest Year for our loop.
    $query = "SELECT workout_date FROM flmain WHERE plan_type='a' GROUP BY workout_date ASC";
    $result = @mysql_query($query);
    $first = TRUE;
    while ($row = mysql_fetch_array($result)) {
        if ($first) {
            $first_year = explode("-", $row["workout_date"]);
            $first = FALSE;
        } else {
            $last_year = explode("-", $row["workout_date"]);
        }
    }
    // Setup the dates.
    $beg_date->setDayMonthYear(1, 1, $first_year[0]);
    $end_date->setDayMonthYear(31, 12, $first_year[0]);
    for ($i = intval($first_year[0]); $i <= intval($last_year[0]); $i++) {
        // Move on to the next year only if we are not on the first year.
        if ($i != intval($first_year[0])) {
            $beg_date->setDayMonthYear(1, 1, $i);
            $end_date->setDayMonthYear(31, 12, $i);
        }
        $query = "SELECT sbr_type, plan_type, SUM(seconds) AS seconds FROM flmain WHERE workout_date>='" . $beg_date->format("%Y-%m-%d") . "' AND workout_date<='" . $end_date->format("%Y-%m-%d") . "' AND plan_type='a'" . " AND user_id=" . $userID . " GROUP BY sbr_type ASC";
        $result = @mysql_query($query);
        $bikerow = mysql_fetch_array($result);
        $runrow = mysql_fetch_array($result);
        $swimrow = mysql_fetch_array($result);
        // Fill in the Dataset.
        $swim_vol[$i] = convert_seconds_minutes($swimrow["seconds"]);
        $bike_vol[$i] = convert_seconds_minutes($bikerow["seconds"]);
        $run_vol[$i] = convert_seconds_minutes($runrow["seconds"]);
    }
    // Push the three datasets into the $Volume and $Distance datasets to plot on the graph.
    $Volume["swim"] = $swim_vol;
    $Volume["bike"] = $bike_vol;
    $Volume["run"] = $run_vol;
    //Setup the graph.
    $Graph =& Image_Graph::factory('graph', array(array("width" => 800, "height" => 400)));
    $Graph->add(Image_Graph::vertical(Image_Graph::factory('title', array('Annual Volume', 12)), Image_Graph::vertical($Plotarea = Image_Graph::factory('plotarea'), $Legend = Image_Graph::factory('legend'), 90), 5));
    $Legend->setPlotarea($Plotarea);
    // Add the actual volume for each activity to the graph, side-by-side
    foreach ($Volume as $name => $dataset) {
        $data =& Image_Graph::factory('dataset');
        $data->setName($name);
        foreach ($dataset as $x => $y) {
            $data->addPoint($x, $y);
        }
        $dataset_vol[] = $data;
    }
    // Plot the data to the graph.
    $Plot =& $Plotarea->addNew('bar', array($dataset_vol));
    // Set the colors for the bars.
    $FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
    $FillArray->addColor('lightblue');
    $FillArray->addColor('yellow');
    $FillArray->addColor('lightgreen');
    // Set the fill style
    $Plot->setFillStyle($FillArray);
    // Setup the axis titles.
    $YAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
    $YAxis->setTitle('Minutes', 'vertical');
    $XAxis =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
    $XAxis->setTitle("Year", array('angle' => 0));
    //Output the finished graph to the graphs directory.
    $result = $Graph->done($filename);
    if ($result) {
        var_dump("error creating graph!");
    }
}