} else {
            return 0;
        }
    }
}
function convertToJSON($items)
{
    global $chartmapvlaue;
    for ($va = 0; $va < sizeof($items); $va++) {
        $item = $items[$va];
        $chartmapvlaue .= '{"driver_name":"' . $item->driver_name . '" , "total_score":' . $item->total_score . ',"aggressive_score":"' . $item->aggressive_score . '","distraction_score":"' . $item->distraction_score . '"},';
    }
    return $chartmapvlaue;
}
require JPATH_BASE . DS . "components" . DS . "com_fleetmatrix" . DS . "models" . DS . "calculator.php";
$calculator = new ScoreCalculator();
$user =& JFactory::getUser();
$db =& JFactory::getDBo();
if ($user) {
    $query = $db->getQuery(true)->select('entity_type, entity_id')->from('#__fleet_user')->where('id = "' . $user->id . '"');
    $db->setQuery($query);
    $row = $db->loadObject();
    if ($row) {
        $query = $db->getQuery(true)->select('id')->from("#__fleet_entity")->where('parent_entity_id = ' . $row->entity_id);
        $db->setQuery($query);
        $results = $db->loadResultArray();
        switch ($row->entity_type) {
            case 1:
                // reseller
                foreach ($results as $id) {
                    $GLOBALS['user_companies'][] = $id;
<?php

defined('_JEXEC') or die('Restricted Access');
?>

<?php 
// require(JPATH_BASE.DS."components".DS."com_fleetmatrix".DS."models".DS."calculator.php");
$calculator = new ScoreCalculator();
$driver_id = JRequest::getInt('driver', 0);
$driver_name = JRequest::getString('drivername');
$accel_decel_turns = $calculator->getDriverADTScore($driver_id);
$speed = $calculator->getDriverAllSpeedScore($driver_id);
$merged_events = array_merge($accel_decel_turns, $speed);
# the following merged adt and speed into one array by date
usort($merged_events, "sort_items_by_totalScore");
function sort_items_by_totalScore($a, $b)
{
    if ($a->starttime > $b->starttime) {
        return -1;
    } else {
        if ($b->starttime > $a->starttime) {
            return 1;
        } else {
            return 0;
        }
    }
}
?>

<?php 
foreach ($merged_events as $i => $item) {