Skip to content

Commit

Permalink
Schedule Criteria: weather "clear sky" condition does not match (#3487)
Browse files Browse the repository at this point in the history
relates to xibosignage/xibo#3487

- Updated the weather schedule criteria's and XMDS getWeather's prefix.
  • Loading branch information
nadzpogi committed Oct 1, 2024
1 parent 94071ae commit c1b4017
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions lib/Connector/OpenWeatherMapConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ private static function cardinalDirections()
public function onScheduleCriteriaRequest(ScheduleCriteriaRequestInterface $event): void
{
// Initialize Open Weather Schedule Criteria parameters
$event->addType('openweathermap', __('Weather'))
->addMetric('owm_weather_condition', __('Weather Condition'))
$event->addType('weather', __('Weather'))
->addMetric('weather_condition', __('Weather Condition'))
->addValues('dropdown', [
'Thunderstorm' => __('Thunderstorm'),
'Drizzle' => __('Drizzle'),
Expand All @@ -674,17 +674,17 @@ public function onScheduleCriteriaRequest(ScheduleCriteriaRequestInterface $even
'Clear' => __('Clear'),
'Clouds' => __('Clouds')
])
->addMetric('owm_temp_imperial', __('Temperature (Imperial)'))
->addMetric('weather_temp_imperial', __('Temperature (Imperial)'))
->addValues('number', [])
->addMetric('owm_temp_metric', __('Temperature (Metric)'))
->addMetric('weather_temp_metric', __('Temperature (Metric)'))
->addValues('number', [])
->addMetric('owm_feels_like_imperial', __('Apparent Temperature (Imperial)'))
->addMetric('weather_feels_like_imperial', __('Apparent Temperature (Imperial)'))
->addValues('number', [])
->addMetric('owm_feels_like_metric', __('Apparent Temperature (Metric)'))
->addMetric('weather_feels_like_metric', __('Apparent Temperature (Metric)'))
->addValues('number', [])
->addMetric('owm_wind_speed', __('Wind Speed'))
->addMetric('weather_wind_speed', __('Wind Speed'))
->addValues('number', [])
->addMetric('owm_wind_direction', __('Wind Direction'))
->addMetric('weather_wind_direction', __('Wind Direction'))
->addValues('dropdown', [
'N' => __('North'),
'NE' => __('Northeast'),
Expand All @@ -695,13 +695,13 @@ public function onScheduleCriteriaRequest(ScheduleCriteriaRequestInterface $even
'W' => __('West'),
'NW' => __('Northwest'),
])
->addMetric('owm_wind_degrees', __('Wind Direction (degrees)'))
->addMetric('weather_wind_degrees', __('Wind Direction (degrees)'))
->addValues('number', [])
->addMetric('owm_humidity', __('Humidity (Percent)'))
->addMetric('weather_humidity', __('Humidity (Percent)'))
->addValues('number', [])
->addMetric('owm_pressure', __('Pressure'))
->addMetric('weather_pressure', __('Pressure'))
->addValues('number', [])
->addMetric('owm_visibility', __('Visibility (meters)'))
->addMetric('weather_visibility', __('Visibility (meters)'))
->addValues('number', []);
}

Expand All @@ -720,7 +720,7 @@ private function processXmdsWeatherData($item, $unit, $requestUnit): array
$data = array();

// format the weather condition
$data['owm_weather_condition'] = str_replace(' ', '_', strtolower($item['weather'][0]['main']));
$data['weather_condition'] = str_replace(' ', '_', strtolower($item['weather'][0]['main']));

// Temperature
// imperial = F
Expand All @@ -733,50 +733,50 @@ private function processXmdsWeatherData($item, $unit, $requestUnit): array
$apparentTempMetric = ($apparentTempImperial - 32) * 5 / 9;

// Round those temperature values
$data['owm_temp_imperial'] = round($tempImperial, 0);
$data['owm_feels_like_imperial'] = round($apparentTempImperial, 0);
$data['owm_temp_metric'] = round($tempMetric, 0);
$data['owm_feels_like_metric'] = round($apparentTempMetric, 0);
$data['weather_temp_imperial'] = round($tempImperial, 0);
$data['weather_feels_like_imperial'] = round($apparentTempImperial, 0);
$data['weather_temp_metric'] = round($tempMetric, 0);
$data['weather_feels_like_metric'] = round($apparentTempMetric, 0);


// Humidity
$data['owm_humidity'] = $item['humidity'];
$data['weather_humidity'] = $item['humidity'];

// Pressure
// received in hPa, display in mB
$data['owm_pressure'] = $item['pressure'] / 100;
$data['weather_pressure'] = $item['pressure'] / 100;

// Wind
// metric = meters per second
// imperial = miles per hour
$data['owm_wind_speed'] = $item['wind_speed'] ?? $item['speed'] ?? null;
$data['owm_wind_degrees'] = $item['wind_deg'] ?? $item['deg'] ?? null;
$data['weather_wind_speed'] = $item['wind_speed'] ?? $item['speed'] ?? null;
$data['weather_wind_degrees'] = $item['wind_deg'] ?? $item['deg'] ?? null;

if ($requestUnit === 'metric' && $windSpeedUnit !== 'MPS') {
// We have MPS and need to go to something else
if ($windSpeedUnit === 'MPH') {
// Convert MPS to MPH
$data['owm_wind_degrees'] = round($data['owm_wind_degrees'] * 2.237, 2);
$data['weather_wind_degrees'] = round($data['weather_wind_degrees'] * 2.237, 2);
} else if ($windSpeedUnit === 'KPH') {
// Convert MPS to KPH
$data['owm_wind_degrees'] = round($data['owm_wind_degrees'] * 3.6, 2);
$data['weather_wind_degrees'] = round($data['weather_wind_degrees'] * 3.6, 2);
}
} else if ($requestUnit === 'imperial' && $windSpeedUnit !== 'MPH') {
if ($windSpeedUnit === 'MPS') {
// Convert MPH to MPS
$data['owm_wind_degrees'] = round($data['owm_wind_degrees'] / 2.237, 2);
$data['weather_wind_degrees'] = round($data['weather_wind_degrees'] / 2.237, 2);
} else if ($windSpeedUnit === 'KPH') {
// Convert MPH to KPH
$data['owm_wind_degrees'] = round($data['owm_wind_degrees'] * 1.609344, 2);
$data['weather_wind_degrees'] = round($data['weather_wind_degrees'] * 1.609344, 2);
}
}

// Wind direction
$data['owm_wind_direction'] = '--';
if ($data['owm_wind_degrees'] !== null && $data['owm_wind_degrees'] !== 0) {
$data['weather_wind_direction'] = '--';
if ($data['weather_wind_degrees'] !== null && $data['weather_wind_degrees'] !== 0) {
foreach (self::cardinalDirections() as $dir => $angles) {
if ($data['owm_wind_degrees'] >= $angles[0] && $data['owm_wind_degrees'] < $angles[1]) {
$data['owm_wind_direction'] = $dir;
if ($data['weather_wind_degrees'] >= $angles[0] && $data['weather_wind_degrees'] < $angles[1]) {
$data['weather_wind_direction'] = $dir;
break;
}
}
Expand All @@ -785,17 +785,17 @@ private function processXmdsWeatherData($item, $unit, $requestUnit): array
// Visibility
// metric = meters
// imperial = meters?
$data['owm_visibility'] = $item['visibility'] ?? '--';
$data['weather_visibility'] = $item['visibility'] ?? '--';

if ($data['owm_visibility'] !== '--') {
if ($data['weather_visibility'] !== '--') {
// Always in meters
if ($visibilityDistanceUnit === 'mi') {
// Convert meters to miles
$data['owm_visibility'] = $data['owm_visibility'] / 1609;
$data['weather_visibility'] = $data['weather_visibility'] / 1609;
} else {
if ($visibilityDistanceUnit === 'km') {
// Convert meters to KM
$data['owm_visibility'] = $data['owm_visibility'] / 1000;
$data['weather_visibility'] = $data['weather_visibility'] / 1000;
}
}
}
Expand Down

0 comments on commit c1b4017

Please sign in to comment.