Skip to content

Commit 645a75e

Browse files
authored
General backend cleanup (#86)
1 parent e4b163b commit 645a75e

15 files changed

Lines changed: 348 additions & 318 deletions

File tree

demo/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
# tasking-api
1+
# Demo
22

3-
Install packages
3+
This directory contains a demo site where several satelite providers
4+
have implemented proxies to map the STAT API to their existing
5+
provider-specific APIs.
6+
7+
## Run locally
8+
9+
### Install packages
410

511
```python
612
pip install -r requirements.txt
713
```
814

9-
Run backend:
15+
Install next: [Next.js](https://nextjs.org/)
16+
17+
### Run demo
1018

1119
```shell
1220
./scripts/run
1321
```
22+
23+
### Access demo
24+
25+
frontend: localhost:3000
26+
backend: localhost:8000

demo/api/api_types.py

Lines changed: 0 additions & 121 deletions
This file was deleted.

demo/api/backends/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from api.backends.base import Backend
22
from api.backends.blacksky_backend import BlackskyBackend
3+
from api.backends.earthsearch_backend import EarthSearchBackend
34
from api.backends.fake_backend import FakeBackend
45
from api.backends.planet_backend import PlanetBackend
5-
from api.backends.sentinel_backend import HistoricalBackend
66
from api.backends.umbra_backend import UmbraBackend
77

88
BACKENDS: dict[str, Backend] = {
9-
"fake": FakeBackend,
10-
"historical": HistoricalBackend,
11-
"blacksky": BlackskyBackend,
12-
"planet": PlanetBackend,
13-
"umbra": UmbraBackend,
9+
"fake": FakeBackend(), # type: ignore
10+
"earthsearch": EarthSearchBackend(), # type: ignore
11+
"blacksky": BlackskyBackend(), # type: ignore
12+
"planet": PlanetBackend(), # type: ignore
13+
"umbra": UmbraBackend(), # type: ignore
1414
}

demo/api/backends/base.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
from typing import Protocol
22

3-
from api.api_types import OpportunityCollection, Order, Product, Search
3+
from api.models import Opportunity, Order, Product
44

55

6-
# backend protocol class
76
class Backend(Protocol):
8-
"""Backend Python API"""
7+
"""
8+
Protocol class that backend provider APIs must conform to
99
10-
async def find_opportunities(
11-
self,
12-
search: Search,
13-
token: str,
14-
) -> OpportunityCollection:
15-
return NotImplemented
10+
In order to create a backend a provider must create a class
11+
with the methods defined in this Protocol.
12+
"""
1613

1714
async def find_products(
1815
self,
1916
token: str,
2017
) -> list[Product]:
18+
"""Get a list of all Products"""
2119
return NotImplemented
2220

2321
async def place_order(
2422
self,
25-
search: Search,
23+
search: Opportunity,
2624
token: str,
2725
) -> Order:
26+
"""Given an Opportunity, place an order"""
27+
return NotImplemented
28+
29+
async def find_opportunities(
30+
self,
31+
search: Opportunity,
32+
token: str,
33+
) -> list[Opportunity]:
34+
"""Given an Opportunity, get a list of Opportunites that fulfill it"""
2835
return NotImplemented

demo/api/backends/blacksky_backend.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import requests
2-
3-
from api.api_types import Opportunity, OpportunityCollection, Search
2+
from api.models import Opportunity
43

54
BLACKSKY_BASE_URL = "https://api.dev.blacksky.com/v1"
65

76

8-
def stac_search_to_oppurtunities_request(search_request: Search):
7+
def stat_to_oppurtunities_request(search_request: Opportunity):
98
"""
109
:param search_request: STAC search as passed on to find_future_items
1110
:return: a triple of iw request body, geom and bbox (geom and bbox needed again later to construct STAC answers)
@@ -55,37 +54,33 @@ def get_oppurtunities(blacksky_request, token):
5554
return r.json()["opportunities"]
5655

5756

58-
def oppurtunity_to_stac_item(iw):
57+
def blacksky_oppurtunity_to_opportunity(iw):
5958
"""
6059
translates a Planet Imaging Windows into a STAC item
6160
:param iw: an element from the 'imaging_windows' array of a /imaging_windows/[search_id] response
6261
:return: a corresponding STAC item
6362
"""
6463

65-
item = Opportunity(
64+
opportunity = Opportunity(
6665
id=iw["satellite"],
66+
product_id="BS-Test:Standard",
6767
geometry={"type": "Point", "coordinates": [iw["longitude"], iw["latitude"], 0]},
68-
properties={
69-
"title": "",
70-
"datetime": f"{iw['timestamp']}/{iw['timestamp']}",
71-
"constraints": {
72-
"off_nadir": iw["offNadirAngleDegrees"],
73-
"cloud_cover": iw["weatherForecast"]["cloudCover"],
74-
},
68+
datetime=f"{iw['timestamp']}/{iw['timestamp']}",
69+
constraints={
70+
"off_nadir": iw["offNadirAngleDegrees"],
71+
"cloud_cover": iw["weatherForecast"]["cloudCover"],
7572
},
7673
)
7774

78-
return item
75+
return opportunity
7976

8077

8178
class BlackskyBackend:
8279
async def find_opportunities(
8380
self,
84-
search_request: Search,
81+
search_request: Opportunity,
8582
token: str,
86-
) -> OpportunityCollection:
87-
blacksky_request = stac_search_to_oppurtunities_request(search_request)
83+
) -> list[Opportunity]:
84+
blacksky_request = stat_to_oppurtunities_request(search_request)
8885
oppurtunities = get_oppurtunities(blacksky_request, token)
89-
stac_items = [oppurtunity_to_stac_item(iw) for iw in oppurtunities]
90-
91-
return OpportunityCollection(features=stac_items, links=[])
86+
return [blacksky_oppurtunity_to_opportunity(iw) for iw in oppurtunities]

0 commit comments

Comments
 (0)