Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Refactor for travis ci imports and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Kuehn committed Oct 16, 2019
1 parent 400c24d commit 74ed977
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion autofocus/predict/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def classify_zip():

file = ZipArchive(request.files["file"], app.config["UPLOAD_FOLDER"])
if not file.hasImages():
validator.error['file'] = "No image files detected in the zip file."
validator.error["file"] = "No image files detected in the zip file."
validator.abort()

# Extract files
Expand Down
1 change: 1 addition & 0 deletions autofocus/predict/app/models/File.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from werkzeug import secure_filename


Expand Down
3 changes: 1 addition & 2 deletions autofocus/predict/app/models/Predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def predict_multiple(self, files):
Parameters:
files: Dict with File objects of image file
Returns:
dict: Dictionary of probabilities for each file in files
"""
Expand All @@ -45,7 +45,6 @@ def predict_multiple(self, files):
predictions[key] = self.getProbabilities()
return predictions


def getProbabilities(self):
"""
Return formated Probabilities
Expand Down
9 changes: 5 additions & 4 deletions autofocus/predict/app/models/ZipArchive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from zipfile import ZipFile

from .File import File
from ..requests.Validator import ALLOWED_IMAGE_FILES
from ..utils import allowed_file
Expand Down Expand Up @@ -46,7 +47,7 @@ def listAllImages(self, extensions=ALLOWED_IMAGE_FILES):
Parameters:
extensions: Array of allowed image extensions
Returns:
array: Array of filenames matching the extension
"""
Expand All @@ -58,7 +59,7 @@ def hasImages(self, extensions=ALLOWED_IMAGE_FILES):
Parameters:
extensions: Array of allowed image extensions
Returns:
boolean: True if zip has images
"""
Expand All @@ -74,9 +75,9 @@ def extractAll(self, path=None, members=None):
Parameters:
path: Path to store files
members: Files to extract
Returns:
array: Array of extracted File objects
array: Array of extracted File objects
"""
self.zip.extractall(path, members)
extractedFiles = {}
Expand Down
12 changes: 6 additions & 6 deletions autofocus/predict/app/requests/PredictRequestValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@


class PredictRequestValidator(Validator):
"""
Validate request for endpoint predict
"""
"""Validate request for endpoint predict"""

def validate(self):
"""
Expand All @@ -18,11 +16,13 @@ def validate(self):
"""
self.error = {}

file = self.request.files.get('file', None)
file = self.request.files.get("file", None)
if not file:
self.error['file'] = "No file given."
self.error["file"] = "No file given."
elif not allowed_file(file.filename, ALLOWED_IMAGE_FILES):
self.error['file'] = "File type not allowed. File must be of type {allowed}".format(
self.error[
"file"
] = "File type not allowed. File must be of type {allowed}".format(
allowed=ALLOWED_IMAGE_FILES
)

Expand Down
12 changes: 6 additions & 6 deletions autofocus/predict/app/requests/PredictZipRequestValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@


class PredictZipRequestValidator(Validator):
"""
Validate request for endpoint predict_zip
"""
"""Validate request for endpoint predict_zip"""

def validate(self):
"""
Expand All @@ -18,11 +16,13 @@ def validate(self):
"""
self.error = {}

file = self.request.files.get('file', None)
file = self.request.files.get("file", None)
if not file:
self.error['file'] = "No file given."
self.error["file"] = "No file given."
elif not allowed_file(file.filename, ALLOWED_ZIP_FILES):
self.error['file'] = "File type not allowed. File must be of type {allowed}".format(
self.error[
"file"
] = "File type not allowed. File must be of type {allowed}".format(
allowed=ALLOWED_ZIP_FILES
)

Expand Down
20 changes: 9 additions & 11 deletions autofocus/predict/app/requests/Validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABC, abstractmethod

from flask import abort, jsonify, make_response
from flask_api import status

Expand Down Expand Up @@ -48,15 +49,12 @@ def getError(self):
dict: The errors found during validation
"""
return self.error

def abort(self):
"""
Abort with errors
"""
abort(make_response(
jsonify(
status=status.HTTP_400_BAD_REQUEST,
error=self.getError()
),
status.HTTP_400_BAD_REQUEST
))
"""Abort with errors"""
abort(
make_response(
jsonify(status=status.HTTP_400_BAD_REQUEST, error=self.getError()),
status.HTTP_400_BAD_REQUEST,
)
)

0 comments on commit 74ed977

Please sign in to comment.