Advertisement
Guest User

Untitled

a guest
Nov 15th, 2010
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. $valley = array();
  2. $peak = array();
  3.  
  4. foreach ($data as $date => $events) {
  5.     $v_cycle = 0;
  6.     $p_cycle = 0;
  7.  
  8.     $valley[$v_cycle] = array('blank',999);
  9.     $peak[$p_cycle] = array('blank',-999);
  10.  
  11.     $current = 0;
  12.     $previous = 'blank';
  13.     $direction = 0;
  14.  
  15.     echo '<table border="1">' . PHP_EOL;
  16.     echo ' <tr><th>Date</th><th>Time</th><th>PREDICTED</th><th>OBSERVED</th><th class="dev">DIRECTION</th></tr>' . PHP_EOL;
  17.  
  18.     foreach ($events as $time => $readings) {  
  19.         $predicted = $readings[0];
  20.         $observed = $readings[1];
  21.         $current = ($observed != '---' ? $observed : $predicted);
  22.  
  23.         if ($previous > $current && $previous != 'blank') {
  24.             if ($direction == 1) {
  25.                 $peak[$p_cycle++] = array($time,$current);
  26.             }
  27.             $direction = -1;
  28.         }
  29.         if ($previous < $current && $previous != 'blank') {
  30.             if ($direction == -1) {
  31.                 $valley[$v_cycle++] = array($time,$current);
  32.             }
  33.             $direction = 1;
  34.         }
  35.  
  36.         echo ' <tr><td>' . $date . '</td><td>' . $time . '</td>';
  37.         echo '<td>' . sprintf('%+.2f',$predicted) . '</td>';
  38.         echo '<td>' . ($observed != '---' ? sprintf('%+.2f',$observed) : $observed) . '</td>';
  39.         echo '<td class="dev">' . ($direction == 1 ? 'UP' : ($direction == -1 ? 'DOWN' : 'START')) . '</td>';
  40.  
  41.         $previous = $current;
  42.     }
  43.  
  44.     for ($x=0; $x<(sizeof($valley) >= sizeof($peak) ? sizeof($valley) : sizeof($peak)); $x++) {
  45.         echo '<tr><th colspan="2">Peak ' . ($x+1) . ': ' . $peak[$x][0] . '</th>';
  46.         echo '<th colspan="2">Valley ' . ($x+1) . ': ' . $valley[$x][0] . '</td></tr>' . PHP_EOL;
  47.     }
  48.     echo '</table><hr>' . PHP_EOL;
  49.    
  50.     unset($peak);
  51.     unset($valley);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement