Share via


Azure Data Manager for Agriculture で天気予報データを取り込む

天気は農業において誰でも利用できる可能性が高いサービスです。 Azure Data Manager for Agriculture は顧客に、顧客が選択した気象プロバイダーと連携する機能を提供します。

Azure Data Manager for Agriculture では、拡張機能ベースで、かつプロバイダー非依存のアプローチを使用し、現在および予測の気象データを提供します。 気象拡張機能を記述する手順に従って、選択したプロバイダーと連携することができます。

設計の概要

Azure Data Manager for Agriculture はプロバイダー非依存のアプローチで気象データを提供するため、ユーザーはプロバイダーの API に精通する必要がありません。 代わりに、プロバイダーに関係なく、同じ Azure Data Manager for Agriculture API を使用することができます。

プロバイダー非依存の API の動作に関する注意事項を次に示します。

  • 1 回の呼び出しで最大 50 か所の気象データを要求することができます。
  • 予測のデータは 15 分以内のものです。 現状のデータは 10 分以内のものです。
  • ある場所に対して最初の呼び出しが行われると、データは定義された有効期間 (TTL) キャッシュされます。
  • キャッシュに新しいデータを保つには、気象拡張機能において apiFreshnessTimeInMinutes パラメーターを使用することができます。 プラットフォームは定義された期間ジョブを実行し続け、キャッシュを更新します。 この既定値は 0 です。つまり、既定ではキャッシュに新しいデータは保持されません。

次のセクションでは気象データをフェッチし、それを Azure Data Manager for Agriculture に取り込むコマンドを示します。

手順 1: 気象拡張機能をインストールする

この拡張機能をインストールするには、Azure Resource Manager ARMClient ツールを使用して、次のコマンドを実行します。

山かっこ (<>) 内のすべての値を、ご利用のそれぞれの環境の値に置き換えてください。 現在サポートされている拡張機能 ID は IBM.TWC です。

armclient PUT /subscriptions/<subscriptionid>/resourceGroups/<resource-group-name>/providers/Microsoft.AgFoodPlatform/farmBeats/<farmbeats-resource-name>/extensions/<extensionid>?api-version=2020-05-12-preview '{}'

このインストール コマンドの出力例を次に示します。

{
      "id": "/subscriptions/<subscriptionid>/resourceGroups/<resource-group-name>/providers/Microsoft.AgFoodPlatform/farmBeats/<farmbeats-resource-name>/extensions/<extensionid>",
      "type": "Microsoft.AgFoodPlatform/farmBeats/extensions",
      "systemData": {
        "createdBy": "testuser@abc.com",
        "createdByType": "User",`        
        "createdAt": "2021-03-17T12:36:51Z",
        "lastModifiedBy": "testuser@abc.com",
        "lastModifiedByType": "User",
        "lastModifiedAt": "2021-03-17T12:36:51Z"
      },
      "properties": {
        "category": "Weather",
        "installedExtensionVersion": "1.0",
        "extensionAuthLink": "https://www.<provider.com/integration/",
        "extensionApiDocsLink": "https://docs.<provider>.com/documentation/Weather_Data/Historical_and_Climatological_Weather/latest#_daily_historical_ag_weather_v1_0"
      },
      "eTag": "92003c91-0000-0700-0000-804752e00000",
      "name": "<provider>"
}

拡張機能のインストールが完了したら、気象データを取り込むことができます。

apiFreshnessTimeInMinutes を更新する場合は、次の PowerShell コマンドを使用して拡張機能を更新します。 山かっこ内のすべての値を、それぞれの環境の値に置き換えてください。

armclient put /subscriptions/<subscriptionid>/resourceGroups/<resource-group-name>/providers/Microsoft.AgFoodPlatform/farmBeats/<farmbeats-resource-name>/<extensionid>?api-version=2021-09-01-preview '{"additionalApiProperties": {""15-day-daily-forecast"": {"apiFreshnessTimeInMinutes": <time>}, ""currents-on-demand"": {"apiFreshnessTimeInMinutes": <time>},""15-day-hourly-forecast"":{"apiFreshnessTimeInMinutes": <time>}}}'

上記の update コマンドには、パッチ操作が組み合わされています。 これは、コマンド内に記載されている API の Freshness Time のみを更新し、他の API の Freshness Time の値は以前と同じままです。

update コマンドの出力例を次に示します。

{
  "id": "/subscriptions/<subscriptionid>/resourceGroups/<resource-group-name>/providers/Microsoft.AgFoodPlatform/farmBeats/<farmbeats-resource-name>/extensions/<extensionid>",
  "type": "Microsoft.AgFoodPlatform/farmBeats/extensions",
  "systemData": {
    "createdBy": "50e74af5-3b8f-4a8c-9521-4f506b4e0c16",
    "createdByType": "User",
    "createdAt": "2022-10-10T21:28:05Z",
    "lastModifiedBy": "50e74af5-3b8f-4a8c-9521-4f506b4e0c16",
    "lastModifiedByType": "User",
    "lastModifiedAt": "2022-11-08T13:10:17Z"
  },
  "properties": {
    "extensionId": "provider",
    "extensionCategory": "Weather",
    "installedExtensionVersion": "2.0",
    "extensionApiDocsLink": "https://go.microsoft.com/fwlink/?linkid=2192974",
    "additionalApiProperties": {
      "15-day-daily-forecast": {
        "apiFreshnessTimeInMinutes": 1600
      },
      "currents-on-demand": {
        "apiFreshnessTimeInMinutes": 1600
      },
       "15-day-hourly-forecast": {
        "apiFreshnessTimeInMinutes": 1600
      }
    }
  },
  "eTag": "ea0261d0-0000-0700-0000-636a55390000",
  "name": "provider"
}

手順 2: 気象データを取得する

API にアクセスするために必要な資格情報を取得したら、Weather Data API を呼び出して気象データをフェッチする必要があります。