Compare commits
3
Commits
0.6.0
...
d6487facf4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6487facf4 | ||
|
|
86879a3219 | ||
|
|
aa0d5a7a41 |
@@ -41,7 +41,9 @@ class GismeteoApi(WeatherApi):
|
|||||||
# group values by 3 hours
|
# group values by 3 hours
|
||||||
if len(values) > 8:
|
if len(values) > 8:
|
||||||
n = 3
|
n = 3
|
||||||
values = [merge_weather_values(values[i].date, values[i : i + n]) for i in range(0, len(values), n)]
|
values = [
|
||||||
|
merge_weather_values(values[i].date, values[i : i + n], "average") for i in range(0, len(values), n)
|
||||||
|
]
|
||||||
return WeatherResponse(
|
return WeatherResponse(
|
||||||
location=location or "n/a",
|
location=location or "n/a",
|
||||||
date=date,
|
date=date,
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import statistics
|
import statistics
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
from .model import Cloudness, Precipitation, Sky, WeatherValue, WindDirectionDeg
|
from .model import Cloudness, Precipitation, Sky, WeatherValue, WindDirectionDeg
|
||||||
|
|
||||||
|
MergeMode = Literal["interval", "average"]
|
||||||
|
|
||||||
|
|
||||||
def build_weather_value(date: datetime.datetime) -> WeatherValue:
|
def build_weather_value(date: datetime.datetime) -> WeatherValue:
|
||||||
return WeatherValue(
|
return WeatherValue(
|
||||||
@@ -23,7 +26,15 @@ def build_weather_value(date: datetime.datetime) -> WeatherValue:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def merge_weather_values(date: datetime.datetime, values: list[WeatherValue]) -> WeatherValue:
|
def _merge_values(values: list[int], mode: MergeMode) -> list[int]:
|
||||||
|
return [max(values), min(values)] if mode == "interval" else [round(sum(values) / len(values))]
|
||||||
|
|
||||||
|
|
||||||
|
def merge_weather_values(
|
||||||
|
date: datetime.datetime,
|
||||||
|
values: list[WeatherValue],
|
||||||
|
mode: MergeMode = "interval",
|
||||||
|
) -> WeatherValue:
|
||||||
result = build_weather_value(date)
|
result = build_weather_value(date)
|
||||||
temperatures = []
|
temperatures = []
|
||||||
pressures = []
|
pressures = []
|
||||||
@@ -44,8 +55,8 @@ def merge_weather_values(date: datetime.datetime, values: list[WeatherValue]) ->
|
|||||||
cloudnesses.append(value.sky.cloudness)
|
cloudnesses.append(value.sky.cloudness)
|
||||||
precipitations.append(value.sky.precipitation)
|
precipitations.append(value.sky.precipitation)
|
||||||
precipitation += value.precipitation
|
precipitation += value.precipitation
|
||||||
result.temperature = [max(temperatures), min(temperatures)]
|
result.temperature = _merge_values(temperatures, mode)
|
||||||
result.pressure = [max(pressures), min(pressures)]
|
result.pressure = _merge_values(pressures, mode)
|
||||||
result.humidity = round(statistics.mean(humidities))
|
result.humidity = round(statistics.mean(humidities))
|
||||||
result.wind_speed = round(statistics.mean(wind_speeds))
|
result.wind_speed = round(statistics.mean(wind_speeds))
|
||||||
result.wind_gust = round(statistics.mean(wind_gusts))
|
result.wind_gust = round(statistics.mean(wind_gusts))
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "gallery"
|
name = "gallery"
|
||||||
description = ""
|
description = ""
|
||||||
version = "0.6.0"
|
version = "0.6.1"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = [{ name = "shmyga", email = "shmyga.z@gmail.com" }]
|
authors = [{ name = "shmyga", email = "shmyga.z@gmail.com" }]
|
||||||
requires-python = '>=3.14,<4.0'
|
requires-python = '>=3.14,<4.0'
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "gallery",
|
"name": "gallery",
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "gallery",
|
"name": "gallery",
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@popperjs/core": "^2.11.8",
|
"@popperjs/core": "^2.11.8",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gallery",
|
"name": "gallery",
|
||||||
"version": "0.6.0",
|
"version": "0.6.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack --mode production",
|
"build": "webpack --mode production",
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from tests.common.mock import MockSource
|
||||||
|
|
||||||
|
YANDEXWEATHER_MOCK_SOURCE = MockSource(
|
||||||
|
Path(__file__).parent,
|
||||||
|
{
|
||||||
|
"details": "details.html",
|
||||||
|
"suggest": "suggest.json",
|
||||||
|
},
|
||||||
|
)
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,27 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from gallery.painting.yandexweather.api import YandexWeatherApi
|
||||||
|
from tests.common.mock import create_mock_api
|
||||||
|
from tests.data.yandexweather import YANDEXWEATHER_MOCK_SOURCE
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="yandexweather_api", scope="module")
|
||||||
|
def yandexweather_api_fixture() -> YandexWeatherApi:
|
||||||
|
return create_mock_api(YandexWeatherApi, YANDEXWEATHER_MOCK_SOURCE)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_search(yandexweather_api: YandexWeatherApi):
|
||||||
|
result = await yandexweather_api.find_locations("test")
|
||||||
|
assert len(result) == 5
|
||||||
|
|
||||||
|
|
||||||
|
async def test_day(yandexweather_api: YandexWeatherApi):
|
||||||
|
result = await yandexweather_api.get_day("test", datetime.date.today())
|
||||||
|
assert len(result.values) == 4
|
||||||
|
|
||||||
|
|
||||||
|
async def test_days(yandexweather_api: YandexWeatherApi):
|
||||||
|
result = await yandexweather_api.get_days("test", 10)
|
||||||
|
assert len(result.values) == 10
|
||||||
Reference in New Issue
Block a user