Changeset 96


Ignore:
Timestamp:
10/01/07 22:37:08 (5 years ago)
Author:
nigel
Message:

Bug fixes

Location:
openweather
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • openweather/openweather.install

    r80 r96  
    99    db_query("CREATE TABLE `openweather_readings` ( 
    1010  `nid` INT( 10 ) NOT NULL , 
    11   `time` DATETIME NOT NULL , 
    12   `temp_in` decimal(3,1) NOT NULL default '0.0', 
     11  `timestamp` DATETIME NOT NULL , 
    1312  `temp_out` decimal(3,1) NOT NULL default '0.0', 
    1413  `dewpoint` decimal(3,1) NOT NULL default '0.0', 
    15   `rel_hum_in` tinyint(3) NOT NULL default '0', 
    1614  `rel_hum_out` tinyint(3) NOT NULL default '0', 
    1715  `windspeed` decimal(3,1) NOT NULL default '0.0', 
  • openweather/openweather.module

    r95 r96  
    212212  */ 
    213213function openweather_summary($nid){ 
    214   $data = db_query("SELECT * FROM {openweather_readings} WHERE nid = $nid ORDER BY `time` DESC LIMIT 1"); 
     214  $data = db_query("SELECT * FROM {openweather_readings} WHERE nid = $nid ORDER BY `timestamp` DESC LIMIT 1"); 
    215215  $data = db_fetch_object($data); 
    216216 
     
    218218  $output .= "<tr><th>Temperature</th><td>$data->temp_out dec C</td><th>Humidity</th><td>$data->rel_hum_out %</td></tr>"; 
    219219  $output .= "<tr><th>Wind speed</th><td>$data->windspeed kMh</td><th>Wind direction</th><td>".openweather_to_direction($data->wind_angle)."($data->wind_angle)</td></tr>"; 
    220   $output .= "<tr><th>Relative pressure</th><td>$data->rel_pressure</td><th>Timestamp</th><td>$data->time</td></tr>"; 
     220  $output .= "<tr><th>Relative pressure</th><td>$data->rel_pressure</td><th>Timestamp</th><td>$data->timestamp</td></tr>"; 
    221221  $output .= "</table>"; 
    222222  return $output; 
     
    262262  print "Time, Value\n"; 
    263263  foreach($results as $row){ 
    264     print '"'.$row->time.'",'.$row->value."\n"; 
     264    print '"'.$row->timestamp.'",'.$row->value."\n"; 
    265265  } 
    266266} 
     
    271271function openweather_get_values($node){ 
    272272  $res = array(); 
    273   $results = db_query("SELECT * FROM {openweather_readings} WHERE nid = %d ORDER BY time DESC", $node->nid); 
     273  $results = db_query("SELECT * FROM {openweather_readings} WHERE nid = %d ORDER BY timestamp DESC", $node->nid); 
    274274 
    275275  while ($row = db_fetch_object($results)){ 
     
    299299  $last = reset($values); 
    300300  $row = $last; 
    301   $target = strtotime($row->time); // Set the first target 
     301  $target = strtotime($row->timestamp); // Set the first target 
    302302  $value = $row->value; // We know what the first reading is! 
    303303 
     
    308308    $target -= $days*60*60*24; 
    309309 
    310     while ( !($row === false) && strtotime($row->time) > $target){ 
     310    while ( !($row === false) && strtotime($row->timestamp) > $target){ 
    311311      $last = $row; 
    312312      $row = next($values); 
     
    315315      break; 
    316316    } else { 
    317       $timeBetween = (strtotime( $last->time ) - strtotime( $row->time )); 
    318       $timeToTarget = $target - strtotime( $row->time ); 
     317      $timeBetween = (strtotime( $last->timestamp ) - strtotime( $row->timestamp )); 
     318      $timeToTarget = $target - strtotime( $row->timestamp ); 
    319319      $value = $row->value + (($last->value - $row->value)/$timeBetween*$timeToTarget); 
    320320      $entry = new StdClass(); 
     
    391391    // Check person owns or can write to entry 
    392392 
    393     return db_query("INSERT INTO {openweather_readings} (nid, `time`, temp_out, rel_hum_out, windspeed, wind_angle, wind_chill, rain_1h, rel_pressure, dewpoint) VALUES (%d, '%s', %s, %s, %s, %s, %s, %s, %s, %s)", $nid, $data['timestamp'], $data['temp'], $data['rel_hum'], $data['windspeed'], $data['wind_angle'], $data['wind_chill'], $data['rain_1h'], $data['rel_pressure'], $data['dewpoint']); 
     393    return db_query("INSERT INTO {openweather_readings} (nid, `timestamp`, temp_out, rel_hum_out, windspeed, wind_angle, wind_chill, rain_1h, rel_pressure, dewpoint) VALUES (%d, '%s', %s, %s, %s, %s, %s, %s, %s, %s)", $nid, $data['timestamp'], $data['temp'], $data['rel_hum'], $data['windspeed'], $data['wind_angle'], $data['wind_chill'], $data['rain_1h'], $data['rel_pressure'], $data['dewpoint']); 
    394394  } else { 
    395395    return false; 
     
    439439  } 
    440440 
    441   $r = db_query("SELECT time(`time`) AS `timevalue`, unix_timestamp(`time`) as `timestamp`, $type FROM {openweather_readings} WHERE nid = $nid ORDER BY `time` DESC LIMIT 144" ); 
     441  $r = db_query("SELECT time(`timestamp`) AS `timevalue`, unix_timestamp(`timestamp`) as `utimestamp`, $type FROM {openweather_readings} WHERE nid = $nid ORDER BY `timestamp` DESC LIMIT 144" ); 
    442442 
    443443  #$results = openweather_get_values($node); 
     
    456456  $minY = null; 
    457457  while ($e = db_fetch_object($r)) { 
    458     $g->x_data = array_merge($g->x_data, array($e->timevalue=>$e->timestamp)); 
     458    $g->x_data = array_merge($g->x_data, array($e->timevalue=>$e->utimestamp)); 
    459459    $g->y_data[$type][] = $e->$type; 
    460     //echo $e->$type.",".$e->timevalue.",".$e->timestamp."<br>"; 
     460    //echo $e->$type.",".$e->timevalue.",".$e->utimestamp."<br>"; 
    461461    if ($minY == null || $e->$type < $minY) $minY = $e->$type; 
    462462  } 
Note: See TracChangeset for help on using the changeset viewer.