示例#1
0
文件: task.py 项目: JelteF/bottor
def result():
    # peer_id = 0
    result = request.json

    task_id = result['id']
    task = TaskController.get(task_id)
    task.completed += len(result['results'])
    job = task.job
    job.completed += len(result['results'])
    job.running -= len(result['results'])
    resultMatrix = Matrix.matrices[job.id]['result']
    taskMatrix = Matrix.matrices[job.id]['task']

    for res in result['results']:
        row = res['row']
        col = res['col']
        value = res['value']

        resultMatrix[row][col] = value
        taskMatrix[row][col] = Constants.STATE_DONE

    print ("Job " + str(job.id) + ": " + str(job.completed) + "/" + str(job.toComplete) + " completed")

    if job.isFinished():
        filename = "result_matrices/result_job_" + str(job.id)
        print ("Job " + str(job.id) + " completed. Writing result to file " + filename)
        MatrixController.writeToFile(Matrix.matrices[job.id]['result'],
                                     filename, True)
        job.end = datetime.now()
        # REMOVE JOB + MATRICES
    db.session.commit()

    return jsonify()
示例#2
0
def result():
    # peer_id = 0
    result = request.json

    task_id = result['id']
    task = TaskController.get(task_id)
    task.completed += len(result['results'])
    job = task.job
    job.completed += len(result['results'])
    job.running -= len(result['results'])
    resultMatrix = Matrix.matrices[job.id]['result']
    taskMatrix = Matrix.matrices[job.id]['task']

    for res in result['results']:
        row = res['row']
        col = res['col']
        value = res['value']

        resultMatrix[row][col] = value
        taskMatrix[row][col] = Constants.STATE_DONE

    print("Job " + str(job.id) + ": " + str(job.completed) + "/" +
          str(job.toComplete) + " completed")

    if job.isFinished():
        filename = "result_matrices/result_job_" + str(job.id)
        print("Job " + str(job.id) + " completed. Writing result to file " +
              filename)
        MatrixController.writeToFile(Matrix.matrices[job.id]['result'],
                                     filename, True)
        job.end = datetime.now()
        # REMOVE JOB + MATRICES
    db.session.commit()

    return jsonify()
示例#3
0
def post_task():
    data = request.get_json(silent=True)
    title = data['title']
    date = data['date']  # should be in the form of "08 Nov 2019"
    time = data['time'] # should be in the form of "12:00 PM"
    course = data['course']
    description = data['description']
    student = data['student'] # student id
    attachments = data['attachments'] # a list of uploaded file returned by the upload api

    grade = 0
    progress = 0

    deadline = TaskController.create_date(date, time)

    result = TaskController.post(title, deadline, course, description, attachments, student, grade, progress)

    return result
示例#4
0
def update_task(id):
    data = request.get_json()
    print(data)
    title = data['title']
    date = data['date']
    time = data['time']
    course_id = data['course_id']
    description = data['description']
    attachments = data['attachments']

    if ('grade' and 'progress' in data):
        grade = data['grade']
        progress = data['progress']
        result = TaskController.update(title, date, time, course_id, description, attachments, id, grade, progress)
    else:   
        result = TaskController.update_without_progress(title, date, time, course_id, description, attachments, id)

    return result
示例#5
0
文件: task.py 项目: JelteF/bottor
def get(peer_id):

    task = TaskManager.getTask(peer_id)
    if task == 0:
        return jsonify(), 500

    print('started json')
    json = TaskController.getAsJson(task)
    print('finished json')
    return json
示例#6
0
def get(peer_id):

    task = TaskManager.getTask(peer_id)
    if task == 0:
        return jsonify(), 500

    print('started json')
    json = TaskController.getAsJson(task)
    print('finished json')
    return json
示例#7
0
    def getTask(job, peer_id):
        from app.controllers import TaskController
        from app.controllers import MatrixController
        try:
            taskMatrix = Matrix.matrices[job.id]['task']
        except KeyError:
            job.loadMatrices(job.matrixA, job.matrixB)
            taskMatrix = Matrix.matrices[job.id]['task']

        if(not job.started):
            job.started = True
            job.start = datetime.now()
        db.session.commit()
        startRow = 0
        startCol = 0

        # Find first 0 in taskMatrix
        while taskMatrix[startRow][startCol] != Constants.STATE_NONE:
            startCol += 1
            if startCol >= job.resultRows:
                startCol = 0
                startRow += 1
                if startRow >= job.resultRows:
                    # NO TASKS TO DO, COMPLETED OR EVERYTHING RUNNING
                    return 0

        nCols = 0
        nRows = 0

        # Take a few more columns
        while startCol + nCols < job.resultCols and \
                taskMatrix[startRow + nRows][startCol + nCols] == \
                Constants.STATE_NONE and \
                nCols < Constants.TASK_SIZE:
            nCols += 1

        # Take some rows
        while startRow + nRows < job.resultRows and \
                taskMatrix[startRow + nRows][startCol + nCols - 1] == \
                Constants.STATE_NONE and \
                nRows < Constants.TASK_SIZE:
            nRows += 1

        # Set on working
        for i in range(nRows):
            for j in range(nCols):
                JobController.changeState(job, Constants.STATE_WORKING,
                                          startRow + i, startCol + j)

        job.running += nCols * nRows
        job.free -= nCols * nRows

        return TaskController.create(job, peer_id, startRow, startCol, nRows,
                                     nCols)
示例#8
0
def delete_task(id):
    return TaskController.delete(id)
示例#9
0
def get_task(id):
    return TaskController.get(id)
示例#10
0
def get_task_for_student_and_course():
    student = request.args.get('student')
    course = request.args.get('course')
    return TaskController.get_by_student_and_course(student,course)
示例#11
0
def get_task_by_student():
    student_id = request.args.get('id')
    return TaskController.get_by_student(student_id)