Skip to content

Commit

Permalink
added black and formatted files
Browse files Browse the repository at this point in the history
  • Loading branch information
sal2pak committed Oct 27, 2023
1 parent 79db86c commit c0a6d34
Show file tree
Hide file tree
Showing 10 changed files with 33,390 additions and 283 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ jobs:
- name: Run test suite
run: |
pipenv run pytest
format:
- name: Run black formatter
uses: rickstaa/[email protected]


1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ numpy = "*"
sklearn = "*"
joblib = "*"
ipykernel = "*"
black = "*"

[requires]
python_version = "3.8"
614 changes: 356 additions & 258 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

app = Flask(__name__)

from app.handlers import routes
from app.handlers import routes
2 changes: 1 addition & 1 deletion app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

configure_routes(app)

if __name__ == '__main__':
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True, port=80)
16 changes: 9 additions & 7 deletions app/fib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
The zeroth number in the fibonacci sequence is 0. The first number is 1
Negative numbers should return None
"""


def fibonacci(position):
if(position < 0):
raise ValueError("Invalid input")
if (position == 0):
return 0
if(position == 1 or position == 2):
return 1
return fibonacci(position - 1) + fibonacci(position - 2)
if position < 0:
raise ValueError("Invalid input")
if position == 0:
return 0
if position == 1 or position == 2:
return 1
return fibonacci(position - 1) + fibonacci(position - 2)
26 changes: 14 additions & 12 deletions app/handlers/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@
import numpy as np
import os


def configure_routes(app):

this_dir = os.path.dirname(__file__)
model_path = os.path.join(this_dir, "model.pkl")
clf = joblib.load(model_path)

@app.route('/')
@app.route("/")
def hello():
return "try the predict route it is great!"


@app.route('/predict')
@app.route("/predict")
def predict():
#use entries from the query string here but could also use json
age = request.args.get('age')
absences = request.args.get('absences')
health = request.args.get('health')
# use entries from the query string here but could also use json
age = request.args.get("age")
absences = request.args.get("absences")
health = request.args.get("health")
data = [[age], [health], [absences]]
query_df = pd.DataFrame({
'age': pd.Series(age),
'health': pd.Series(health),
'absences': pd.Series(absences)
})
query_df = pd.DataFrame(
{
"age": pd.Series(age),
"health": pd.Series(health),
"absences": pd.Series(absences),
}
)
query = pd.get_dummies(query_df)
prediction = clf.predict(query)
return jsonify(np.asscalar(prediction))
8 changes: 6 additions & 2 deletions app/tests/test_fib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from app.fib import fibonacci

# Test cases for the fibonacci function
def test_first_fibonacci(): assert(fibonacci(1) == 1)
def test_zero_fibonacci(): assert(fibonacci(0) == 0)
def test_first_fibonacci():
assert fibonacci(1) == 1


def test_zero_fibonacci():
assert fibonacci(0) == 0
4 changes: 2 additions & 2 deletions app/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def test_base_route():
app = Flask(__name__)
configure_routes(app)
client = app.test_client()
url = '/'
url = "/"

response = client.get(url)

assert response.status_code == 200
assert response.get_data() == b'try the predict route it is great!'
assert response.get_data() == b"try the predict route it is great!"
Loading

0 comments on commit c0a6d34

Please sign in to comment.