-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
92682bd
README
Li-Nathaniel fcf17f0
eta integration
Li-Nathaniel 907e0c7
Modified to work with postgresql
Li-Nathaniel f265bac
Modified README.md
Li-Nathaniel ea01352
.env file
Li-Nathaniel 6835d21
.env file
Li-Nathaniel 92f8f45
Modify .env file
Li-Nathaniel 855c9de
Modified for use with PostgreSQL
Li-Nathaniel a4c456d
Modified to test eta.py
Li-Nathaniel 5d1e31f
Getting rid of old venv and .DS_store
Li-Nathaniel f46b162
Removed old venv and .DS_Store
Li-Nathaniel a78021b
Remove .DS_Store
Li-Nathaniel 6f0bf49
Remove .DS_Store
Li-Nathaniel 511eba0
Remove .DS_Store
Li-Nathaniel 38fb3a6
Remove .DS_Store
Li-Nathaniel f23720e
Fixed list appending issues in PSQL and handle NaN
Li-Nathaniel 83c0d85
Merge branch 'eta_api' of https://github.com/uw-midsun/victini-micros…
Li-Nathaniel 1a7a400
Merge branch 'eta_api' of https://github.com/uw-midsun/victini-micros…
Li-Nathaniel 63b8609
Delete eta_api directory
Li-Nathaniel c153a37
Update gitignore
Li-Nathaniel 11f29df
Removed old .DS_Store
Li-Nathaniel 8e6e390
Update gitignore
Li-Nathaniel 0d14a17
Delete .DS_Store
Li-Nathaniel 7aa115f
Updated comments for clarity and Schemas folder
Li-Nathaniel bdffbe3
Updated DB credentials
Li-Nathaniel cab6df6
Fixed the issue where the eta to future checkpoints were not being ca…
Li-Nathaniel 4590616
Discarded testing code
Li-Nathaniel c7ed123
Create README.md
Li-Nathaniel 687bd85
Update eta.py
kasethi23 8f26425
Merge pull request #2 from kasethi23/eta_api
rodrigotiscareno d6ec178
Delete .vscode/settings.json
rodrigotiscareno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# victini-microservices | ||
# victini-microservices | ||
eta Flask API integration | ||
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete Line 2