Esempio n. 1
0
from utils.NestableBlueprint import NestableBlueprint
from .contributors.contributors_controller import contributors_controller
from .skills.skills_controller import skills_controller

v1_controller = NestableBlueprint("v1", __name__, url_prefix="/v1")

v1_controller.register_blueprint(contributors_controller)
v1_controller.register_blueprint(skills_controller)
Esempio n. 2
0
import logging
from flask import abort, jsonify, request, Response
from models import KerasPrediction
from utils import LoggingUtils
from utils.NestableBlueprint import NestableBlueprint

URL_PREFIX = "/predictions"

logger = logging.getLogger(__name__)
predictions_controller = NestableBlueprint("predictions", __name__)

KerasPrediction.init()
keras_prediction = KerasPrediction()

# DEMO: Disabled for demo purposes
#
# @predictions_controller.route(URL_PREFIX, methods=["POST"])
# @LoggingUtils.log_execution_time("Prediction processing finished")
# def get_predictions() -> Response:
#     data = request.get_json()
#     logger.info("Request data: " + str(data))
#
#     if "posts" not in data:
#         logger.warning("Posts are missing from payload.")
#         return jsonify(abort(400))
#
#     predictions = list(map(lambda post: keras_prediction.get_prediction(post["imageHash"]), data["posts"]))
#
#     return jsonify({
#         "status": "success",
#         "predictions": predictions
Esempio n. 3
0
import logging
from flask import jsonify, request, Response
from werkzeug.exceptions import BadRequest, InternalServerError
from middleware import api_key_authentication
from predictors.skills_predictor import SkillsPredictor
from utils import LoggingUtils
from utils.NestableBlueprint import NestableBlueprint

logger = logging.getLogger(__name__)

skills_controller = NestableBlueprint("skills", __name__, url_prefix="/skills")

predictor = SkillsPredictor()


@skills_controller.route("/predict", methods=["POST"])
@api_key_authentication()
@LoggingUtils.log_execution_time("Prediction processing finished")
def predict_skills() -> Response:
    raw_stats = request.get_json().get("raw_stats", {})
    existing_emails = request.get_json().get("existing_emails", [])

    if type(raw_stats) != dict:
        raise BadRequest(
            "'raw_stats' must be a set of skill/file stats from the Scraper service."
        )

    try:
        predictions = predictor.predict(raw_stats, existing_emails)
    except:
        raise InternalServerError(
Esempio n. 4
0
import logging
from flask import jsonify, request, Response
from werkzeug.exceptions import BadRequest, InternalServerError
from middleware import api_key_authentication
from predictors.contributors_predictor import ContributorsPredictor
from utils import LoggingUtils
from utils.NestableBlueprint import NestableBlueprint

logger = logging.getLogger(__name__)

contributors_controller = NestableBlueprint("contributors",
                                            __name__,
                                            url_prefix="/contributors")

predictor = ContributorsPredictor()


@contributors_controller.route("/predict", methods=["POST"])
@api_key_authentication()
@LoggingUtils.log_execution_time("Prediction processing finished")
def predict_contributors() -> Response:
    issues = request.get_json()

    if type(issues) != list:
        raise BadRequest("'issues' must be a list of Jira issues.")

    try:
        predictions = predictor.predict(issues)
    except:
        raise InternalServerError(
            "Failed to make predictions; see logs for more details.")
Esempio n. 5
0
from utils.NestableBlueprint import NestableBlueprint

v1_controller = NestableBlueprint("v1", __name__, url_prefix="/v1")
import logging
from flask import jsonify, request, Response
from models import MemePost
from utils import LoggingUtils
from utils.NestableBlueprint import NestableBlueprint
from .predictions.predictions_controller import predictions_controller

logger = logging.getLogger(__name__)

memes_controller = NestableBlueprint("memes", __name__, url_prefix="/memes")
memes_controller.register_blueprint(predictions_controller)

meme_post_service = MemePost()

# DEMO: Disabled for demo purposes
#
# @memes_controller.route("/", methods=["GET"])
# @LoggingUtils.log_execution_time("Prediction processing finished")
# def get_latest_posts() -> Response:
#     posts = meme_post_service.get_latest_posts()
#
#     return jsonify({
#         "status": "success",
#         "posts": posts
#     })
#
#
# @memes_controller.route("/<post_id>/score", methods=["POST"])
# @LoggingUtils.log_execution_time("Score update finished")
# def increment_post_score(post_id: str) -> Response:
#     updated_score = meme_post_service.increment_score(post_id)
from utils.NestableBlueprint import NestableBlueprint
from .v1.v1_controller import v1_controller

api_controller = NestableBlueprint("api", __name__, url_prefix="/api")
api_controller.register_blueprint(v1_controller)
from utils.NestableBlueprint import NestableBlueprint
from .memes.memes_controller import memes_controller

v1_controller = NestableBlueprint("v1", __name__, url_prefix="/v1")
v1_controller.register_blueprint(memes_controller)