Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oleander/ah
https://github.com/oleander/ah
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/oleander/ah
- Owner: oleander
- Created: 2022-08-17T10:40:05.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-22T22:22:00.000Z (3 months ago)
- Last Synced: 2024-11-20T20:12:07.075Z (2 months ago)
- Language: Ruby
- Size: 56.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AroundHome [![Ruby on Rails CI](https://github.com/oleander/ah/actions/workflows/rubyonrails.yml/badge.svg)](https://github.com/oleander/ah/actions/workflows/rubyonrails.yml)
* Requirements
* Ruby 3.1
* PostgreSQL 9.3+
* With support for the `cube` and `earthdistance` extensions* Installation
* `bundle install`
* `bundle exec rails db:create db:migrate`
* `bundle exec rails db:seed`
* `bundle exec rails server`
* Open
* http://localhost:3000/partners/1
* http://localhost:3000/requests/1/partners/1* How to run the test suite
* `bundle exec rspec`* Possible improvements
* Joined indexes in relational tables
* Point indexes on `lat` and `lng`
* Authentication
* Caching## Solution in a nutshell
Where `$2` and `$3` are latitude and longitude parameters for a request `$1`.
``` sql
SELECT
partners.*,
earth_distance(
ll_to_earth(partners.lat, partners.lng),
ll_to_earth($2, $3)
) AS distance
FROM
partners
INNER JOIN
experiences
ON experiences.partner_id = partners.id
INNER JOIN
materials
ON materials.id = experiences.material_id
WHERE
materials.id IN (
SELECT
materials.id
FROM
materials
INNER JOIN
requirements
ON materials.id = requirements.material_id
WHERE
requirements.request_id = $1
) AND earth_distance(
ll_to_earth(partners.lat, partners.lng),
ll_to_earth($2, $3)
) <= partners.operating_radius
GROUP BY
partners.id
ORDER BY
rating DESC,
distance ASC
```