function CreateRoute($route, $startdate) { // routes : // 1 Thuis - La Treve - via autoroute du soleil // 2 La Treve - Nuits-Saint-Georges via Nimes // 3 La Treve - Nuits-Saint-Georges via Orange // 4 Nuits-Saint-Georges - Brecht (thuis) // 51 La Treve - Auxerre via Orange // 52 La Treve - Auxerre via Valence // 6 Auxerre - Brecht (thuis) // //$route = 4; // startdate = '2015-10-25 10:30' $uu = substr($startdate, 11, 2); $nn = substr($startdate, 14, 2); $dd = substr($startdate, 8, 2); $mm = substr($startdate, 5, 2); $jj = substr($startdate, 0, 4); echo 'Create New Trip<br>===============<br><br>'; // trip $t1 = new trip(); //$t1->att('statusid',1); if ($route == 1) { $t1->att('name', 'Thuis - La Treve - via autoroute du soleil'); } if ($route == 2) { $t1->att('name', 'La Treve - Ibis Nuits Saint Georges - via Nimes'); } if ($route == 3) { $t1->att('name', 'La Treve - Ibis Nuits Saint Georges - via Orange'); } if ($route == 4) { $t1->att('name', 'Nuits-Saint-Georges - Brecht (thuis)'); } if ($route == 51) { $t1->att('name', 'La Treve - Auxerre (via Orange)'); } if ($route == 52) { $t1->att('name', 'La Treve - Auxerre (via Valence)'); } if ($route == 6) { $t1->att('name', 'Auxerre - Brecht (thuis)'); } $t1->att('date', mktime($uu, $nn, 0, $mm, $dd, $jj)); $t1->att('car', '38855'); $t1->save(); $tripid = $t1->att('objid'); echo 'Trip ' . $t1->att('name') . ' (id : ' . $t1->att('objid') . ') saved<br>'; echo 'Create New Waypoints<br>====================<br><br>'; // waypoints if ($route == 1) { $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Brecht'); $wp->att('typeid', 1); $wp->att('statusid', 3); $wp->att('theoreticaldistance', null); $wp->att('theoreticaltypical', null); $wp->att('theoreticalconsumption', null); $wp->att('theoreticaldrivetime', null); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(373)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Metz'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 322.5); $wp->att('theoreticaltypical', 373); $wp->att('theoreticalconsumption', 70.0); $wp->att('theoreticaldrivetime', 195); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(86)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Nancy'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 79.5); $wp->att('theoreticaltypical', 86); $wp->att('theoreticalconsumption', 16.0); $wp->att('theoreticaldrivetime', 60); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(287)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Nuits-Saint-Georges'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 229.6); $wp->att('theoreticaltypical', 287); $wp->att('theoreticalconsumption', 53.0); $wp->att('theoreticaldrivetime', 130); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(225)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Vienne'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 188.5); $wp->att('theoreticaltypical', 225); $wp->att('theoreticalconsumption', 42.0); $wp->att('theoreticaldrivetime', 115); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(289)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Nimes'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 234.1); $wp->att('theoreticaltypical', 289); $wp->att('theoreticalconsumption', 54.0); $wp->att('theoreticaldrivetime', 130); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(143)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'La Trêve, Véreilles'); $wp->att('typeid', 2); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 124.0); $wp->att('theoreticaltypical', 143); $wp->att('theoreticalconsumption', 27.0); $wp->att('theoreticaldrivetime', 110); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', null); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; } if ($route == 2) { $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'La Trêve'); $wp->att('typeid', 1); $wp->att('statusid', 3); $wp->att('theoreticaldistance', null); $wp->att('theoreticaltypical', null); $wp->att('theoreticalconsumption', null); $wp->att('theoreticaldrivetime', null); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(135)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Nimes'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 124.8); $wp->att('theoreticaltypical', 135); $wp->att('theoreticalconsumption', 25.0); $wp->att('theoreticaldrivetime', 105); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(307)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Vienne'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 234.1); $wp->att('theoreticaltypical', 307); $wp->att('theoreticalconsumption', 57.0); $wp->att('theoreticaldrivetime', 135); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(237)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Nuits-Saint-Georges (Ibis)'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 189.9); $wp->att('theoreticaltypical', 237); $wp->att('theoreticalconsumption', 44.0); $wp->att('theoreticaldrivetime', 110); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(350)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; } if ($route == 3) { $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'La Trêve'); $wp->att('typeid', 1); $wp->att('statusid', 3); $wp->att('theoreticaldistance', null); $wp->att('theoreticaltypical', null); $wp->att('theoreticalconsumption', null); $wp->att('theoreticaldrivetime', null); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(200)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Orange'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 186.7); $wp->att('theoreticaltypical', 200); $wp->att('theoreticalconsumption', 37.0); $wp->att('theoreticaldrivetime', 135); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(220)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Vienne'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 184.5); $wp->att('theoreticaltypical', 220); $wp->att('theoreticalconsumption', 42.0); $wp->att('theoreticaldrivetime', 120); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(230)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Nuits-Saint-Georges (Ibis)'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 190.2); $wp->att('theoreticaltypical', 230); $wp->att('theoreticalconsumption', 44.0); $wp->att('theoreticaldrivetime', 110); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(350)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; } if ($route == 4) { $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Nuits-Saint-Georges (Ibis)'); $wp->att('typeid', 1); $wp->att('statusid', 3); $wp->att('theoreticaldistance', null); $wp->att('theoreticaltypical', null); $wp->att('theoreticalconsumption', null); $wp->att('theoreticaldrivetime', null); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(350)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Châlon-en-Champagne'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 287.3); $wp->att('theoreticaltypical', 350); $wp->att('theoreticalconsumption', 65.0); $wp->att('theoreticaldrivetime', 150); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(250)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Nivelles-Sud'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 227.8); $wp->att('theoreticaltypical', 250); $wp->att('theoreticalconsumption', 44.5); $wp->att('theoreticaldrivetime', 170); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(120)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Brecht (thuis)'); $wp->att('typeid', 2); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 103.4); $wp->att('theoreticaltypical', 120); $wp->att('theoreticalconsumption', 21.0); $wp->att('theoreticaldrivetime', 90); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', null); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; } if ($route == 51) { $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'La Trêve'); $wp->att('typeid', 1); $wp->att('statusid', 3); $wp->att('theoreticaldistance', null); $wp->att('theoreticaltypical', null); $wp->att('theoreticalconsumption', null); $wp->att('theoreticaldrivetime', null); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(210)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Orange'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 186.7); $wp->att('theoreticaltypical', 210); $wp->att('theoreticalconsumption', 40.0); $wp->att('theoreticaldrivetime', 150); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(240)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Vienne'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 184.5); $wp->att('theoreticaltypical', 240); $wp->att('theoreticalconsumption', 45.0); $wp->att('theoreticaldrivetime', 110); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(200)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Beaune'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 173.9); $wp->att('theoreticaltypical', 200); $wp->att('theoreticalconsumption', 37.0); $wp->att('theoreticaldrivetime', 110); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(188)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Auxerre (Novotel)'); $wp->att('typeid', 2); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 153.2); $wp->att('theoreticaltypical', 188); $wp->att('theoreticalconsumption', 35.0); $wp->att('theoreticaldrivetime', 95); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', null); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; } if ($route == 52) { $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'La Trêve'); $wp->att('typeid', 1); $wp->att('statusid', 3); $wp->att('theoreticaldistance', null); $wp->att('theoreticaltypical', null); $wp->att('theoreticalconsumption', null); $wp->att('theoreticaldrivetime', null); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(313)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Valence'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 272.6); $wp->att('theoreticaltypical', 313); $wp->att('theoreticalconsumption', 58.0); $wp->att('theoreticaldrivetime', 200); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(295)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Beaune'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 254.8); $wp->att('theoreticaltypical', 295); $wp->att('theoreticalconsumption', 55.0); $wp->att('theoreticaldrivetime', 170); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(188)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Auxerre (Novotel)'); $wp->att('typeid', 2); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 153.2); $wp->att('theoreticaltypical', 188); $wp->att('theoreticalconsumption', 35.0); $wp->att('theoreticaldrivetime', 95); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', null); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; } if ($route == 6) { $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Suc Auxerre (Novotel)'); $wp->att('typeid', 1); $wp->att('statusid', 3); $wp->att('theoreticaldistance', null); $wp->att('theoreticaltypical', null); $wp->att('theoreticalconsumption', null); $wp->att('theoreticaldrivetime', null); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(240)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Senlis'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 210.0); $wp->att('theoreticaltypical', 240); $wp->att('theoreticalconsumption', 42.0); $wp->att('theoreticaldrivetime', 145); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(200)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'SuC Lille'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 165.0); $wp->att('theoreticaltypical', 200); $wp->att('theoreticalconsumption', 35.0); $wp->att('theoreticaldrivetime', 100); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', CalculateChargeNeeded(200)); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; $wp = new waypoint(); $wp->att('tripid', $tripid); $wp->att('destination', 'Brecht (thuis)'); $wp->att('typeid', 3); $wp->att('statusid', 0); $wp->att('theoreticaldistance', 160.0); $wp->att('theoreticaltypical', 200); $wp->att('theoreticalconsumption', 30.0); $wp->att('theoreticaldrivetime', 110); $wp->att('theoreticalchargetime', null); $wp->att('theoreticalchargeneeded', null); $wp->save(); echo 'Waypoint ' . $wp->att('destination') . ' (id : ' . $wp->att('objid') . ') saved<br>'; } echo '<br>done<br>'; }
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; }