Skip to content

Commit

Permalink
Added daily sunrise and sunset values to forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
briis committed Apr 27, 2024
1 parent 358ae09 commit e2b89f5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
8 changes: 5 additions & 3 deletions php/forecast_visualcrossing.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@
$jobj_fcst->native_precipitation = $value["precip"];
$jobj_fcst->precipitation_probability = $value["precipprob"];
$jobj_fcst->native_pressure = $value["pressure"];
$jobj_fcst->sunriseepoch = $value["sunriseEpoch"];
$jobj_fcst->sunsetepoch = $value["sunsetEpoch"];
$jobj_fcst->wind_bearing = $value["winddir"];
$jobj_fcst->native_wind_speed = kmh2ms($value["windspeed"]);
$jobj_fcst->native_wind_gust = kmh2ms($value["windgust"]);

$sql = "INSERT INTO `forecast_daily` (`day_num`, `datetime`, `temperature`, `temp_low`, `description`, `icon`, `precipitation_probability`, `precipitation`, `pressure`, `wind_bearing`, `wind_speed`, `wind_gust`) ";
$sql = $sql . "VALUES (".$day_num.",'".$jobj_fcst->datetime."',".$jobj_fcst->native_temperature.",".$jobj_fcst->native_templow.",'".$jobj_fcst->description."','".$jobj_fcst->icon."',".$jobj_fcst->precipitation_probability."," .$jobj_fcst->native_precipitation."," .$jobj_fcst->native_pressure.",".$jobj_fcst->wind_bearing.",".$jobj_fcst->native_wind_speed.",".$jobj_fcst->native_wind_gust.") ";
$sql = $sql . "ON DUPLICATE KEY UPDATE `datetime`='".$jobj_fcst->datetime."', `temperature`=".$jobj_fcst->native_temperature.", `temp_low`=".$jobj_fcst->native_templow.", `description`='".$jobj_fcst->description."', `icon`='".$jobj_fcst->icon."', `precipitation_probability`=".$jobj_fcst->precipitation_probability.", `precipitation`=".$jobj_fcst->native_precipitation.", `pressure`=".$jobj_fcst->native_pressure.", `wind_bearing`=".$jobj_fcst->wind_bearing.", `wind_speed`=".$jobj_fcst->native_wind_speed.", `wind_gust`=".$jobj_fcst->native_wind_gust;
$sql = "INSERT INTO `forecast_daily` (`day_num`, `datetime`, `temperature`, `temp_low`, `description`, `icon`, `precipitation_probability`, `precipitation`, `pressure`, `sunriseepoch`, `sunsetepoch`, `wind_bearing`, `wind_speed`, `wind_gust`) ";
$sql = $sql . "VALUES (".$day_num.",'".$jobj_fcst->datetime."',".$jobj_fcst->native_temperature.",".$jobj_fcst->native_templow.",'".$jobj_fcst->description."','".$jobj_fcst->icon."',".$jobj_fcst->precipitation_probability."," .$jobj_fcst->native_precipitation."," .$jobj_fcst->native_pressure.",".$jobj_fcst->sunriseepoch.",".$jobj_fcst->sunsetepoch.",".$jobj_fcst->wind_bearing.",".$jobj_fcst->native_wind_speed.",".$jobj_fcst->native_wind_gust.") ";
$sql = $sql . "ON DUPLICATE KEY UPDATE `datetime`='".$jobj_fcst->datetime."', `temperature`=".$jobj_fcst->native_temperature.", `temp_low`=".$jobj_fcst->native_templow.", `description`='".$jobj_fcst->description."', `icon`='".$jobj_fcst->icon."', `precipitation_probability`=".$jobj_fcst->precipitation_probability.", `precipitation`=".$jobj_fcst->native_precipitation.", `pressure`=".$jobj_fcst->native_pressure.", `sunriseepoch`=".$jobj_fcst->sunriseepoch.", `sunsetepoch`=".$jobj_fcst->sunsetepoch.", `wind_bearing`=".$jobj_fcst->wind_bearing.", `wind_speed`=".$jobj_fcst->native_wind_speed.", `wind_gust`=".$jobj_fcst->native_wind_gust;
++$day_num;

if (!mysqli_query($conn, $sql)) {
Expand Down
38 changes: 38 additions & 0 deletions pymeteobridgesql/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ class ForecastHourly:
wind_gust: float
uv_index: float

def to_dict(self):
return {
"hour_num": self.hour_num,
"datetime": self.datetime,
"temperature": self.temperature,
"apparent_temperature": self.apparent_temperature,
"humidity": self.humidity,
"description": self.description,
"icon": self.icon,
"precipitation_probability": self.precipitation_probability,
"precipitation": self.precipitation,
"pressure": self.pressure,
"wind_bearing": self.wind_bearing,
"wind_speed": self.wind_speed,
"wind_gust": self.wind_gust,
"uv_index": self.uv_index,
}

@dataclass(frozen=True)
class ForecastDaily:
day_num: int
Expand All @@ -254,10 +272,30 @@ class ForecastDaily:
precipitation_probability: int
precipitation: float
pressure: float
sunriseepoch: int
sunsetepoch: int
wind_bearing: int
wind_speed: float
wind_gust: float

def to_dict(self):
return {
"day_num": self.day_num,
"datetime": self.datetime,
"temperature": self.temperature,
"temp_low": self.temp_low,
"description": self.description,
"icon": self.icon,
"precipitation_probability": self.precipitation_probability,
"precipitation": self.precipitation,
"pressure": self.pressure,
"sunriseepoch": self.sunriseepoch,
"sunsetepoch": self.sunsetepoch,
"wind_bearing": self.wind_bearing,
"wind_speed": self.wind_speed,
"wind_gust": self.wind_gust,
}

@dataclass(frozen=True)
class StationData:
ID: str
Expand Down
2 changes: 2 additions & 0 deletions sql/create_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ CREATE TABLE `forecast_daily` (
`precipitation_probability` INT NULL DEFAULT NULL ,
`precipitation` FLOAT NULL DEFAULT NULL ,
`pressure` FLOAT NULL DEFAULT NULL ,
`sunriseepoch` INT NULL DEFAULT NULL ,
`sunsetepoch` INT NULL DEFAULT NULL ,
`wind_bearing` INT NULL DEFAULT NULL ,
`wind_speed` FLOAT NULL DEFAULT NULL ,
`wind_gust` FLOAT NULL DEFAULT NULL ,
Expand Down

0 comments on commit e2b89f5

Please sign in to comment.