Skip to content

Commit

Permalink
Tests + readme
Browse files Browse the repository at this point in the history
  • Loading branch information
agniveshadhikari committed May 18, 2021
1 parent 8617cf8 commit 4e56b77
Show file tree
Hide file tree
Showing 21 changed files with 3,845 additions and 1,350 deletions.
143 changes: 142 additions & 1 deletion sdk/agrifood/azure-agrifood-farming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,148 @@ client = FarmBeatsClient(endpoint="https://<my-account-name>.farmbeats.azure.net

## Examples

The following section shows you how to initialize and authenticate your client, then get all of your type-defs.
### Create a Farmer
Once you have authenticated and created the client object as shown in the [Authenticate the client](#Authenticate-the-client)
section, you can create a farmer within the FarmBeats resource like this:

```python
from azure.agrifood.farming.models import Farmer

farmer = client.farmers.create_or_update(
farmer_id="farmer-1",
body=Farmer(
name="Contoso Farmer",
description="Your custom farmer description here",
status="Active",
properties={
"your-custom-key": "queryable value",
}
)
)
```

### Create a Farm


```python
from azure.agrifood.farming.models import Farm

farm = client.farms.create_or_update(
farmer_id=farmer.id,
farm_id="farm-1",
body=Farm(
name="Contoso Westlake Farm",
properties={
"location": "Westlake",
"country": "USA"
}
)
)
```

### Create a Season

```python
from azure.agrifood.farming.models import Season
from isodate.tzinfo import Utc
from datetime import datetime

season = client.seasons.create_or_update(
season_id="season-summer-2021",
body=Season(
start_date_time=datetime(2021, 4, 1, tzinfo=Utc()),
end_date_time=datetime(2021, 8, 31, tzinfo=Utc()),
name="Summer of 2021",
year=2021
)
)
```

### Create a Seasonal Field

```python
from azure.agrifood.farming.models import SeasonalField

seasonal_field = client.seasonal_fields.create_or_update(
farmer_id=farmer.id,
seasonal_field_id="westlake-summer-2021",
body=SeasonalField(
farm_id=farm.id,
season_id=season.id
)
)
```

### Create a Boundary

```python
from azure.agrifood.farming.models import Boundary, Polygon

boundary = client.boundaries.create_or_update(
farmer_id=farmer.id,
boundary_id="westlake-boundary-1",
body=Boundary(
parent_id=seasonal_field.id,
geometry=Polygon(
coordinates=[
[
[73.70457172393799, 20.545385304358106],
[73.70457172393799, 20.545385304358106],
[73.70448589324951, 20.542411534243367],
[73.70877742767334, 20.541688176010233],
[73.71023654937744, 20.545083911372505],
[73.70663166046143, 20.546992723579137],
[73.70457172393799, 20.545385304358106],
]
]
)
)
)
```

### Ingest Satellite Imagery

```python
from isodate.tzinfo import Utc
from datetime import datetime

from azure.agrifood.farming.models import SatelliteData,

# Queue the job
satellite_job_poller = client.scenes.begin_create_satellite_data_ingestion_job(
job_id="westlake-boundary-1-lai-jan2020",
body=SatelliteDataIngestionJob(
farmer_id=farmer.id,
boundary_id=boundary.id,
start_date_time=datetime(2020, 1, 1, tzinfo=Utc()),
end_date_time=datetime(2020, 1, 31, tzinfo=Utc()),
data=SatelliteData(
image_names=[
"LAI"
]
)
)
)

# Wait for the job to terminate
satellite_job = satellite_job_poller.result()
```

### Get Ingested Satellite Scenes

```python
scenes = client.scenes.list(
farmer_id=farmer.id,
boundary_id=boundary.id,
start_date_time=datetime(2020, 1, 1, tzinfo=Utc()),
end_date_time=datetime(2020, 1, 31, tzinfo=Utc()),
)

for scene in scenes:
bands = [image_file.name for image_file in scene.image_files]
bands_str = ", ".join(bands)
print(f"Scene at {scene.scene_date_time} has the bands {bands_str}")
```

## Troubleshooting

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ interactions:
User-Agent:
- azsdk-python-agrifood-farming/1.0.0b1 Python/3.7.4 (Windows-10-10.0.19041-SP0)
method: PATCH
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer?api-version=2021-03-31-preview
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer-farmer-ops?api-version=2021-03-31-preview
response:
body:
string: '{"id":"test-farmer","eTag":"01002150-0000-0600-0000-60a2e4450000","status":"Sample
Status","createdDateTime":"2021-05-17T21:46:45Z","modifiedDateTime":"2021-05-17T21:46:45Z","name":"Test
string: '{"id":"test-farmer-farmer-ops","eTag":"0000b216-0000-0600-0000-60a42f410000","status":"Sample
Status","createdDateTime":"2021-05-18T21:18:57Z","modifiedDateTime":"2021-05-18T21:18:57Z","name":"Test
Farmer","description":"Farmer created during testing.","properties":{"foo":"bar","numeric
one":1,"1":"numeric key"}}'
headers:
Expand All @@ -32,15 +32,15 @@ interactions:
connection:
- keep-alive
content-length:
- '303'
- '314'
content-type:
- application/json; charset=utf-8
date:
- Mon, 17 May 2021 21:46:45 GMT
- Tue, 18 May 2021 21:18:57 GMT
etag:
- 01002150-0000-0600-0000-60a2e4450000
- 0000b216-0000-0600-0000-60a42f410000
location:
- http://sdk-live-test-agadhika-second.farmbeats.azure.net/farmers/test-farmer
- http://sdk-live-test-agadhika-second.farmbeats.azure.net/farmers/test-farmer-farmer-ops
server:
- nginx/1.19.1
strict-transport-security:
Expand All @@ -60,11 +60,11 @@ interactions:
User-Agent:
- azsdk-python-agrifood-farming/1.0.0b1 Python/3.7.4 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer?api-version=2021-03-31-preview
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer-farmer-ops?api-version=2021-03-31-preview
response:
body:
string: '{"id":"test-farmer","eTag":"01002150-0000-0600-0000-60a2e4450000","status":"Sample
Status","createdDateTime":"2021-05-17T21:46:45Z","modifiedDateTime":"2021-05-17T21:46:45Z","name":"Test
string: '{"id":"test-farmer-farmer-ops","eTag":"0000b216-0000-0600-0000-60a42f410000","status":"Sample
Status","createdDateTime":"2021-05-18T21:18:57Z","modifiedDateTime":"2021-05-18T21:18:57Z","name":"Test
Farmer","description":"Farmer created during testing.","properties":{"foo":"bar","numeric
one":1,"1":"numeric key"}}'
headers:
Expand All @@ -75,11 +75,11 @@ interactions:
connection:
- keep-alive
content-length:
- '303'
- '314'
content-type:
- application/json; charset=utf-8
date:
- Mon, 17 May 2021 21:46:46 GMT
- Tue, 18 May 2021 21:18:58 GMT
server:
- nginx/1.19.1
strict-transport-security:
Expand Down Expand Up @@ -109,11 +109,11 @@ interactions:
User-Agent:
- azsdk-python-agrifood-farming/1.0.0b1 Python/3.7.4 (Windows-10-10.0.19041-SP0)
method: PATCH
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer?api-version=2021-03-31-preview
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer-farmer-ops?api-version=2021-03-31-preview
response:
body:
string: '{"id":"test-farmer","eTag":"01002350-0000-0600-0000-60a2e4470000","status":"Sample
Status","createdDateTime":"2021-05-17T21:46:45Z","modifiedDateTime":"2021-05-17T21:46:47Z","name":"Test
string: '{"id":"test-farmer-farmer-ops","eTag":"0000b316-0000-0600-0000-60a42f430000","status":"Sample
Status","createdDateTime":"2021-05-18T21:18:57Z","modifiedDateTime":"2021-05-18T21:18:59Z","name":"Test
Farmer Updated","description":"Farmer created during testing.","properties":{"foo":"bar","numeric
one":1,"1":"numeric key"}}'
headers:
Expand All @@ -124,11 +124,11 @@ interactions:
connection:
- keep-alive
content-length:
- '311'
- '322'
content-type:
- application/json; charset=utf-8
date:
- Mon, 17 May 2021 21:46:48 GMT
- Tue, 18 May 2021 21:18:59 GMT
server:
- nginx/1.19.1
strict-transport-security:
Expand All @@ -152,11 +152,11 @@ interactions:
User-Agent:
- azsdk-python-agrifood-farming/1.0.0b1 Python/3.7.4 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer?api-version=2021-03-31-preview
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer-farmer-ops?api-version=2021-03-31-preview
response:
body:
string: '{"id":"test-farmer","eTag":"01002350-0000-0600-0000-60a2e4470000","status":"Sample
Status","createdDateTime":"2021-05-17T21:46:45Z","modifiedDateTime":"2021-05-17T21:46:47Z","name":"Test
string: '{"id":"test-farmer-farmer-ops","eTag":"0000b316-0000-0600-0000-60a42f430000","status":"Sample
Status","createdDateTime":"2021-05-18T21:18:57Z","modifiedDateTime":"2021-05-18T21:18:59Z","name":"Test
Farmer Updated","description":"Farmer created during testing.","properties":{"foo":"bar","numeric
one":1,"1":"numeric key"}}'
headers:
Expand All @@ -167,11 +167,11 @@ interactions:
connection:
- keep-alive
content-length:
- '311'
- '322'
content-type:
- application/json; charset=utf-8
date:
- Mon, 17 May 2021 21:46:48 GMT
- Tue, 18 May 2021 21:19:00 GMT
server:
- nginx/1.19.1
strict-transport-security:
Expand All @@ -197,7 +197,7 @@ interactions:
User-Agent:
- azsdk-python-agrifood-farming/1.0.0b1 Python/3.7.4 (Windows-10-10.0.19041-SP0)
method: DELETE
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer?api-version=2021-03-31-preview
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer-farmer-ops?api-version=2021-03-31-preview
response:
body:
string: ''
Expand All @@ -211,7 +211,7 @@ interactions:
content-length:
- '0'
date:
- Mon, 17 May 2021 21:46:50 GMT
- Tue, 18 May 2021 21:19:02 GMT
server:
- nginx/1.19.1
strict-transport-security:
Expand All @@ -231,11 +231,11 @@ interactions:
User-Agent:
- azsdk-python-agrifood-farming/1.0.0b1 Python/3.7.4 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer?api-version=2021-03-31-preview
uri: https://fakeAccount.farmbeats.azure.net/farmers/test-farmer-farmer-ops?api-version=2021-03-31-preview
response:
body:
string: '{"error":{"code":"ResourceNotFound","message":"Resource with id ''test-farmer''
does not exist.","target":null,"details":null,"innererror":null},"traceId":"0HM8KA703E1AH:00000002"}'
string: '{"error":{"code":"ResourceNotFound","message":"Resource with id ''test-farmer-farmer-ops''
does not exist.","target":null,"details":null,"innererror":null},"traceId":"0HM8KA6VEKNA0:00000002"}'
headers:
api-deprecated-versions:
- 2020-12-31-preview
Expand All @@ -244,11 +244,11 @@ interactions:
connection:
- keep-alive
content-length:
- '178'
- '189'
content-type:
- application/json
date:
- Mon, 17 May 2021 21:46:51 GMT
- Tue, 18 May 2021 21:19:03 GMT
server:
- nginx/1.19.1
strict-transport-security:
Expand Down
Loading

0 comments on commit 4e56b77

Please sign in to comment.