Public feed
#894182
function fromelmatime($string) { // convert "xx:xx:xx" to integer } function getWbTimeFromRec($recpath) { $recdata = getTimeFromRec($recpath, true); if ($recdata[1][count($recdata[1])-1][2] == 0) $time = fromelmatime($recdata[0]); else { $time = 0; for($n=1;$n<count($recdata[1]); $n++) if ($recdata[1][$n][1] == 4) $time++; $time = 1000000000 + (50 - $time); } return $time; } function getTimeFromRec($filename, $returnevents=false) { $events = array(); $max = -1; $outtime = "00:00:00"; $f = fopen($filename, "r") or die("open error!"); list( $no) = array_values( unpack("V", fread($f, 4)) ); fread($f, 32+27*$no); list( $no) = array_values(unpack("V", fread($f, 4))); for($i = 0; $i < $no; $i++) { list( $d) = array_values(unpack("d", fread($f, 8))); list( $j) = array_values(unpack("f", fread($f, 4))); list( $k) = array_values(unpack("f", fread($f, 4))); $eventss[] = array($d, $j, $k); } fclose($f); // overly long code to make sure "take flower" event is last // if inside a flower while taking the last apple this can happen. $count = count($eventss)-1; $lasttime = $eventss[$count][0]; $end = false; for($n=$count; $n>=0; $n--) { if ($eventss[$n][0] != $lasttime) break; if ($eventss[$n][2] == 0) { $end = $eventss[$n]; for($i=$n; $i<$count; $i++) $eventss[$i] = $eventss[$i+1]; $eventss[$count] = $end; break; } } // overly long code ended $events = array(); foreach($eventss as $e) { list($d, $j, $k) = $e; $events[] = array((($d * 62500 / 273)/100), (int)($j*1E40), round($k)); } $tmp = $eventss[count($eventss)-1]; $time = -1; if ($tmp[2] == 0) $time = $tmp[0]; if ($time >= 0) { $i = $time * 62500 / 273; $outtime = sprintf("%02d:%02d:%02d", $i/6000, ($i/100)%60, $i%100); } if ($returnevents) return array( $outtime, $events ); return $outtime; }