Esempio n. 1
0
def api_file(ftype=None):
    """List of downloadable file, with optional type filtering. Allowed types are "vm" and "usb".
    
    GET /api/file
    GET /api/file/usb
    GET /api/file/vm
    Query parameters:
    (none implemented)
    API returns 200 OK and:
    {
        ...,
        "data" : [
            {
                TBA
            },
            ...
        ],
        ...
    }
    """
    log_request(request)
    try:
        if ftype not in (None, "usb", "vm"):
            raise api.InvalidArgument(f"Invalid type '{ftype}'!")
        from api.File import File
        return api.response(File().search(file_type=ftype,
                                          downloadable_to=sso.role))
    except Exception as e:
        return api.exception_response(e)
Esempio n. 2
0
def hitcount_aggregate(function):
    """Aggregated classified PATE particle hits

    GET /api/hitcount/<string:function>
    Allowed aggregate functions are: avg, sum, min, max and count.
    Query parameters:
    begin - PATE timestamp (Unix timestamp)
    end - PATE timestamp (Unix timestamp)
    fields - A comma separated list of fields to return
    API returns 200 OK and:
    {
        ...,
        "data" : {
            <fields according to query parameter 'fields'>
        },
        ...
    }

    Data is logically grouped into full rotations, each identified by the timestamp when the rotation started. Information on rotational period or starting time of each sector is not available within data. It must be deciphered separately, if needed.

    Parameters 'begin' and 'end' are integers, although the 'rotation' field they are compared to, is a decimal number. NOTE: This datetime format is placeholder, because instrument development has not formally specified the one used in the actual satellite. Internally, Python timestamp is used.

    A JSON list containing a single object is returned. The identifier field ('timestamp') is never included, because that would defeat the purpose of the aggregate functions."""
    log_request(request)
    try:
        from api.HitCount import HitCount
        if function.lower() not in ('avg', 'sum', 'min', 'max', 'count'):
            raise api.InvalidArgument(
                "Function '{}' is not supported!".format(function))
        return api.response(HitCount(request).get(function))
    except Exception as e:
        return api.exception_response(e)
Esempio n. 3
0
def housekeeping_aggregate(function):
    """Aggregated PATE Housekeeping data

    GET /api/housekeeping/<string:function>
    Allowed aggregate functions are: avg, sum, min, max and count.
    Query parameters:
    begin - PATE timestamp (Unix timestamp)
    end - PATE timestamp (Unix timestamp)
    fields - A comma separated list of fields to return
    API returns 200 OK and:
    {
        ...,
        "data" : {
            <fields according to query parameter 'fields'>
        },
        ...
    }

    Parameters 'begin' and 'end' are integers, although the 'timestamp' field they are compared to, is a decimal number. NOTE: This datetime format is placeholder, because instrument development has not formally specified the one used in the actual satellite. Internally, Python timestamp is used.

    Unlike in the above described API endpoint, these responses do not explicitly include primary key field ('timestamp'), because that would defeat the purpose of the aggregate functions.
    """
    log_request(request)
    try:
        from api.Housekeeping import Housekeeping
        if function.lower() not in ('avg', 'sum', 'min', 'max', 'count'):
            raise api.InvalidArgument(
                "Function '{}' is not supported!".format(function))
        return api.response(Housekeeping(request).get(function))
    except Exception as e:
        return api.exception_response(e)
Esempio n. 4
0
def pulseheight_aggregate(function):
    """Aggregated raw PATE pulse height data.

    GET /api/pulseheight/<string:function>
    Allowed aggregate functions are: avg, sum, min, max and count.
    Query parameters:
    begin - PATE timestamp (Unix timestamp)
    end - PATE timestamp (Unix timestamp)
    fields - A comma separated list of fields to return
    API returns 200 OK and:
    {
        ...,
        "data" : [
            {
                <fields according to query parameter 'fields'>
            },
            ...
        ],
        ...
    }
    """
    log_request(request)
    try:
        from api.PulseHeight import PulseHeight
        if function.lower() not in ('avg', 'sum', 'min', 'max', 'count'):
            raise api.InvalidArgument(
                "Function '{}' is not supported!".format(function))
        return api.response(PulseHeight(request).get(function))
    except Exception as e:
        return api.exception_response(e)
Esempio n. 5
0
def api_publish(id=None):
    """POST with uploaded filename will trigger prepublish procedure. For .OVA files this means reading the included .OVF file for characteristics of the virtual machine. A 'file' table row is inserted and the ID will be returned in the response JSON body { 'id': <int> }."""
    try:
        # Dummy response tuple REMOVE WHEN THIS ROUTE IS COMPLETED!
        response = (200, {
            'data': {
                '.role': f'{sso.role}',
                '.is_teacher': f'{str(sso.is_teacher)}',
                '.is_student': f'{str(sso.is_student)}',
                '.is_anonymous': f'{str(sso.is_anonymous)}',
                '.is_authenticated': f'{str(sso.is_authenticated)}'
            }
        })
        raise api.NotImplemented("Sorry! Not yet implemented!")

        if not sso.is_teacher:
            raise api.Unauthorized("Teacher privileges required")
        if not app.config.get('UPLOAD_FOLDER', None):
            raise api.InternalError(
                "Configuration parameter 'UPLOAD_FOLDER' is not set!")

        if request.method == 'GET':
            file = request.args.get('file', default=None, type=str)
            folder = app.config.get('UPLOAD_FOLDER')
            if not file:
                raise api.InvalidArgument(
                    "GET Request must provide 'file' URI variable")
            # Generate JSONForm for editing
            response = api.Publish(request).preprocess(folder + "/" + file,
                                                       sso.uid)
        elif request.method == 'POST':
            pass
    except Exception as e:
        return api.exception_response(e)
    else:
        # api.response(code: int, payload: dict) -> Flask.response_class
        return api.response(response)