最終更新: 2026-02-28
状態: 本番稼働中
Open-Meteo archive API から窪川の気象データを日次取得し、PostgreSQL に蓄積する。
農業における積算温度計算・類似年分析・作期の気象振り返りを目的とする。
backend/apps/weather/apps/weather/models.py)| フィールド | 型 | 説明 |
|---|---|---|
| date | DateField (unique) | 日付 |
| temp_mean | FloatField nullable | 平均気温 (℃) |
| temp_max | FloatField nullable | 最高気温 (℃) |
| temp_min | FloatField nullable | 最低気温 (℃) |
| sunshine_h | FloatField nullable | 日照時間 (h) |
| precip_mm | FloatField nullable | 降水量 (mm) |
| wind_max | FloatField nullable | 最大風速 (m/s) |
| pressure_min | FloatField nullable | 最低気圧 (hPa) |
Crop.base_temp (apps/plans/models.py に追加):
/api/weather/)/api/weather/sync/{"saved": N} or {"saved": N, "errors": [...]}[
{
"date": "2026-02-27",
"temp_mean": 8.5, "temp_max": 14.2, "temp_min": 3.1,
"sunshine_h": 6.3, "precip_mm": 0.0,
"wind_max": 4.2, "pressure_min": 1008.0
}
]
/api/weather/records/?year=2025 — 年指定?start=2025-05-01&end=2025-09-30 — 日付範囲指定/api/weather/summary/?year=2025{
"year": 2025,
"monthly": [
{
"month": 1,
"temp_mean_avg": 5.2, "temp_max_avg": 10.1, "temp_min_avg": 0.8,
"precip_total": 45.0, "sunshine_total": 98.3, "wind_max": 9.5,
"hot_days": 0, "cold_days": 8, "rainy_days": 12
},
...
],
"annual": {
"temp_mean_avg": 16.1, "precip_total": 2310.0, "sunshine_total": 1850.5,
"hot_days": 12, "cold_days": 25
}
}
/api/weather/gdd/?start_date=2025-05-15 (必須) — 起算日?base_temp=10 (省略時=0) — 基準温度 ℃?end_date=2025-09-30 (省略時=昨日){
"start_date": "2025-05-15",
"end_date": "2025-09-30",
"base_temp": 10.0,
"total_gdd": 1342.5,
"records": [
{"date": "2025-05-15", "temp_mean": 18.2, "daily_gdd": 8.2, "cumulative_gdd": 8.2},
...
]
}
/api/weather/similarity/?year=2026{
"target_year": 2026,
"comparison_period": "1/1〜2/27",
"target_features": {"mean_temp": 7.3, "total_precip": 185.0, "total_sunshine": 240.5},
"similar_years": [
{
"year": 2020, "distance": 0.312,
"features": {...},
"monthly": [...]
}
]
}
# 全期間取得(初回のみ)
docker compose exec backend python manage.py fetch_weather --full
# 差分取得(最終レコード翌日〜昨日)
docker compose exec backend python manage.py fetch_weather
# 任意期間
docker compose exec backend python manage.py fetch_weather --start-date 2025-01-01 --end-date 2025-12-31
仕様:
--full: 2016-01-01 から昨日まで(初回投入用)| 項目 | 値 |
|---|---|
| パス | f/weather/weather_sync |
| スケジュール | 0 0 6 * * *(毎朝 6:00 Asia/Tokyo) |
| スクリプト | windmill/u/admin/weather_sync.flow/a.inline_script.py |
| 状態 | ✅ 本番稼働中(windmill.keinafarm.net) |
使用 Windmill Variables:
| 変数名 | 内容 |
|---|---|
u/admin/KEINASYSTEM_API_KEY |
API キー(メール機能と共用) |
u/admin/KEINASYSTEM_API_URL |
https://keinafarm.net |
/weather)使用ライブラリ: Recharts 3.7.x(frontend/package.json に登録済み)
| ファイル | 役割 |
|---|---|
backend/apps/weather/models.py |
WeatherRecord モデル |
backend/apps/weather/views.py |
5つのAPIビュー |
backend/apps/weather/urls.py |
URL設定 |
backend/apps/weather/serializers.py |
Serializer |
backend/apps/weather/admin.py |
管理画面登録 |
backend/apps/weather/migrations/0001_initial.py |
初回マイグレーション |
backend/apps/weather/management/commands/fetch_weather.py |
管理コマンド |
backend/apps/plans/migrations/0004_crop_base_temp.py |
Crop.base_temp 追加 |
frontend/src/app/weather/page.tsx |
気象画面(400行) |
windmill/u/admin/weather_sync.flow/a.inline_script.py |
Windmill Python スクリプト |
windmill/u/admin/weather_sync.flow/flow.yaml |
Windmill フロー定義 |
Crop.base_temp を使い、播種日から目標GDDに達する日を予測pressure_min は surface_pressure_min(地表気圧)。海面更正気圧とは異なるsunshine_duration は秒単位 → sunshine_h = 秒 ÷ 3600 で変換