Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nathaniel - ETA API #1

Merged
merged 31 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
92682bd
README
Li-Nathaniel Jul 11, 2023
fcf17f0
eta integration
Li-Nathaniel Jul 11, 2023
907e0c7
Modified to work with postgresql
Li-Nathaniel Sep 14, 2023
f265bac
Modified README.md
Li-Nathaniel Sep 16, 2023
ea01352
.env file
Li-Nathaniel Sep 16, 2023
6835d21
.env file
Li-Nathaniel Sep 16, 2023
92f8f45
Modify .env file
Li-Nathaniel Sep 16, 2023
855c9de
Modified for use with PostgreSQL
Li-Nathaniel Sep 17, 2023
a4c456d
Modified to test eta.py
Li-Nathaniel Oct 11, 2023
5d1e31f
Getting rid of old venv and .DS_store
Li-Nathaniel Oct 11, 2023
f46b162
Removed old venv and .DS_Store
Li-Nathaniel Oct 11, 2023
a78021b
Remove .DS_Store
Li-Nathaniel Oct 11, 2023
6f0bf49
Remove .DS_Store
Li-Nathaniel Oct 11, 2023
511eba0
Remove .DS_Store
Li-Nathaniel Oct 11, 2023
38fb3a6
Remove .DS_Store
Li-Nathaniel Oct 11, 2023
f23720e
Fixed list appending issues in PSQL and handle NaN
Li-Nathaniel Oct 31, 2023
83c0d85
Merge branch 'eta_api' of https://github.com/uw-midsun/victini-micros…
Li-Nathaniel Oct 31, 2023
1a7a400
Merge branch 'eta_api' of https://github.com/uw-midsun/victini-micros…
Li-Nathaniel Oct 31, 2023
63b8609
Delete eta_api directory
Li-Nathaniel Oct 31, 2023
c153a37
Update gitignore
Li-Nathaniel Oct 31, 2023
11f29df
Removed old .DS_Store
Li-Nathaniel Oct 31, 2023
8e6e390
Update gitignore
Li-Nathaniel Oct 31, 2023
0d14a17
Delete .DS_Store
Li-Nathaniel Oct 31, 2023
7aa115f
Updated comments for clarity and Schemas folder
Li-Nathaniel Oct 31, 2023
bdffbe3
Updated DB credentials
Li-Nathaniel Nov 26, 2023
cab6df6
Fixed the issue where the eta to future checkpoints were not being ca…
Li-Nathaniel Dec 1, 2023
4590616
Discarded testing code
Li-Nathaniel Dec 2, 2023
c7ed123
Create README.md
Li-Nathaniel Dec 2, 2023
687bd85
Update eta.py
kasethi23 Feb 11, 2024
8f26425
Merge pull request #2 from kasethi23/eta_api
rodrigotiscareno Mar 16, 2024
d6ec178
Delete .vscode/settings.json
rodrigotiscareno Mar 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# victini-microservices
# victini-microservices
eta Flask API integration
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete Line 2

Binary file added eta_api/.DS_Store
Binary file not shown.
160 changes: 160 additions & 0 deletions eta_api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
27 changes: 27 additions & 0 deletions eta_api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use an official Python runtime as the base image
FROM python:3.9

# Set the working directory in the container
WORKDIR /app

# Copy the requirements.txt file and install dependencies
COPY requirements.txt .

RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy the application files to the container
COPY src .

# Expose the port on which the Flask app will run
EXPOSE 5000

# Set the environment variables for Flask
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0

# Run the Flask application
CMD ["flask", "run", "--host", "0.0.0.0"]

