Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $valley = array();
- $peak = array();
- foreach ($data as $date => $events) {
- $v_cycle = 0;
- $p_cycle = 0;
- $valley[$v_cycle] = array('blank',999);
- $peak[$p_cycle] = array('blank',-999);
- $current = 0;
- $previous = 'blank';
- $direction = 0;
- echo '<table border="1">' . PHP_EOL;
- echo ' <tr><th>Date</th><th>Time</th><th>PREDICTED</th><th>OBSERVED</th><th class="dev">DIRECTION</th></tr>' . PHP_EOL;
- foreach ($events as $time => $readings) {
- $predicted = $readings[0];
- $observed = $readings[1];
- $current = ($observed != '---' ? $observed : $predicted);
- if ($previous > $current && $previous != 'blank') {
- if ($direction == 1) {
- $peak[$p_cycle++] = array($time,$current);
- }
- $direction = -1;
- }
- if ($previous < $current && $previous != 'blank') {
- if ($direction == -1) {
- $valley[$v_cycle++] = array($time,$current);
- }
- $direction = 1;
- }
- echo ' <tr><td>' . $date . '</td><td>' . $time . '</td>';
- echo '<td>' . sprintf('%+.2f',$predicted) . '</td>';
- echo '<td>' . ($observed != '---' ? sprintf('%+.2f',$observed) : $observed) . '</td>';
- echo '<td class="dev">' . ($direction == 1 ? 'UP' : ($direction == -1 ? 'DOWN' : 'START')) . '</td>';
- $previous = $current;
- }
- for ($x=0; $x<(sizeof($valley) >= sizeof($peak) ? sizeof($valley) : sizeof($peak)); $x++) {
- echo '<tr><th colspan="2">Peak ' . ($x+1) . ': ' . $peak[$x][0] . '</th>';
- echo '<th colspan="2">Valley ' . ($x+1) . ': ' . $valley[$x][0] . '</td></tr>' . PHP_EOL;
- }
- echo '</table><hr>' . PHP_EOL;
- unset($peak);
- unset($valley);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement