Esempio n. 1
0
from backend.models import Job, GeneralJobSchema, Well
from flask import current_app as app
from flask import render_template
from flask import jsonify
from config import SCHEMA_MAIN, SCHEMA_WEBSITE
from datetime import datetime, timedelta
from backend import db
from flask_login import login_required
from flask import request
from flask_restx import Resource
from backend.api import api
from backend.api.serializers import job
from sqlalchemy.orm import joinedload
from backend.api.jwt import validate
ns = api.namespace('Jobs', description='Operations related to jobs.')


@ns.route('/')
class JobCollection(Resource):

    @validate
    @api.marshal_with(job)
    def get(self):
        jobs = db.session.query(Job).options(joinedload(Job.well)).all()
        return jobs


@ns.route('/<int:job_num>')
@api.response(404, 'Job not found.')
class JobItem(Resource):
Esempio n. 2
0
import email
import requests
from io import BytesIO
from flask import jsonify, request, current_app
from backend.api import api
from backend.database import db
from flask_restplus import Resource
from backend.api.routines.laptime import read_laptimesheet, validate_laptimes

ns = api.namespace('email',
                   description='Operations related to received emails.')


@ns.route('/')
class EmailCollection(Resource):
    @api.doc(security='apikey')
    @api.response(200, 'Email successfully received.')
    def post(self):
        """
        Receives emails containing training sessions.
        """

        header = bytes(str(request.headers).encode("utf-8"))
        body = request.get_data()

        msg = email.message_from_bytes(header + body)

        response = None
        for part in msg.walk():

            if part.get_content_maintype() == 'multipart':
Esempio n. 3
0
from datetime import datetime, timezone
from flask import jsonify, request
from flask_restplus import Resource, fields
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.database import db
from backend.database.models.training import TrainingModel, TrainingSchema
from backend.database.models.setup import SetupSchema
from backend.database.models.session import SessionModel, SessionSchema
from backend.database.models.laptime import LaptimeSchema
from backend.api.routines.common import query_intervals

ns = api.namespace('training',
                   description='Operations related to training entries.')
training_schema = TrainingSchema()
setup_schema = SetupSchema()
session_schema = SessionSchema()
laptime_schema = LaptimeSchema()

training_input_parameters = api.model(
    'TrainingInputParameters', {
        "location":
        fields.String(description="location of the training",
                      required=True,
                      example="track name"),
        "weather_hourly":
        fields.Raw(description="hourly track weather data",
                   required=False,
                   example=[{
                       "lat": 47.4325306,
                       "lon": 6.7046713,
Esempio n. 4
0
from flask import jsonify, request
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.database import db
from backend.database.models.coach import CoachModel, CoachSchema
from flask_restplus import Resource, fields

ns = api.namespace('coach', description='Operations related to bike entries.')
coach_schema = CoachSchema()

coach_input_parameters = api.model('CoachInputParameters', {
    "category":
        fields.String(description="bike suspension end", required=True, example="category name"),
    "symptom":
        fields.Raw(description="suspension symptom", required=True, example={
            "id": "example ID",
            "name": "example name",
        }),
    "notes":
        fields.String(description="notes", required=False, example="notes on the symptom"),
    "questions":
        fields.Raw(description="array of questions in terms of troubleshouting", required=False, example=[
            "example question 1",
            "example question 2",
        ]),
    "advice":
        fields.Raw(description="object of possible problems and solutions", required=True, example={
            "A": {
                "problem": "problem A description",
                "solution": [
                    "solution approach 1 of the problem",
Esempio n. 5
0
from datetime import datetime, timezone
from flask import jsonify, request
from flask_restplus import Resource, fields
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.database import db
from backend.database.models.tire import TireModel, TireSchema
from backend.api.routines.common import query_intervals

ns = api.namespace('tire', description='Operations related to tire entries.')
tire_schema = TireSchema()

tire_input_parameters = api.model(
    'TireInputParameters', {
        "bike_id":
        fields.String(description="corresponding bike ID",
                      required=True,
                      example="UUID4"),
        "active":
        fields.Boolean(description="mounted on the bike or not",
                       required=False,
                       example="false"),
        "rim":
        fields.String(description="rim on which the tire is mounted",
                      required=False,
                      example="Alpina black"),
        "category":
        fields.String(
            description="slick or rain tire", required=True, example="slick"),
        "manufacturer":
        fields.String(description="manufacturer of the tire",
Esempio n. 6
0
from backend.models import Job, GeneralJobSchema, Well, Upload
from flask import current_app as app
from flask import render_template
from flask import jsonify
from config import SCHEMA_MAIN, SCHEMA_WEBSITE
from datetime import datetime, timedelta
from backend import db
from flask_login import login_required
from flask import request
from flask_restx import Resource
from backend.api import api
from backend.api.serializers import upload
from sqlalchemy.orm import joinedload
from backend.api.jwt import validate

ns = api.namespace('Uploads',
                   description='Operations related to file uploads.')


@ns.route('/')
class UploadCollection(Resource):
    @validate
    @api.marshal_with(upload)
    def get(self):
        uploads = db.session.query(Upload)
        return uploads


@ns.route('/<int:job_num>')
@api.response(404, 'Files not found.')
class UploadItem(Resource):
    @validate
Esempio n. 7
0
from datetime import datetime, timedelta, timezone
from flask import jsonify, request
from flask_restplus import Resource, fields
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.database import db
from backend.database.models.maintenance import MaintenanceModel, MaintenanceSchema
from backend.database.models.history import HistorySchema
from backend.database.models.bike import BikeModel, BikeSchema
from backend.api.routines.common import query_intervals
from sqlalchemy import cast
from sqlalchemy.dialects.postgresql import ARRAY

ns = api.namespace('maintenance', description='Operations related to maintenance entries.')
history_schema = HistorySchema()
maintenance_schema = MaintenanceSchema()
bike_schema = BikeSchema()

maintenance_input_parameters = api.model('MaintenanceInputParameters', {
    "category":
        fields.String(description="maintenance work category according to bike module",
                      required=True, example="maintenance category"),
    "name":
        fields.String(description="maintenance work name", required=True, example="maintenance name"),
    "interval_amount":
        fields.Float(description="interval of maintenance work", required=True, example=10.0),
    "interval_unit":
        fields.String(description="unit of maintenance interval", required=False, example="h"),
    "interval_type":
        fields.String(description="type of maintenance interval", required=False, example="planned maintenance"),
    "tags_default":
Esempio n. 8
0
from flask import jsonify, request
from flask_restplus import Resource, fields
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.api.routines.common import query_intervals
from backend.database import db
from backend.database.models.sparepart import SparepartModel, SparepartSchema
from backend.database.models.sparepartitem import SparepartitemSchema

ns = api.namespace('sparepart',
                   description='Operations related to spareparts.')
sparepart_schema = SparepartSchema()
sparepartitem_schema = SparepartitemSchema()

sparepart_input_parameters = api.model(
    'SparepartInputParameters', {
        "name":
        fields.String(description="name of the spare part",
                      required=True,
                      example="spare part name"),
        "module":
        fields.String(
            description="bike module where the spare part belongs to",
            required=True,
            example="Engine"),
        "min_stock":
        fields.Integer(description="minimal stock of the spare part",
                       required=True,
                       example=2),
    })
sparepart_query_parameters = api.model(
Esempio n. 9
0
from datetime import datetime, timezone
from flask import jsonify, request
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.database import db
from backend.database.models.laptime import LaptimeModel, LaptimeSchema
from flask_restplus import Resource, fields

ns = api.namespace('laptime',
                   description='Operations related to lap time entries.')
laptime_schema = LaptimeSchema()

laptime_input_parameters = api.model(
    'LaptimeInputParameters', {
        "session_id":
        fields.String(description="corresponding session ID",
                      required=True,
                      example="UUID4"),
        "lap_no":
        fields.Integer(
            description="lap number of session", required=True, example=1),
        "valid":
        fields.Boolean(
            description="validity of lap", required=False, example=True),
        "laptime_seconds":
        fields.Float(
            description="lap time in seconds", required=False, example=66.61),
        "sectors":
        fields.Raw(description="sector times",
                   required=False,
                   example={
Esempio n. 10
0
from datetime import datetime, timezone
from flask import jsonify, request
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.database import db
from backend.database.models.session import SessionModel, SessionSchema
from backend.database.models.laptime import LaptimeSchema
from flask_restplus import Resource, fields

ns = api.namespace('session',
                   description='Operations related to training sessions.')
session_schema = SessionSchema()
laptime_schema = LaptimeSchema()

session_input_parameters = api.model(
    'SessionInputParameters', {
        "training_id":
        fields.String(description="corresponding training ID",
                      required=True,
                      example="UUID4"),
        "bike_id":
        fields.String(description="corresponding bike ID",
                      required=True,
                      example="UUID4"),
        "setup_id":
        fields.String(description="corresponding setup ID",
                      required=True,
                      example="UUID4"),
        "datetime_display":
        fields.DateTime(description="utc time stamp in seconds",
                        required=True,
Esempio n. 11
0
from datetime import datetime, timezone
from flask import jsonify, request
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.database import db
from backend.database.models.setup import SetupModel, SetupSchema
from flask_restplus import Resource, fields

ns = api.namespace('setup', description='Operations related to bike setup entries.')
setup_schema = SetupSchema()

setup_input_parameters = api.model('SetupInputParameters', {
    "training_id":
        fields.String(description="corresponding training ID", required=True, example="UUID4"),
    "bike_id":
        fields.String(description="corresponding bike ID", required=True, example="UUID4"),
    "operating_hours":
        fields.Float(description="operating hours", required=True, example=66.1),
    "weather_current":
        fields.Raw(description="current track weather data", required=False, example={
            "lat": 49.2966279,
            "lon": 8.601037,
            "temp": {
                "value": 30.04,
                "units": "C"
            },
            "type": "measurement"
        }),
    "slick_pressure_front":
        fields.Float(description="pressure of front slick tire", required=False, example=2.0),
    "slick_pressure_rear":
Esempio n. 12
0
from datetime import datetime, timezone
from flask import jsonify, request
from flask_restplus import Resource, fields
from backend.api import api
from backend.api.authentication.validation import validate_api_key
from backend.api.routines.common import query_intervals
from backend.database import db
from backend.database.models.history import HistoryModel, HistorySchema
from backend.database.models.maintenance import MaintenanceSchema
from sqlalchemy import cast
from sqlalchemy.dialects.postgresql import ARRAY

ns = api.namespace('history',
                   description='Operations related to history entries.')
history_schema = HistorySchema()
maintenance_schema = MaintenanceSchema()

history_input_parameters = api.model(
    'HistoryInputParameters', {
        "maintenance_id":
        fields.String(description="corresponding maintenance ID",
                      required=True,
                      example="UUID4"),
        "bike_id":
        fields.String(description="corresponding bike ID",
                      required=True,
                      example="UUID4"),
        "operating_hours":
        fields.Float(
            description=
            "operating hours of the bike when the maintenance work was done",