Changeset 96
- Timestamp:
- 10/01/07 22:37:08 (5 years ago)
- Location:
- openweather
- Files:
-
- 2 edited
-
openweather.install (modified) (1 diff)
-
openweather.module (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
openweather/openweather.install
r80 r96 9 9 db_query("CREATE TABLE `openweather_readings` ( 10 10 `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 , 13 12 `temp_out` decimal(3,1) NOT NULL default '0.0', 14 13 `dewpoint` decimal(3,1) NOT NULL default '0.0', 15 `rel_hum_in` tinyint(3) NOT NULL default '0',16 14 `rel_hum_out` tinyint(3) NOT NULL default '0', 17 15 `windspeed` decimal(3,1) NOT NULL default '0.0', -
openweather/openweather.module
r95 r96 212 212 */ 213 213 function 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"); 215 215 $data = db_fetch_object($data); 216 216 … … 218 218 $output .= "<tr><th>Temperature</th><td>$data->temp_out dec C</td><th>Humidity</th><td>$data->rel_hum_out %</td></tr>"; 219 219 $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>"; 221 221 $output .= "</table>"; 222 222 return $output; … … 262 262 print "Time, Value\n"; 263 263 foreach($results as $row){ 264 print '"'.$row->time .'",'.$row->value."\n";264 print '"'.$row->timestamp.'",'.$row->value."\n"; 265 265 } 266 266 } … … 271 271 function openweather_get_values($node){ 272 272 $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); 274 274 275 275 while ($row = db_fetch_object($results)){ … … 299 299 $last = reset($values); 300 300 $row = $last; 301 $target = strtotime($row->time ); // Set the first target301 $target = strtotime($row->timestamp); // Set the first target 302 302 $value = $row->value; // We know what the first reading is! 303 303 … … 308 308 $target -= $days*60*60*24; 309 309 310 while ( !($row === false) && strtotime($row->time ) > $target){310 while ( !($row === false) && strtotime($row->timestamp) > $target){ 311 311 $last = $row; 312 312 $row = next($values); … … 315 315 break; 316 316 } 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 ); 319 319 $value = $row->value + (($last->value - $row->value)/$timeBetween*$timeToTarget); 320 320 $entry = new StdClass(); … … 391 391 // Check person owns or can write to entry 392 392 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']); 394 394 } else { 395 395 return false; … … 439 439 } 440 440 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" ); 442 442 443 443 #$results = openweather_get_values($node); … … 456 456 $minY = null; 457 457 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)); 459 459 $g->y_data[$type][] = $e->$type; 460 //echo $e->$type.",".$e->timevalue.",".$e-> timestamp."<br>";460 //echo $e->$type.",".$e->timevalue.",".$e->utimestamp."<br>"; 461 461 if ($minY == null || $e->$type < $minY) $minY = $e->$type; 462 462 }
Note: See TracChangeset
for help on using the changeset viewer.
