Skip to content

Commit

Permalink
Merge demo into main (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: sash-enka <[email protected]>
Co-authored-by: Vincent Wijaya <[email protected]>
Co-authored-by: sash-enka <[email protected]>
Co-authored-by: Adam Ye <[email protected]>
Co-authored-by: Adam Ye <[email protected]>
Co-authored-by: rdev0010 <[email protected]>
Co-authored-by: Zahin Shahriar Bin Khair <[email protected]>
Co-authored-by: rdev0010 <[email protected]>
Co-authored-by: ell-cam <[email protected]>
Co-authored-by: gfra12 <[email protected]>
Co-authored-by: Rutvik Dave <[email protected]>
Co-authored-by: vincent-wijaya <[email protected]>
  • Loading branch information
13 people authored Oct 13, 2023
1 parent 0f35e36 commit f9147c2
Show file tree
Hide file tree
Showing 66 changed files with 13,791 additions and 19,847 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

name: CI/CD

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events for the main branch
push:
branches: [main]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
backend-deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Deploy to Heroku
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
appdir: "src/backend"
env:
DATABASE_HOST: ${{secrets.DATABASE_HOST}}
DATABASE_NAME: ${{secrets.DATABASE_NAME}}
DATABASE_PASSWORD: ${{secrets.DATABASE_PASSWORD}}
DATABASE_PORT: ${{secrets.DATABASE_PORT}}
DATABASE_USER: ${{secrets.DATABASE_USER}}

frontend-build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

defaults:
run:
working-directory: src/frontend/Finding-Neno

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: npm
cache-dependency-path: '**/package-lock.json'

- name: Setup EAS
uses: expo/expo-github-action@v8
with:
eas-version: 3.17.1
token: ${{ secrets.EXPO_TOKEN }}

- name: Install dependencies
run: npm install

# Build the preview of the app
- name: Build preview application
run: |
eas secret:create --name GOOGLE_MAPS_API_KEY --value ${{ secrets.GOOGLE_MAPS_API_KEY }} --type string --force --non-interactive
eas build --profile preview --platform android --clear-cache --non-interactive
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# Ignore all files containing environment variables
.env*
/.idea/
.idea/Finding-Neno.iml
.idea/misc.xml
.idea/modules.xml
.idea/vcs.xml
.idea/workspace.xml
package-lock.json
package.json
.idea*
**/.DS_Store
__pycache__/

Expand Down
62 changes: 22 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@ Finding Neno currently has the following features:

Detailed documentation can be found in the team's [Google Drive](https://drive.google.com/drive/u/1/folders/1URib5DxULDa4vhqCTlcQM6K4CIRcmrmG).

## Getting Started
## Getting Started (for running on your local machine)

### Hardware Requirements
* A Windows or Mac machine
* A smartphone (or Simulator on Mac devices)

### Software Requirements and Dependencies

* Python
* pip
* Python (including pip)
* Node: https://nodejs.org/en/download
* Expo CLI
```
npm install -g expo-cli
```
* Expo Go on your phone: https://expo.dev/client
* Flask: https://flask.palletsprojects.com/en/2.2.x/installation/
* PostgreSQL: https://www.postgresql.org/download/ (add a new server once installed)
* TablePlus (optional, used to visualise database): https://tableplus.com/ (Create a connection to the database using the details of the PostgreSQL server created in the previous step)

Expand All @@ -46,30 +44,21 @@ Create a .env file in the root directory. Add the following to the .env file (en
DATABASE_USER=postgres
DATABASE_PASSWORD=password
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_PORT=5432
SENDGRID_API_KEY=<REDACTED> # Speak to @josiahschuller to get a key.
```
Create a .env file within the src/frontend/Finding-Neno directory. Add the following to this .env file:
Create a .env file within the `src/frontend/Finding-Neno` directory. Add the following to this .env file:
```
IP=your device’s IP address
PORT=5000
API_URL=the URL outputted when the back-end API is run
```
Run the following command from the root directory:
* Mac users:
```
src/backend/install_dependencies_mac.sh
```
* Windows users:
```
src/backend/install_dependencies_windows.bat
```
If this does not work, run the following commands instead:
```
pip3 install psycopg2
pip3 install python-dotenv
pip3 install pytest
pip3 install pytest-mock
```
Run the following command from the root directory:
Install backend dependencies:

```
pip3 install -r src/backend/requirements.txt
```

Set up the database structure:
```
python3 src/backend/db/setup_db.py .env
```
Expand All @@ -81,33 +70,26 @@ Run the following command from the root directory:
python3 src/backend/api/main.py .env
```

3. In a new terminal, run the following commands from the src/frontend/Finding-Neno directory:
3. In a new terminal, run the following commands from the `src/frontend/Finding-Neno` directory:
```
npm install
npx expo start
npm start
```

4. Scan the QR code to start using Finding Neno!

## Notes and Common Issues
* Network error:
* Stop the server
* Reset cache by running this command from the src/frontend/Finding-Neno directory
```
npm cache clean --force
```
or
```
npx expo start -c
```
or
* Reset cache by running this command from the `src/frontend/Finding-Neno` directory:
```
npx react-native start --reset-cache
* Ensure that the IP and PORT on the src/frontend/Finding-Neno/.env are correct
* Ensure that your device is on the same IP/network as the server
```
* Ensure that the API_URL in `src/frontend/Finding-Neno/.env` is correct
* Ensure that your phone/tablet device is on the same LAN as the server
* Run the app again
* psycopg2 module not found:
* *Blah* module not found:
* Run the command:
```
pip3 install psycopg2-binary
pip3 install -r src/backend/requirements.txt
```
1 change: 1 addition & 0 deletions src/backend/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn api.main:app
59 changes: 59 additions & 0 deletions src/backend/api/get_suburb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# import requests

# def get_suburb(location_latitude, location_longitude):
# try:
# api_url = f"https://nominatim.openstreetmap.org/reverse?lat={location_latitude}&lon={location_longitude}&format=geocodejson"

# response = requests.get(api_url)

# result = response.json()
# print(result)
# suburb = f"{result['address']['suburb']}, {result['address']['state']}"
# return suburb

# except requests.exceptions.RequestException as e:
# print('Error fetching data:', e)

# # Example usage
# location_latitude = 123.456 # Replace with your latitude
# location_longitude = 78.910 # Replace with your longitude
# suburb = get_suburb(location_latitude, location_longitude)
# print('Suburb:', suburb)

from geopy.geocoders import Nominatim

def get_suburb(latitude: float, longitude: float) -> str:
"""
Returns the suburb of the given latitude and longitude. left indicates the suburb (or city), right indicates the state.
"""
geolocator = Nominatim(user_agent="Finding_Neno")
coordinates = f"{latitude}, {longitude}"
address = geolocator.reverse(coordinates, addressdetails=True)

if address is not None:
address = address.raw["address"]
left, right = None, None

if "suburb" in address:
left = address["suburb"]
else:
if "city" in address:
left = address["city"]

if "state" in address:
right = address["state"]

if right is not None:
if left is not None:
return f"{left}, {right}"
else:
return right
else:
if left is not None:
return left

else:
print("Location not found")

return "Location not available"

Loading

0 comments on commit f9147c2

Please sign in to comment.