function GetTripDetail($tripId) { //----------------------------------------- // selected trip $trip = new trip(); $trip->retrieve($tripId); // get all waypoints for this trip $waypoint = new waypoint(); $waypoints = $waypoint->getAllObjectsArray('tripid = ' . DB::qstr($tripId), null, 'objid'); /* $wpdistance = ''; $totaldistance = 0; $wptypical = ''; $totaltypical = 0; $wpconsumption = ''; $totalconsumption = 0; $wpaverage = ''; $wpdrivetime = ''; $totaldrivetime = 0; $wpchargetime = ''; $totalchargetime = 0; $startdrivetime = $trip->att('theoreticalstarttime'); $wpchargeneeded = 0; $wpchargestarted = 0; $wparrivaltime = ''; $wpdeparturetime = ''; $wpchargestart = 0; */ // declare and initialize all variables $wpnbr = -1; $statusid = WaypointStatus::STATUS_LEFT; // build the waypoints array $dwp = null; //foreach ($waypoints as &$wp) { for ($i = 0; $i < count($waypoints); $i++) { // get the needed waypoints $wp = $waypoints[array_keys($waypoints)[$i]]; if ($i > 0) { $prevwp = $waypoints[array_keys($waypoints)[$i - 1]]; } if ($i < count($waypoints) - 1) { $nextwp = $waypoints[array_keys($waypoints)[$i + 1]]; } // get the active waypoint (etappe) and status if ($statusid == WaypointStatus::STATUS_LEFT) { $wpnbr++; $statusid = $wp['statusid']; } // calculate all values // first position : O overview (effective), T theoretical, F formatting // second position : A distance, T Typical, V consumption G Average // third position : 1 waypoint-value, 2 sum CalculateDistance($i, $wp, $prevwp, $oa1, $ta1, $oa2, $ta2, $ot1, $tt1, $ot2, $tt2, $ov1, $tv1, $ov2, $tv2, $og1, $tg1, $og2, $tg2, $fa1, $fa2, $ft1, $ft2, $fv1, $fv2, $fg1, $fg2); $oa1 = format($oa1, 1); $foa2 = format($oa2, 1); $ta1 = format($ta1, 1); $fta2 = format($ta2, 1); $ot1 = format($ot1, 0); $fot2 = format($ot2, 0); $tt1 = format($tt1, 0); $ftt2 = format($tt2, 0); $ov1 = format($ov1, 1); $fov2 = format($ov2, 1); $tv1 = format($tv1, 1); $ftv2 = format($tv2, 1); $og1 = format($og1, 0); $fog2 = format($og2, 0); $tg1 = format($tg1, 0); $ftg2 = format($tg2, 0); CalculateTimes($trip, $i, $wp, $prevwp, $nextwp, $or1, $tr1, $or2, $tr2, $ol1, $tl1, $ol2, $tl2, $ocn, $tcn, $oat, $tat, $ovt, $tvt, $fr1, $fr2, $fl1, $fl2, $fcn, $fat, $fvt); // build the waypoint output result $dwp[] = array('id' => $wp['objid'], 'location' => '', 'name' => $wp['destination'], 'statusid' => $wp['statusid'], 'overview' => array('distance' => $oa1, 'totaldistance' => $foa2, 'typical' => $ot1, 'totaltypical' => $fot2, 'consumption' => $ov1, 'totalconsumption' => $fov2, 'average' => $og1, 'totalaverage' => $fog2, 'drivetime' => $or1, 'totaldrivetime' => $or2, 'chargetime' => $ol1, 'totalchargetime' => $ol2, 'chargeneeded' => $ocn, 'arrivaltime' => $oat, 'departuretime' => $ovt), 'theoretical' => array('distance' => $ta1, 'totaldistance' => $fta2, 'typical' => $tt1, 'totaltypical' => $ftt2, 'consumption' => $tv1, 'totalconsumption' => $ftv2, 'average' => $tg1, 'totalaverage' => $ftg2, 'drivetime' => $tr1, 'totaldrivetime' => $tr2, 'chargetime' => $tl1, 'totalchargetime' => $tl2, 'chargeneeded' => $tcn, 'arrivaltime' => $tat, 'departuretime' => $tvt), 'formating' => array('distance' => $fa1, 'totaldistance' => $fa2, 'typical' => $ft1, 'totaltypical' => $ft2, 'consumption' => $fv1, 'totalconsumption' => $fv2, 'average' => $fg1, 'totalaverage' => $fg2, 'drivetime' => $tr1, 'totaldrivetime' => $tr2, 'chargetime' => $tl1, 'totalchargetime' => $tl2, 'chargeneeded' => $tcn, 'arrivaltime' => $tat, 'departuretime' => $tvt)); //$wpchargestarted = $wpchargeneeded; } // final result $d = array('id' => $tripId, 'desc' => $trip->att('name'), 'statusid' => $statusid, 'etape' => $wpnbr, 'waypoints' => $dwp); return array("key" => "trip", "data" => $d); //return $d; }
function GetTripDetail($tripId) { //----------------------------------------- // selected trip $trip = new trip(); $trip->retrieve($tripId); $waypoint = new waypoint(); $waypoints = $waypoint->getAllObjectsArray('tripid = ' . DB::qstr($tripId), null, 'objid'); // make the result array $wpnbr = -1; $statusid = 4; $wpdistance = ''; $totaldistance = 0; $wptypical = ''; $totaltypical = 0; $wpconsumption = ''; $totalconsumption = 0; $wpaverage = ''; $wpdrivetime = ''; $totaldrivetime = 0; $wpchargetime = ''; $totalchargetime = 0; $startdrivetime = $trip->att('theoreticalstarttime'); $wpchargeneeded = 0; $wpchargestarted = 0; $wparrivaltime = ''; $wpdeparturetime = ''; $wpchargestart = 0; // build the waypoints array $dwp = null; //foreach ($waypoints as &$wp) { for ($i = 0; $i < count($waypoints); $i++) { $wp = $waypoints[array_keys($waypoints)[$i]]; //var_dump($wp); exit(); if ($statusid == 4) { $wpnbr++; $statusid = $wp['statusid']; } if ($i == 0) { // first waypoint initialize counters if ($wp['statusid'] < 4) { $startdrivetime = $trip->att('date'); $wpchargeneeded = $wp['theoreticalchargeneeded']; } else { $startdrivetime = $wp['departuretime']; $wpchargeneeded = $wp['departuretypical']; } $wpdeparturetime = date('H:i', $startdrivetime); $wpchargestarted = $wpchargeneeded; } else { // make running totals if ($wp['statusid'] == 0) { $wpdistance = $wp['theoreticaldistance']; $wptypical = $wp['theoreticaltypical']; $wpconsumption = $wp['theoreticalconsumption']; $wparrivaltime = $startdrivetime + $wp['theoreticaldrivetime'] * 60; $wpchargestart = $wpchargestarted - $wp['theoreticaltypical']; } else { $wpdistance = $wp['arrivaldistance']; $wptypical = $wpchargestarted - $wp['arrivaltypical']; $wpconsumption = $wp['arrivalconsumption']; $wparrivaltime = $wp['arrivaltime']; $wpchargestart = intval($wp['arrivaltypical']); } $totaldistance += $wpdistance; $totaltypical += $wptypical; $totalconsumption += $wpconsumption; $startdrivetime = $wparrivaltime; if ($wpdistance != 0) { $wpaverage = round($wpconsumption * 1000 / $wpdistance, 0); } else { $wpaverage = ''; } if ($wp['statusid'] < 3) { //$startdrivetime = $wparrivaltime + ($wp['theoreticalchargetime'] * 60); $startdrivetime = $wparrivaltime + CalculateChargeTime(0, $wp['theoreticalchargeneeded']) * 60; $wpchargeneeded = $wp['theoreticalchargeneeded']; } if ($wp['statusid'] == 3) { $startdrivetime = $wp['chargeendtime']; $wpchargeneeded = $wp['chargeendtypical']; } if ($wp['statusid'] == 4) { $wpchargeneeded = $wp['departuretypical']; $startdrivetime = $wp['departuretime']; } // to calculate $wpdrivetime = $wp['theoreticaldrivetime']; $totaldrivetime += $wpdrivetime; //$wpchargetime = $wp['theoreticalchargetime']; $wpchargetime = CalculateChargeTime(0, $wp['theoreticalchargeneeded']); $totalchargetime += $wpchargetime; //format the output $wpdistance = number_format($wpdistance, 1, ',', '.'); $wptypical = number_format($wptypical, 0); $wpconsumption = number_format($wpconsumption, 1, ',', '.'); $wpdrivetime = date('H:i', mktime(0, $wpdrivetime, 0, 1, 1, 2000)); if ($wpchargetime > 0) { $wpchargetime = date('H:i', mktime(0, $wpchargetime, 0, 1, 1, 2000)); } else { $wpchargetime = ''; } $wparrivaltime = date('H:i', $wparrivaltime); $wpdeparturetime = date('H:i', $startdrivetime); } // build the waypoint $dwp[] = array('id' => $wp['objid'], 'location' => '', 'name' => $wp['destination'], 'statusid' => $wp['statusid'], 'overview' => array('distance' => $wpdistance, 'totaldistance' => number_format($totaldistance, 1, ',', '.'), 'typical' => $wptypical, 'totaltypical' => $totaltypical, 'consumption' => $wpconsumption, 'totalconsumption' => number_format($totalconsumption, 1, ',', '.'), 'averageconsumption' => $wpaverage, 'drivetime' => $wpdrivetime, 'totaldrivetime' => date('H:i', mktime(0, $totaldrivetime, 0, 1, 1, 2000)), 'chargetime' => $wpchargetime, 'totalchargetime' => date('H:i', mktime(0, $totalchargetime, 0, 1, 1, 2000)), 'chargeneeded' => $wpchargeneeded, 'arrivaltime' => $wparrivaltime, 'departuretime' => $wpdeparturetime), 'theoretical' => array('arrival' => array('distance' => $wpdistance + 0.0, 'typical' => $wpchargestarted - $wp['theoreticaltypical'], 'consumption' => $wp['theoreticalconsumption'] + 0.0, 'time' => $wp['theoreticaldrivetime']), 'chargestart' => array('typical' => $wpchargestart, 'time' => ''), 'chargeend' => array('typical' => $wp['theoreticalchargeneeded'] + 0, 'time' => ''), 'departure' => array('distance' => 0.0, 'typical' => $wpchargeneeded + 0, 'consumption' => 0.0, 'time' => '')), 'effective' => array('arrival' => array('distance' => $wp['arrivaldistance'], 'typical' => $wp['arrivaltypical'], 'consumption' => $wp['arrivalconsumption'], 'time' => $wp['arrivaltime']), 'chargestart' => array('typical' => $wp['chargestarttypical'], 'time' => $wp['chargestarttime']), 'chargeend' => array('typical' => $wp['chargeendtypical'], 'time' => $wp['chargeendtime']), 'departure' => array('distance' => $wp['departuredistance'], 'typical' => $wp['departuretypical'], 'consumption' => $wp['departureconsumption'], 'time' => $wp['departuretime']))); $wpchargestarted = $wpchargeneeded; } // final result $d = array('id' => $tripId, 'desc' => $trip->att('name'), 'statusid' => $statusid, 'etape' => $wpnbr, 'waypoints' => $dwp); return array("key" => "trip", "data" => $d); //return $d; }