Skip to content

Commit

Permalink
feat(weather/smhi): calculate apparent temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySails committed Aug 28, 2022
1 parent 4915ad8 commit 48756e8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/default/weather/providers/smhi.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ WeatherProvider.register("smhi", {
return `https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/${lon}/lat/${lat}/data.json`;
},

/** Calculates the apparent temperature based on known atmospheric data. */
calculateApparentTemperature(weatherData) {
const Ta = this.paramValue(weatherData, "t");
const rh = this.paramValue(weatherData, "r");
const ws = this.paramValue(weatherData, "ws");
const p = (rh / 100) * 6.105 * Math.E * ((17.27 * Ta) / (237.7 + Ta))

return Ta + 0.33 * p - 0.7 * ws - 4
},

/**
* Converts the returned data into a WeatherObject with required properties set for both current weather and forecast.
* The returned units is always in metric system.
Expand All @@ -128,6 +138,7 @@ WeatherProvider.register("smhi", {
currentWeather.windSpeed = this.paramValue(weatherData, "ws");
currentWeather.windDirection = this.paramValue(weatherData, "wd");
currentWeather.weatherType = this.convertWeatherType(this.paramValue(weatherData, "Wsymb2"), currentWeather.isDayTime());
currentWeather.feelsLikeTemp = this.calculateAT(weatherData);

// Determine the precipitation amount and category and update the
// weatherObject with it, the valuetype to use can be configured or uses
Expand Down

2 comments on commit 48756e8

@majorfrog
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	currentWeather.feelsLikeTemp = this.calculateAT(weatherData);

should be
currentWeather.feelsLikeTemp = this.calculateApparentTemperature(weatherData);

@SkySails
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well of course, thanks for pointing it out! Will correct this.

Please sign in to comment.