Skip to content

Commit 98cf6af

Browse files
authored
Merge pull request #53 from via-cs/cleanup/backend
Cleaned Backend + Documentation
2 parents d4f61ff + 3ff75e9 commit 98cf6af

File tree

3 files changed

+10
-38
lines changed

3 files changed

+10
-38
lines changed

backend/app/base.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
import pandas as pd
1212
import numpy as np
13-
from shapely.geometry import LineString
14-
import rasterio
15-
from rasterio.warp import calculate_default_transform, reproject, Resampling
1613

1714
from PIL import Image
1815
from io import BytesIO
@@ -266,12 +263,6 @@ def get_bird_ids(bird: str):
266263
status_code=404,
267264
detail= f'CSV file for {filename} not found')
268265

269-
270-
def simplify_line(coordinates, tolerance=0.1):
271-
line = LineString(coordinates)
272-
simplified_line = line.simplify(tolerance, preserve_topology=False)
273-
return list(zip(*simplified_line.xy))
274-
275266

276267
@app.get('/get_heatmap_data')
277268
def get_heatmap_data(bird: str):

backend/tests/test_restful.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,6 @@ def client(app):
3030

3131
yield TestClient(app)
3232

33-
34-
def test_get_bird_info(client):
35-
36-
valid_birds = {
37-
"Blackpoll Warbler" : "Setophaga Striata",
38-
"Bald Eagle" : "Haliaeetus Leucocephalus",
39-
"White Fronted Goose" : "Anser Albifrons",
40-
"Long Billed Curlew" : "Numenius Americanus",
41-
"Whimbrel" : "Numenius Phaeopus"
42-
}
43-
44-
# Test for each bird that exists
45-
for bird in valid_birds:
46-
47-
response = client.get(f'/bird-info/{bird}')
48-
49-
assert response.status_code == 200
50-
51-
# Decode the response body.
52-
response_body = read_response_body(response)
53-
assert response_body['scientific_name'] == valid_birds[bird]
54-
55-
# Test an invalid entry
56-
response = client.get(f'/bird-info/Invalid_Bird')
57-
58-
assert response.status_code == 404
59-
6033
def test_get_temp_data(client):
6134

6235
response = client.get(f'/temperature/{2021}')

techdoc/tech-doc.tex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@ \subsubsection*{React}
8787
up in src/App.css.
8888

8989
\subsubsection*{FastAPI}
90-
TODO
90+
The middleware and backend of the website was developed using python and FastAPI, in the file base.py located in the subfolder backend/app. The FastAPI backend primarily serves the purpose of quickly retrieving data and sending it to the front end as requested, allowing the front end user-interface to remain lightweight and easy to load quickly. FastAPI was used to build the backend due to its ease in creating end points for a frontend application to call, natively supporting features such as delayed requests and an intuitive way of passing arguments to the FastAPI backend.
91+
The backend is defined predominantly by functions that handle various requests the front end makes in order to retrieve data to display. These functions and their functions are discussed in greater detail in the following section for RestFUL API.
9192

9293
\subsubsection*{RestFUL}
93-
TODO
94+
RestFUL API was used to define how the end points were set up, partially due to built-in compatibility with FastAPI, but also due to its simple and intuitive interface. While RestFUL API primarily defines 4 primary methods for GET, PUT, POST, and DELETE, the final application was operational with a stateless backend, meaning only GET and PUT requests were used.
95+
In the file base.py, GET and PUT requests were used to define the following end points:
96+
- get_temperature_data(): a GET end point that in turn performs a POST request to grid2.rcc-acis.org to obtain temperature data for the state of California throughout a year, which is specified per the user's request.
97+
- get_precipitation_data(): a GET end point that in turn performs a POST request to grid2.rcc-acis.org to obtain precipitation data for the state of California throughout a year, which is specified per the user's request.
98+
- get_predictions(): a PUT end point that retrieves the pre-computed predictions the Species Distribution Model makes about a specified bird, for a specified year based on specified emission data. While a GET request would have sufficed for its current utility, a PUT request was preferred as this could be expanded to implement a machine learning model to generate predictions dynamically should such a feature be planned in the future.
99+
- get_trajectory_data(): a GET end point that retrieves a csv file containing the migration trajectory of a specific bird, identified by its unique bird ID, that can be used to generate individual trajectory maps of an individual bird. The trajectory information is discussed later in the subsection for Leaflet.
100+
- get_bird_ids(): a GET end point that returns all unique bird IDs per a given species. This is used to by the front end component PolylineMap.js to search for a specified bird ID.
101+
- get_heatmap_data(): a GET end point that retrieves heatmap data of a bird species, to display the aggregated paths of all birds catalogued for that species on the front end with HeatMap.js, as a heat map. This is discussed in further detail in the Leaflet subsection.
94102

95103
\subsubsection*{Leaflet}
96104
Leaflet was used to map bird migration patterns in two ways under the "Trajectory" component. The first map, "Individual Path", is created in src/components/PolylineMap.js.

0 commit comments

Comments
 (0)