A function (management script) the calculates and saves the top 10 closest Activities for each School.
Why do we need this feature?
To be able to calculate distance between activities & schools. This helps recommending relevant activities to school staff.
What does the proposed solution look like? (Balsamiq / Technical Overview)
First, we need to add lat, lan fields to School & Activity models (like Organization has). School Model can be found in schools/models.py, Activity inorganizations/models.py`.
Add nearby_activities django's ManyToManyField to School model.
Then, we need to create a management script file (similar to create_test_data.py script).
The script can be ran the script using python manage.py <script_name> (e.g., python manage.py create_test_data)
In the script we need to:
get all School & Activities and their location from DB
from server.schools.models import School
from server.organizations.models import Activity
School.objects.all()
Activity.objects.all()
- For each school, get all the activities in 30km **air** distance. using something like [this](https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula).
- Get the closest activities from them based on **travel** distance. Use [Google Maps Distance API](https://developers.google.com/maps/documentation/distance-matrix/usage-and-billing#distance-matrix) for that purpose.
- Populate the `nearby_activities` field for each school using the Activities found.
* **Note:** we use air distance to narrow down the options and reduce time & costs.
* **Note:** please don't spam Google API if not needed as it might get expensive.
Feature Description
A function (management script) the calculates and saves the top 10 closest Activities for each School.
Why do we need this feature?
To be able to calculate distance between activities & schools. This helps recommending relevant activities to school staff.
What does the proposed solution look like? (Balsamiq / Technical Overview)
First, we need to add
lat
,lan
fields toSchool
&Activity
models (likeOrganization
has).School
Model can be found inschools/models.py
,Activity in
organizations/models.py`.Add
nearby_activities
django's ManyToManyField toSchool
model.Apply the changes to the DB using:
Then, we need to create a management script file (similar to
create_test_data.py
script).The script can be ran the script using
python manage.py <script_name>
(e.g.,python manage.py create_test_data
)In the script we need to:
get all School & Activities and their location from DB
School.objects.all() Activity.objects.all()
How to test?
Pytest. use a mock for the API endpoint.
Blocked
Not blocked 🥇 talk to us to use our GCP account