# Run the database migrations, for after database has been defined
# CMD flask db upgrade && flask run --host 0.0.0.0
21 changes: 21 additions & 0 deletions eta_api/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Midnight Sun

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions eta_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ETA Microservice
ETA Flask API using the strategy-flask-template with SQAlchemy
32 changes: 32 additions & 0 deletions eta_api/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
alembic==1.10.4
black==23.3.0
blinker==1.6.2
click==8.1.3
colorama==0.4.6
dnspython==2.3.0
email-validator==1.1.2
Flask==2.3.2
Flask-Migrate==4.0.4
Flask-SQLAlchemy==3.0.3
greenlet==2.0.2
idna==3.4
isbnlib==3.10.3
iso3166==1.0.1
itsdangerous==2.1.2
Jinja2==3.1.2
Mako==1.2.4
MarkupSafe==2.1.2
mypy-extensions==1.0.0
mysqlclient==2.1.1
packaging==23.1
pathspec==0.11.1
platformdirs==3.5.0
psycopg2-binary==2.9.6
py-moneyed==0.8.0
pycountry==22.3.5
python-dotenv==1.0.0
pytz==2020.1
schwifty==2020.9.0
SQLAlchemy==2.0.12
typing_extensions==4.5.0
Werkzeug==2.3.3
Binary file added eta_api/src/.DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions eta_api/src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

from .config import config

db = SQLAlchemy()
migrate = Migrate()

def create_app(config_mode):
app = Flask(__name__)
app.config.from_object(config[config_mode])

db.init_app(app)
migrate.init_app(app, db)

return app
43 changes: 43 additions & 0 deletions eta_api/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
from flask import Flask, request, jsonify
from eta_api.src.eta import ETAQuery # Import the ETAQuery class from eta.py
from eta_api.src.models import db, User # Import the db and User models from models.py
from flask_migrate import Migrate

# Initialize Flask app
app = Flask(__name__)

# Configuration
app.config.from_object(os.environ['APP_SETTINGS'])
db.init_app(app)
migrate = Migrate(app, db)

# Define routes
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
lat = float(request.form['lat'])
lon = float(request.form['lon'])

# Calculate ETA using ETAQuery
eta_query = ETAQuery(lat, lon)
times = eta_query.get_times()

# Return ETA as JSON
return jsonify({'eta': times})

return 'Welcome to the ETA Service'

@app.route('/users', methods=['POST'])
def create_user():
name = request.json.get('name')
if name:
user = User(name=name)
db.session.add(user)
db.session.commit()
return jsonify({'message': 'User created successfully'})
else:
return jsonify({'error': 'Name is required'}), 400

if __name__ == '__main__':
app.run()
24 changes: 24 additions & 0 deletions eta_api/src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

class Config:
SQLALCHEMY_TRACK_MODIFICATIONS = False

class DevelopmentConfig(Config):
DEVELOPMENT = True
DEBUG = True
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')

class StagingConfig(Config):
DEVELOPMENT = True
DEBUG = True
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')

class ProductionConfig(Config):
DEBUG = False
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')

config = {
'development': DevelopmentConfig,
'staging': StagingConfig,
'production': ProductionConfig,
}
8 changes: 8 additions & 0 deletions eta_api/src/data/checkpoint_model_db.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
latitude,longitude,route_model_index,last_updated,forecast_time
43.46786317655638,-80.56637564010215,0,,
43.47181929178542,-80.55498944295489,41,,
43.47567782098289,-80.54387952656383,81,,
43.47953526800491,-80.53276819650009,121,,
43.48532332236007,-80.52733698515767,162,,
43.49079136987552,-80.53590572263501,205,,
43.49414882508247,-80.54735874761738,246,,
10 changes: 10 additions & 0 deletions eta_api/src/data/route.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
43.46786317655638, -80.56637564010215
43.48175280991097, -80.52637854159468
43.48536483714299, -80.5270651870626
43.48511573875007, -80.52869597004897
43.48536483714299, -80.52989759961787
43.48604985242712, -80.5304984144023
43.48816712335336, -80.5320433668198
43.489910702452285, -80.53461828732458
43.49196557034531, -80.53762236124682
43.494347261633344, -80.5482439084337
Loading